Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,49 @@ otherwise, you can install them manually:
pnpm i -D eslint-plugin-eslint-plugin
```

#### Co-located Tests

`projectStructure` requires every source file to sit next to its test file,
through
[eslint-plugin-project-structure](https://github.com/Igorkowalski94/eslint-plugin-project-structure).
`src/place-service.ts` then has to be joined by `src/place-service.spec.ts`.
Only `enforceExistence` is driven here, so the rule never enforces naming:

```ts
// eslint.config.ts
import isentinel from "@isentinel/eslint-config";

export default isentinel({
projectStructure: {
// The plugin's name placeholders, plus `{ext}` for the extension of the
// file that matched. Default: ["{node-name}.spec.{ext}"]
enforceExistence: "__tests__/{node-name}.test.{ext}",
// Default: every source file the preset lints
files: ["src/**/*.{ts,tsx}"],
// Default: tests, `.d.ts` files and build configs
ignores: ["**/index.ts"],
// Default: `process.cwd()`
projectRoot: import.meta.dirname,
// Restricts the check to one subtree. Default: all of `projectRoot`
structureRoot: "src",
},
});
```

```bash
pnpm i -D eslint-plugin-project-structure
```

`{node-name}` matches the kebab-case filenames the preset enforces; the others
are `{nodeName}`, `{NodeName}`, `{node_name}` and `{NODE_NAME}`. A file already
matching a template is exempt from it. A source file with no test disables the
rule at the source.

Two caveats. Deleting `foo.spec.ts` does not change `foo.ts`, so a cached run
replays the old clean result — the check is only sound uncached. And the plugin
writes `projectStructure.cache.json` into `projectRoot` while it has something
to report, so gitignore it.

### Git hooks

If you want to apply lint and auto-fix before every commit, use
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"eslint-plugin-jest": "catalog:peer",
"eslint-plugin-jest-extended": "catalog:peer",
"eslint-plugin-n": "catalog:peer",
"eslint-plugin-project-structure": "catalog:peer",
"eslint-plugin-react-jsx": "catalog:peer",
"eslint-plugin-react-naming-convention": "catalog:peer",
"eslint-plugin-react-x": "catalog:peer",
Expand All @@ -174,6 +175,7 @@
"eslint-plugin-jest": "^29.15.0",
"eslint-plugin-jest-extended": "^3.0.0",
"eslint-plugin-n": "^17.0.0 || ^18.0.0",
"eslint-plugin-project-structure": "^3.14.0",
"eslint-plugin-react-jsx": "^5.10.0",
"eslint-plugin-react-naming-convention": "^5.10.0",
"eslint-plugin-react-x": "^5.10.0",
Expand All @@ -197,6 +199,9 @@
"eslint-plugin-n": {
"optional": true
},
"eslint-plugin-project-structure": {
"optional": true
},
"eslint-plugin-react-jsx": {
"optional": true
},
Expand Down
101 changes: 91 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ catalogs:
eslint-plugin-jest: 29.16.0
eslint-plugin-jest-extended: 3.0.1
eslint-plugin-n: 18.2.2
eslint-plugin-project-structure: 3.14.3
eslint-plugin-react-jsx: 5.17.3
eslint-plugin-react-naming-convention: 5.17.3
eslint-plugin-react-x: 5.17.3
Expand Down
2 changes: 2 additions & 0 deletions scripts/config-factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
packageJson,
perfectionist,
pnpm,
projectStructure,
promise,
react,
roblox,
Expand Down Expand Up @@ -74,6 +75,7 @@ export const PRESET_CONFIGS: Array<Awaitable<Array<TypedFlatConfigItem>>> = [
packageJson(),
perfectionist(),
pnpm({ isInEditor: false }),
projectStructure(),
promise(),
react({ testing: true }),
roblox(),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/constants-generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const versionsMap = {
"eslint": "10.7.0",
"eslint": "10.8.1",
"eslint-plugin-jest": "29.16.0",
"eslint-plugin-react-jsx": "5.17.3",
"eslint-plugin-react-naming-convention": "5.17.3",
Expand Down
1 change: 1 addition & 0 deletions src/eslint/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from "./oxfmt.ts";
export * from "./package-json.ts";
export * from "./perfectionist.ts";
export * from "./pnpm.ts";
export * from "./project-structure.ts";
export * from "./promise.ts";
export * from "./react.ts";
export * from "./roblox.ts";
Expand Down
Loading