@kirill.konshin/lint 0.5.5 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +38 -3
  2. package/commands/spec-author.md +39 -0
  3. package/dist/configs/base.d.ts +4 -3
  4. package/dist/configs/base.js +61 -74
  5. package/dist/configs/imports.d.ts +3 -2
  6. package/dist/configs/imports.js +95 -146
  7. package/dist/configs/nx.d.ts +4 -3
  8. package/dist/configs/nx.js +31 -41
  9. package/dist/configs/prettier.d.ts +3 -2
  10. package/dist/configs/prettier.js +19 -16
  11. package/dist/configs/promise.d.ts +3 -2
  12. package/dist/configs/promise.js +16 -16
  13. package/dist/configs/react.d.ts +4 -3
  14. package/dist/configs/react.js +178 -217
  15. package/dist/configs/storybook.d.ts +4 -3
  16. package/dist/configs/storybook.js +22 -22
  17. package/dist/configs/tailwind.d.ts +4 -3
  18. package/dist/configs/tailwind.js +67 -91
  19. package/dist/configs/testing.d.ts +7 -6
  20. package/dist/configs/testing.js +112 -146
  21. package/dist/configs/turbo.d.ts +4 -3
  22. package/dist/configs/turbo.js +19 -27
  23. package/dist/configs/typescriptTypeAware.d.ts +4 -3
  24. package/dist/configs/typescriptTypeAware.js +99 -95
  25. package/dist/configs/unicorn.d.ts +3 -2
  26. package/dist/configs/unicorn.js +34 -41
  27. package/dist/exts.d.ts +2 -1
  28. package/dist/exts.js +10 -11
  29. package/dist/index.d.ts +44 -42
  30. package/dist/index.js +53 -85
  31. package/dist/lib.d.ts +21 -21
  32. package/dist/lib.js +262 -301
  33. package/dist/lintPrepare.d.ts +20 -17
  34. package/dist/lintPrepare.js +341 -371
  35. package/dist/lintStaged.d.ts +4 -3
  36. package/dist/lintStaged.js +25 -22
  37. package/dist/prettier.d.ts +4 -3
  38. package/dist/prettier.js +16 -17
  39. package/dist/restrictions.d.ts +11 -10
  40. package/dist/restrictions.js +18 -22
  41. package/dist/yarn.cjs +79 -98
  42. package/dist/yarn.d.cts +3 -2
  43. package/package.json +22 -8
  44. package/rules/agent.md +2 -0
  45. package/rules/openspec.md +1 -1
  46. package/skills/spec-steward/SKILL.md +4 -12
  47. package/skills/spec-steward/references/audit.md +18 -43
  48. package/skills/spec-steward/references/contract.md +9 -9
  49. package/skills/spec-steward/references/criteria.md +4 -4
  50. package/skills/spec-steward/references/review-format.md +6 -6
  51. package/skills/spec-steward/references/wiring.md +2 -2
  52. package/skills/spec-steward/references/worker.md +67 -0
  53. package/skills/spec-steward/sweeps.json +49 -0
  54. package/skills/spec-tools/SKILL.md +48 -0
  55. package/skills/spec-tools/references/contract.md +111 -0
  56. package/skills/spec-tools/references/gitlab.md +120 -0
  57. package/skills/spec-tools/scripts/cli.js +8129 -0
  58. package/skills/spec-verify/SKILL.md +153 -0
  59. package/dist/configs/base.d.ts.map +0 -1
  60. package/dist/configs/imports.d.ts.map +0 -1
  61. package/dist/configs/nx.d.ts.map +0 -1
  62. package/dist/configs/prettier.d.ts.map +0 -1
  63. package/dist/configs/promise.d.ts.map +0 -1
  64. package/dist/configs/react.d.ts.map +0 -1
  65. package/dist/configs/storybook.d.ts.map +0 -1
  66. package/dist/configs/tailwind.d.ts.map +0 -1
  67. package/dist/configs/testing.d.ts.map +0 -1
  68. package/dist/configs/turbo.d.ts.map +0 -1
  69. package/dist/configs/typescriptTypeAware.d.ts.map +0 -1
  70. package/dist/configs/unicorn.d.ts.map +0 -1
  71. package/dist/exts.d.ts.map +0 -1
  72. package/dist/index.d.ts.map +0 -1
  73. package/dist/lib.d.ts.map +0 -1
  74. package/dist/lintPrepare.d.ts.map +0 -1
  75. package/dist/lintStaged.d.ts.map +0 -1
  76. package/dist/prettier.d.ts.map +0 -1
  77. package/dist/restrictions.d.ts.map +0 -1
  78. package/dist/yarn.d.cts.map +0 -1
  79. package/skills/spec-steward/scripts/lib/align.mjs +0 -127
  80. package/skills/spec-steward/scripts/lib/checks.mjs +0 -589
  81. package/skills/spec-steward/scripts/lib/citations.mjs +0 -156
  82. package/skills/spec-steward/scripts/lib/corpus.mjs +0 -256
  83. package/skills/spec-steward/scripts/lib/coverage.mjs +0 -123
  84. package/skills/spec-steward/scripts/lib/evidence.mjs +0 -334
  85. package/skills/spec-steward/scripts/lib/git.mjs +0 -138
  86. package/skills/spec-steward/scripts/lib/review.mjs +0 -347
  87. package/skills/spec-steward/scripts/lib/scan.mjs +0 -364
  88. package/skills/spec-steward/scripts/lib/util.mjs +0 -161
  89. package/skills/spec-steward/scripts/lib/wire.mjs +0 -331
  90. package/skills/spec-steward/scripts/steward.mjs +0 -350
  91. package/skills/spec-steward/workflows/audit.js +0 -539
package/README.md CHANGED
@@ -335,11 +335,46 @@ The generated `AGENTS.md` has a `# Custom Rules` section at the bottom — add p
335
335
  In the project root, `lint-prepare`:
336
336
 
337
337
  - Creates real `rules/`, `commands/` and `skills/` directories in `.agents/` (canonical, cross-tool) and `.claude/` (Claude Code), and only ever symlinks files into them.
338
- - Links every `rules/*.md` and every skill folder (`skills/<name>/` with all its files, plus this `README.md` next to `SKILL.md` unless the skill ships one, so a skill can reference `@README.md`) into all three — e.g. `lint-repo`, which sets up the tooling above and audits the repo against the rules. Links point straight at the installed package's real location (`node_modules/@kirill.konshin/lint`, or the workspace package).
338
+ - Links every `rules/*.md`, every `commands/*.md` and every skill folder (`skills/<name>/` with all its files, plus this `README.md` next to `SKILL.md` unless the skill ships one, so a skill can reference `@README.md`) into all three — e.g. `lint-repo`, which sets up the tooling above and audits the repo against the rules. Links point straight at the installed package's real location (`node_modules/@kirill.konshin/lint`, or the workspace package).
339
339
  - Mirrors your own files from `.agents/{rules,commands,skills}/` into `.claude/`; a file of yours wins over the package file at the same path.
340
340
  - Removes dead links (e.g. after renaming a file) and the links it placed before but no longer needs. Each directory gets a generated `.gitignore` listing its links, so your own files stay tracked.
341
341
  - Generates `AGENTS.md` for other assistants (Codex, Cursor, Copilot, …) with a `# Rules` section — one entry per rule (the package's and yours): its title, frontmatter `description`, the `paths` it is scoped to and a plain link to its `.agents/rules/<file>` entry — and symlinks `CLAUDE.md` to it. The links are never `@` imports: Claude Code loads `.claude/rules` itself and honours each rule's `paths`, while an import would load every rule into every session.
342
342
 
343
+ ### OpenSpec
344
+
345
+ For a repository specified with [OpenSpec](https://github.com/Fission-AI/OpenSpec) the package ships one bin, `spec-tools` — a single self-contained file, `skills/spec-tools/scripts/cli.js` — three skills and a command:
346
+
347
+ - `spec-tools steward` and the `spec-steward` skill — the corpus gate (citations, binding, the scenario ratchet), the edit hook, corpus-quality audits and review rounds.
348
+ - `spec-tools` and its skill — the change gates, the workflow-evidence gate, the requirement-level specification diff, the code-conformance audit, and the glue a CI pipeline runs around a headless AI review (verdict gate, merge-request comment, HTML reports).
349
+ - `spec-verify` — the skill every audit worker loads.
350
+ - `/spec-author` — the command that writes or edits a specification in place, the default direct-edit path.
351
+
352
+ Which to reach for:
353
+
354
+ | Question | Tool | Outcome |
355
+ | --- | --- | --- |
356
+ | How do I write or change a rule? | `/spec-author` | The specification edited in place, with the code and tests that prove it |
357
+ | Do citations resolve, is every new scenario bound, did a rule weaken? | `spec-tools steward check` (the gate, the edit hook) | Fails the merge request on an error |
358
+ | Are these the right rules — placement, REQUIRED or ⚠️ ADVISORY, wording, evidence, duplicates, drift across repositories? | the `spec-steward` skill (audit on the `spec-tools` engine, review rounds, align) | A review file of proposals; the owner decides, steward applies; never a build failure |
359
+ | Does the code do exactly what the rules say, and do the bound tests assert them? | the `spec-verify` skill, run by `spec-tools` | Graded, quote-proved findings; PASS / FAIL / INCOMPLETE gates CI |
360
+ | Is the change finished, what did it change, how does CI run the audit? | `spec-tools` (gates, evidence, diff, tier, workers, verdict, comment, html) | Gates and reports for the pipeline |
361
+
362
+ Where each runs:
363
+
364
+ | What | In CI | Locally |
365
+ | --- | --- | --- |
366
+ | `spec-tools steward check` | `spec-tools gates`, every merge request: an error fails it | the edit hook on every edit Claude makes, and `spec-tools gates` before handing back |
367
+ | `spec-tools steward coverage`, `spec-tools steward evidence --json` | the coverage report, and the evidence `spec-tools scope` builds the spec-verify audit from | on demand |
368
+ | spec-steward's corpus audit, review rounds, `align` | never — it is heavy and its outcome is the owner's | on the owner's request: `spec-tools audit --audit spec-steward [--context <decisions file>]`, then the review rounds, where the accepted answers are applied |
369
+ | `spec-verify` | the reading jobs and the judge job: its verdict gates merge requests and the release | `spec-tools audit`, and `/spec-verify changed` before handing back a spec edit |
370
+ | `spec-tools gates`, `evidence`, `diff` | their own jobs | before handing back |
371
+
372
+ Specifications change only by hand, or when the steward skill applies the owner's accepted review answers; `spec-tools steward check --fix` makes the only mechanical repairs. No audit edits code or specifications.
373
+
374
+ The audits share their principles: `spec-verify`'s checks 2–5 are spec-steward's criteria 10, 9, 11 and 5, worded identically — steward asks whether the rule should change, `spec-verify` whether the code or the rule has diverged.
375
+
376
+ Setup and the GitLab pipeline are in the `spec-tools` skill.
377
+
343
378
  ### Safety checks
344
379
 
345
380
  Only the files `lint-prepare` knows (package files and mirrors of yours) and dead links are touched: real files are never overwritten (e.g. your own `.claude/rules/*.md`) and nothing is written through a symlinked directory. `.codex/` is not touched: Codex reads `.agents/skills` and `AGENTS.md`, and the links earlier versions placed in `.codex/` stay until you delete them. `init`/`update` refuse to run if `CLAUDE.md` isn't a symlink. If `AGENTS.md` exists and wasn't generated by this tool, `init` skips it; use `update` to force regeneration.
@@ -400,9 +435,9 @@ Everything else — `prettier`, `listStaged`, extension lists (`tsExts`, …), `
400
435
 
401
436
  ## Development
402
437
 
403
- ### Incremental TypeScript build
438
+ ### Build
404
439
 
405
- The package compiles ESM and declarations from `src/*.ts`, plus the CommonJS Yarn entry from `src/yarn.cts`, with `tsc --build`. Build state is cached in `.tscache/tsconfig.tsbuildinfo`; consumers load `dist`, and this monorepo builds lint first in its root `postinstall` before running `lint-prepare`.
440
+ `tsdown` builds two things (`tsdown.config.ts`): the library — ESM and declarations from `src/*.ts`, one file per module, plus the CommonJS Yarn entry from `src/yarn.cts` — into `dist`, and the `spec-tools` CLI — spec-steward included — into one self-contained file, `skills/spec-tools/scripts/cli.js`, which the skills and CI jobs name. `yarn typecheck` (`tsc --noEmit`) checks types; the build does not. Consumers load `dist`, and this monorepo builds lint first in its root `postinstall` before running `lint-prepare`.
406
441
 
407
442
  ### Eslint
408
443
 
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: Spec author
3
+ description: Write or edit a capability specification in openspec/specs — the default direct-edit path
4
+ allowed-tools: Bash(openspec:*), Bash(spec-tools:*), Bash(spec-steward:*), Bash(yarn openspec:*), Bash(yarn spec-tools:*), Bash(yarn spec-steward:*), Bash(npx openspec:*), Bash(npx spec-tools:*), Bash(npx spec-steward:*), Bash(git diff*), Bash(git log*), Read, Edit, Write, Glob, Grep
5
+ ---
6
+
7
+ Write or edit a capability specification in place. This is the **default** path for specification work; the `/opsx:*` commands drive the full delta flow and run only when the user asks for them.
8
+
9
+ How a specification is written is the spec-steward model, [`references/model.md`](../skills/spec-steward/references/model.md), and what the gate checks is its [`references/contract.md`](../skills/spec-steward/references/contract.md); the rest of the tooling's contract is the spec-tools skill's [`references/contract.md`](../skills/spec-tools/references/contract.md); the change paths and who commits are in the root `AGENTS.md`. Read them; this file only sequences the work.
10
+
11
+ ## Steps
12
+
13
+ 1. **Ask about scope first.** A workspace or branch, or the current tree? A direct edit, or a change folder because the work needs a written plan? Wait for an answer unless the user already gave one. The full delta flow is never yours to choose: take it only when the user names it.
14
+
15
+ 2. **Find the capability.** `openspec list --specs`. Edit the existing `openspec/specs/<capability>/spec.md` that owns the behaviour; a new capability is a decision to raise out loud. A pattern that works system-wide earns its own folder.
16
+
17
+ 3. **Read the neighbours.** A rule lives in the capability that owns it — cite a neighbour rather than restating it. If the new behaviour contradicts an existing requirement, surface it and let the user decide; do not paper over it in either place.
18
+
19
+ 4. **If the user chose a change folder**: `openspec new change <name>`, set `skip_specs: true` in its `.openspec.yaml`, write `proposal.md`, `design.md` and `tasks.md`. The behaviour still lands as a direct edit — the folder carries the plan, never deltas. Set `skip_specs` yourself when the change is plainly simple (a bugfix, a small feature); ask when in doubt. The folder is archived inside the merge or pull request, on the user's word.
20
+
21
+ 5. **Write it.** Name the observable failure the rule prevents and the cheapest evidence that catches it; if there is none, mark the requirement `**⚠️ Advisory:** <why review is its evidence>`, and record what is knowingly missing as `**⚠️ Known gap (<tracker>):** <what is missing>`. Write a new or edited statement in EARS (`When <trigger>, the <system> SHALL <response>`, `While <state>, …`, `If <condition>, then …`, or `The <system> SHALL …`), keeping the RFC 2119 keyword in capitals, and each new or edited scenario in Given/When/Then, one case each, Given only where a precondition matters; leave untouched text as it is. Scenario names are unique within the file:
22
+
23
+ ```markdown
24
+ ### Requirement: <name>
25
+
26
+ When <trigger>, the <system> SHALL <response>.
27
+
28
+ #### Scenario: <name>
29
+
30
+ - **GIVEN** <precondition, only where it matters>
31
+ - **WHEN** <trigger>
32
+ - **THEN** <observable outcome>
33
+ ```
34
+
35
+ A test that proves a scenario cites its anchor on its `describe`/`it`/`test` block; a code citation is optional and only has to resolve (the spec-steward contract).
36
+
37
+ 6. **Verify**: run the checks the root `AGENTS.md` lists; where it lists none, `openspec validate --strict --all` and `spec-tools gates`.
38
+
39
+ 7. **Hand back.** Say what changed and show the `spec-tools diff` first line. Do not commit, push, or archive; end with the decisions the user has to make.
@@ -1,5 +1,6 @@
1
- import type { Linter } from 'eslint';
2
- import type { DefaultIgnoreOptions } from '../index.js';
1
+ import { DefaultIgnoreOptions } from "../index.js";
2
+ import { Linter } from "eslint";
3
+ //#region src/configs/base.d.ts
3
4
  /**
4
5
  * Core JS recommended rules, global ignores, browser + Node globals, and overrides of core ESLint
5
6
  * rules.
@@ -26,4 +27,4 @@ export declare function includeIgnoreFile(importMetaUrl: string, ignoreFile: str
26
27
  * the flag is off by default and enabling it without `importMetaUrl` is a hard error.
27
28
  */
28
29
  export declare function defaultIgnoreConfig(option?: boolean | DefaultIgnoreOptions): Linter.Config[];
29
- //# sourceMappingURL=base.d.ts.map
30
+ //#endregion
@@ -1,80 +1,67 @@
1
- import { dirname, resolve } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import { includeIgnoreFile as includeIgnoreFileConfig } from '@eslint/config-helpers';
4
- import js from '@eslint/js';
5
- import globals from 'globals';
6
- import { asOptions, GLOBAL_IGNORES } from '../lib.js';
1
+ import { GLOBAL_IGNORES, asOptions } from "../lib.js";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { includeIgnoreFile as includeIgnoreFile$1 } from "@eslint/config-helpers";
5
+ import js from "@eslint/js";
6
+ import globals from "globals";
7
+ //#region src/configs/base.ts
7
8
  /**
8
- * Core JS recommended rules, global ignores, browser + Node globals, and overrides of core ESLint
9
- * rules.
10
- *
11
- * `eslint-config-next` already ignores `next-env.d.ts`, but only as a bare pattern ('next-env.d.ts'),
12
- * which only matches at the config's own root - not when the Next app (and its generated
13
- * next-env.d.ts) lives in a subdirectory, like demo/web-static/ here. It's auto-generated and
14
- * explicitly marked "should not be edited", so exclude it recursively instead of just working
15
- * around individual rules (its `///` reference directives otherwise trip multiline-comment-style,
16
- * which would corrupt them if autofixed into a `/* *\/` block).
17
- */
18
- export function baseConfig() {
19
- return [
20
- js.configs.recommended,
21
- {
22
- name: 'Global Ignores',
23
- ignores: GLOBAL_IGNORES,
24
- },
25
- {
26
- name: 'Globals',
27
- languageOptions: {
28
- globals: {
29
- ...globals.browser,
30
- ...globals.node,
31
- },
32
- },
33
- },
34
- {
35
- name: 'ESLint overrides',
36
- rules: {
37
- 'no-restricted-imports': [
38
- 'error',
39
- {
40
- paths: [
41
- {
42
- name: 'next/router',
43
- message: 'Please use next/navigation instead of next/router',
44
- },
45
- ],
46
- },
47
- ],
48
- // 'multiline-comment-style': ['warn', 'starred-block'],
49
- 'multiline-comment-style': 'off',
50
- },
51
- },
52
- ];
9
+ * Core JS recommended rules, global ignores, browser + Node globals, and overrides of core ESLint
10
+ * rules.
11
+ *
12
+ * `eslint-config-next` already ignores `next-env.d.ts`, but only as a bare pattern ('next-env.d.ts'),
13
+ * which only matches at the config's own root - not when the Next app (and its generated
14
+ * next-env.d.ts) lives in a subdirectory, like demo/web-static/ here. It's auto-generated and
15
+ * explicitly marked "should not be edited", so exclude it recursively instead of just working
16
+ * around individual rules (its `///` reference directives otherwise trip multiline-comment-style,
17
+ * which would corrupt them if autofixed into a `/* *\/` block).
18
+ */
19
+ function baseConfig() {
20
+ return [
21
+ js.configs.recommended,
22
+ {
23
+ name: "Global Ignores",
24
+ ignores: GLOBAL_IGNORES
25
+ },
26
+ {
27
+ name: "Globals",
28
+ languageOptions: { globals: {
29
+ ...globals.browser,
30
+ ...globals.node
31
+ } }
32
+ },
33
+ {
34
+ name: "ESLint overrides",
35
+ rules: {
36
+ "no-restricted-imports": ["error", { paths: [{
37
+ name: "next/router",
38
+ message: "Please use next/navigation instead of next/router"
39
+ }] }],
40
+ "multiline-comment-style": "off"
41
+ }
42
+ }
43
+ ];
53
44
  }
54
45
  /**
55
- * Convert an ignore file (`.gitignore`, `.prettierignore`, ...) into an ESLint ignores block,
56
- * resolved next to the consumer's config file.
57
- */
58
- export function includeIgnoreFile(importMetaUrl, ignoreFile) {
59
- // @see https://blog.linotte.dev/eslint-9-next-js-935c2b6d0371
60
- return includeIgnoreFileConfig(resolve(dirname(fileURLToPath(importMetaUrl)), ignoreFile));
46
+ * Convert an ignore file (`.gitignore`, `.prettierignore`, ...) into an ESLint ignores block,
47
+ * resolved next to the consumer's config file.
48
+ */
49
+ function includeIgnoreFile(importMetaUrl, ignoreFile) {
50
+ return includeIgnoreFile$1(resolve(dirname(fileURLToPath(importMetaUrl)), ignoreFile));
61
51
  }
62
52
  /**
63
- * The conventional ignore setup of this toolkit: `.gitignore` + `.prettierignore` next to the
64
- * consumer's config file, both converted into ESLint ignores via {@link includeIgnoreFile} (both
65
- * files must exist - the prettier scripts in README use the same two).
66
- *
67
- * There is nothing to auto-detect here - the consumer's config file location can't be known - so
68
- * the flag is off by default and enabling it without `importMetaUrl` is a hard error.
69
- */
70
- export function defaultIgnoreConfig(option) {
71
- const { enabled = false, importMetaUrl } = asOptions(option);
72
- if (!enabled)
73
- return [];
74
- if (!importMetaUrl) {
75
- throw new Error('[@kirill.konshin/lint] `defaultIgnore` was enabled, but `importMetaUrl` was not provided - the ' +
76
- 'location of the consumer config file cannot be auto-detected. ' +
77
- 'Pass `defaultIgnore: { importMetaUrl: import.meta.url }`.');
78
- }
79
- return [includeIgnoreFile(importMetaUrl, '.gitignore'), includeIgnoreFile(importMetaUrl, '.prettierignore')];
53
+ * The conventional ignore setup of this toolkit: `.gitignore` + `.prettierignore` next to the
54
+ * consumer's config file, both converted into ESLint ignores via {@link includeIgnoreFile} (both
55
+ * files must exist - the prettier scripts in README use the same two).
56
+ *
57
+ * There is nothing to auto-detect here - the consumer's config file location can't be known - so
58
+ * the flag is off by default and enabling it without `importMetaUrl` is a hard error.
59
+ */
60
+ function defaultIgnoreConfig(option) {
61
+ const { enabled = false, importMetaUrl } = asOptions(option);
62
+ if (!enabled) return [];
63
+ if (!importMetaUrl) throw new Error("[@kirill.konshin/lint] `defaultIgnore` was enabled, but `importMetaUrl` was not provided - the location of the consumer config file cannot be auto-detected. Pass `defaultIgnore: { importMetaUrl: import.meta.url }`.");
64
+ return [includeIgnoreFile(importMetaUrl, ".gitignore"), includeIgnoreFile(importMetaUrl, ".prettierignore")];
80
65
  }
66
+ //#endregion
67
+ export { baseConfig, defaultIgnoreConfig, includeIgnoreFile };
@@ -1,4 +1,5 @@
1
- import type { Linter } from 'eslint';
1
+ import { Linter } from "eslint";
2
+ //#region src/configs/imports.d.ts
2
3
  /**
3
4
  * Import linting via eslint-plugin-import-x: recommended rules + overrides + the default-export
4
5
  * relaxation for files that legitimately default-export (framework/tooling conventions) - the
@@ -18,4 +19,4 @@ export declare function importSortConfig(): Linter.Config[];
18
19
  * Autofixable removal of unused imports.
19
20
  */
20
21
  export declare function unusedImportsConfig(): Linter.Config[];
21
- //# sourceMappingURL=imports.d.ts.map
22
+ //#endregion
@@ -1,152 +1,101 @@
1
- import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript';
2
- import importXPlugin, { createNodeResolver } from 'eslint-plugin-import-x';
3
- import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
4
- import unusedImportsPlugin from 'eslint-plugin-unused-imports';
5
- import { tsExts } from '../exts.js';
1
+ import { tsExts } from "../exts.js";
2
+ import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
3
+ import importXPlugin, { createNodeResolver } from "eslint-plugin-import-x";
4
+ import simpleImportSortPlugin from "eslint-plugin-simple-import-sort";
5
+ import unusedImportsPlugin from "eslint-plugin-unused-imports";
6
+ //#region src/configs/imports.ts
6
7
  /**
7
- * Import linting via eslint-plugin-import-x: recommended rules + overrides + the default-export
8
- * relaxation for files that legitimately default-export (framework/tooling conventions) - the
9
- * latter makes no sense without `import-x/no-default-export`, so it is not a separate block.
10
- *
11
- * eslint-config-next already registers `eslint-plugin-import` under the 'import' key, and ESLint 10
12
- * hard-errors ("Cannot redefine plugin") if a later config tries to reuse that same key with a
13
- * different plugin instance. eslint-plugin-import-x is a drop-in replacement, registered under its
14
- * own 'import-x' key instead (its own recommended config does this registration for us).
15
- */
16
- export function importXConfig() {
17
- return [
18
- importXPlugin.configs['flat/recommended'],
19
- {
20
- name: 'eslint-plugin-import-x overrides',
21
- settings: {
22
- /*
23
- * `createTypeScriptImportResolver` correctly resolves relative imports and simple TS path
24
- * aliases, but NOT cross-workspace-package imports in this monorepo (e.g. `@kirill.konshin/node`)
25
- * or subpath exports (e.g. `next/constants`) - verified empirically. That's why the
26
- * resolution-dependent rules below are turned off rather than left on the recommended default.
27
- */
28
- 'import-x/resolver-next': [createTypeScriptImportResolver(), createNodeResolver()],
29
- },
30
- rules: {
31
- /*
32
- * Off because of the workspace/subpath resolution gaps above - re-enable per-project once
33
- * resolution is confirmed reliable there (e.g. a single-app, non-monorepo consumer).
34
- */
35
- 'import-x/no-unresolved': 'off',
36
- 'import-x/named': 'off',
37
- 'import-x/namespace': 'off',
38
- 'import-x/default': 'off',
39
- 'import-x/export': 'off',
40
- /*
41
- * Same resolution caveat, and also the two most expensive rules in the recommended set
42
- * (they parse every imported module looking for its named exports).
43
- */
44
- 'import-x/no-named-as-default': 'off',
45
- 'import-x/no-named-as-default-member': 'off',
46
- 'import-x/no-default-export': 'warn', // relaxed for conventional files below
47
- },
48
- },
49
- {
50
- name: 'Default export overrides',
51
- // files that legitimately default-export (framework/tooling conventions)
52
- files: [
53
- '**/*.config.*',
54
- `**/*.stories.${tsExts}`,
55
- `**/.storybook/main.${tsExts}`,
56
- `**/.storybook/preview.${tsExts}`,
57
- '**/.lintstagedrc*',
58
- '**/.prettierrc*',
59
- `**/App.${tsExts}`,
60
- `**/index.${tsExts}`,
61
- `**/main.${tsExts}`,
62
- '**/*.d.ts',
63
- `**/default.${tsExts}`,
64
- `**/error.${tsExts}`,
65
- `**/forbidden.${tsExts}`,
66
- `**/global-error.${tsExts}`,
67
- `**/layout.${tsExts}`,
68
- `**/loading.${tsExts}`,
69
- `**/not-found.${tsExts}`,
70
- `**/page.${tsExts}`,
71
- `**/template.${tsExts}`,
72
- `**/unauthorized.${tsExts}`,
73
- `**/apple-icon.${tsExts}`,
74
- `**/icon.${tsExts}`,
75
- `**/manifest.${tsExts}`,
76
- `**/opengraph-image.${tsExts}`,
77
- `**/robots.${tsExts}`,
78
- `**/sitemap.${tsExts}`,
79
- `**/twitter-image.${tsExts}`,
80
- ],
81
- rules: {
82
- /*
83
- * Stories always default-export `meta`, and story exports (`Default`, `WithArgs`, ...) are PascalCase by
84
- * Storybook's own convention, which the general rules disallow. The stray naming-convention entry is
85
- * deliberately out of place here - the rule itself lives in typescriptTypeAware.js, which
86
- * defineLintConfig orders BEFORE this block precisely so this exemption wins (flat config is
87
- * last-wins).
88
- */
89
- 'import-x/no-default-export': 'off',
90
- '@typescript-eslint/naming-convention': 'off',
91
- },
92
- },
93
- ];
8
+ * Import linting via eslint-plugin-import-x: recommended rules + overrides + the default-export
9
+ * relaxation for files that legitimately default-export (framework/tooling conventions) - the
10
+ * latter makes no sense without `import-x/no-default-export`, so it is not a separate block.
11
+ *
12
+ * eslint-config-next already registers `eslint-plugin-import` under the 'import' key, and ESLint 10
13
+ * hard-errors ("Cannot redefine plugin") if a later config tries to reuse that same key with a
14
+ * different plugin instance. eslint-plugin-import-x is a drop-in replacement, registered under its
15
+ * own 'import-x' key instead (its own recommended config does this registration for us).
16
+ */
17
+ function importXConfig() {
18
+ return [
19
+ importXPlugin.configs["flat/recommended"],
20
+ {
21
+ name: "eslint-plugin-import-x overrides",
22
+ settings: { "import-x/resolver-next": [createTypeScriptImportResolver(), createNodeResolver()] },
23
+ rules: {
24
+ "import-x/no-unresolved": "off",
25
+ "import-x/named": "off",
26
+ "import-x/namespace": "off",
27
+ "import-x/default": "off",
28
+ "import-x/export": "off",
29
+ "import-x/no-named-as-default": "off",
30
+ "import-x/no-named-as-default-member": "off",
31
+ "import-x/no-default-export": "warn"
32
+ }
33
+ },
34
+ {
35
+ name: "Default export overrides",
36
+ files: [
37
+ "**/*.config.*",
38
+ `**/*.stories.${tsExts}`,
39
+ `**/.storybook/main.${tsExts}`,
40
+ `**/.storybook/preview.${tsExts}`,
41
+ "**/.lintstagedrc*",
42
+ "**/.prettierrc*",
43
+ `**/App.${tsExts}`,
44
+ `**/index.${tsExts}`,
45
+ `**/main.${tsExts}`,
46
+ "**/*.d.ts",
47
+ `**/default.${tsExts}`,
48
+ `**/error.${tsExts}`,
49
+ `**/forbidden.${tsExts}`,
50
+ `**/global-error.${tsExts}`,
51
+ `**/layout.${tsExts}`,
52
+ `**/loading.${tsExts}`,
53
+ `**/not-found.${tsExts}`,
54
+ `**/page.${tsExts}`,
55
+ `**/template.${tsExts}`,
56
+ `**/unauthorized.${tsExts}`,
57
+ `**/apple-icon.${tsExts}`,
58
+ `**/icon.${tsExts}`,
59
+ `**/manifest.${tsExts}`,
60
+ `**/opengraph-image.${tsExts}`,
61
+ `**/robots.${tsExts}`,
62
+ `**/sitemap.${tsExts}`,
63
+ `**/twitter-image.${tsExts}`
64
+ ],
65
+ rules: {
66
+ "import-x/no-default-export": "off",
67
+ "@typescript-eslint/naming-convention": "off"
68
+ }
69
+ }
70
+ ];
94
71
  }
95
72
  /**
96
- * Deterministic import ordering.
97
- */
98
- export function importSortConfig() {
99
- return [
100
- {
101
- name: 'eslint-plugin-simple-import-sort',
102
- files: [`**/*.${tsExts}`],
103
- plugins: { 'simple-import-sort': simpleImportSortPlugin },
104
- rules: {
105
- /*
106
- * Side-effect imports (polyfills, CSS) ARE sorted into their group; the sorter only
107
- * preserves the relative order of multiple side-effect imports that land in the SAME
108
- * group (so order-dependent side effects stay put). Non-import code between imports
109
- * splits them into independently-sorted chunks (standard simple-import-sort behavior).
110
- */
111
- 'simple-import-sort/imports': [
112
- 'error',
113
- {
114
- groups: [
115
- // 1. Polyfills - side-effect imports that must run first
116
- ['^\\u0000.*(polyfill|core-js|regenerator-runtime|whatwg-fetch|@vitest/web-worker)'],
117
- // 2. React
118
- ['^react(-dom)?(/|$)'],
119
- // 3. Third-party packages (node: builtins + npm packages)
120
- ['^node:', '^@?\\w'],
121
- // 4. Local imports - path aliases then relative
122
- ['^@/', '^\\.'],
123
- // 5. CSS/styles from libraries (side-effect, package path)
124
- ['^\\u0000@?\\w'],
125
- // 6. Local CSS/styles (side-effect, relative path)
126
- ['^\\u0000'],
127
- ],
128
- },
129
- ],
130
- },
131
- },
132
- ];
73
+ * Deterministic import ordering.
74
+ */
75
+ function importSortConfig() {
76
+ return [{
77
+ name: "eslint-plugin-simple-import-sort",
78
+ files: [`**/*.${tsExts}`],
79
+ plugins: { "simple-import-sort": simpleImportSortPlugin },
80
+ rules: { "simple-import-sort/imports": ["error", { groups: [
81
+ ["^\\u0000.*(polyfill|core-js|regenerator-runtime|whatwg-fetch|@vitest/web-worker)"],
82
+ ["^react(-dom)?(/|$)"],
83
+ ["^node:", "^@?\\w"],
84
+ ["^@/", "^\\."],
85
+ ["^\\u0000@?\\w"],
86
+ ["^\\u0000"]
87
+ ] }] }
88
+ }];
133
89
  }
134
90
  /**
135
- * Autofixable removal of unused imports.
136
- */
137
- export function unusedImportsConfig() {
138
- return [
139
- {
140
- name: 'eslint-plugin-unused-imports',
141
- plugins: { 'unused-imports': unusedImportsPlugin },
142
- rules: {
143
- /*
144
- * Unlike `@typescript-eslint/no-unused-vars/core` `no-unused-vars`, this rule is
145
- * autofixable - `--fix` deletes the unused import specifier (or the whole import
146
- * statement if nothing from it is used) instead of just reporting it.
147
- */
148
- 'unused-imports/no-unused-imports': 'error',
149
- },
150
- },
151
- ];
91
+ * Autofixable removal of unused imports.
92
+ */
93
+ function unusedImportsConfig() {
94
+ return [{
95
+ name: "eslint-plugin-unused-imports",
96
+ plugins: { "unused-imports": unusedImportsPlugin },
97
+ rules: { "unused-imports/no-unused-imports": "error" }
98
+ }];
152
99
  }
100
+ //#endregion
101
+ export { importSortConfig, importXConfig, unusedImportsConfig };
@@ -1,5 +1,6 @@
1
- import type { Linter } from 'eslint';
2
- import type { ToggleOptions } from '../index.js';
1
+ import { ToggleOptions } from "../index.js";
2
+ import { Linter } from "eslint";
3
+ //#region src/configs/nx.d.ts
3
4
  export declare const nxPlugin: typeof import("@nx/eslint-plugin") | null;
4
5
  /**
5
6
  * Nx blocks: plugin registration + `@nx/dependency-checks` on every `package.json`.
@@ -13,4 +14,4 @@ export declare const nxPlugin: typeof import("@nx/eslint-plugin") | null;
13
14
  *
14
15
  */
15
16
  export declare function nxConfig(option?: boolean | ToggleOptions, strict?: boolean): Promise<Linter.Config[]>;
16
- //# sourceMappingURL=nx.d.ts.map
17
+ //#endregion
@@ -1,43 +1,33 @@
1
- import { existsSync } from 'node:fs';
2
- import { resolve } from 'node:path';
3
- import * as jsoncParser from 'jsonc-eslint-parser';
4
- import { hasNx, toolGate } from '../lib.js';
5
- // lazy so consumers without Nx don't pay the load cost (it drags in a large part of nx itself) -
6
- // re-exported from index.js
7
- export const nxPlugin = hasNx ? (await import('@nx/eslint-plugin')).default : null;
1
+ import { hasNx, toolGate } from "../lib.js";
2
+ import { resolve } from "node:path";
3
+ import { existsSync } from "node:fs";
4
+ import * as jsoncParser from "jsonc-eslint-parser";
5
+ //#region src/configs/nx.ts
6
+ const nxPlugin = hasNx ? (await import("@nx/eslint-plugin")).default : null;
8
7
  /**
9
- * Nx blocks: plugin registration + `@nx/dependency-checks` on every `package.json`.
10
- *
11
- * Only `flat/base` (registers the '@nx' plugin, no rules of its own).
12
- *
13
- * `flat/typescript`/`flat/javascript` were deliberately NOT used - same call as with eslint-plugin-unicorn's
14
- * recommended: they bundle the ENTIRE @stylistic plugin (hundreds of formatting rules - indent, quotes,
15
- * semi, comma-dangle, ...) which would directly fight Prettier, plus a second full copy of
16
- * @typescript-eslint/recommended that would relitigate rules already configured deliberately here.
17
- *
18
- */
19
- export async function nxConfig(option, strict = false) {
20
- const { enabled } = toolGate(option, strict, {
21
- tool: 'nx',
22
- has: hasNx,
23
- // hasNx is the one non-strict `has*` (a workspace-root file check) - strict stays at cwd
24
- strictHas: strict && existsSync(resolve(process.cwd(), 'nx.json')),
25
- });
26
- if (!enabled)
27
- return [];
28
- const nx = (await import('@nx/eslint-plugin')).default;
29
- return [
30
- ...nx.configs['flat/base'],
31
- {
32
- name: '@nx/dependency-checks',
33
- files: ['**/package.json'],
34
- languageOptions: {
35
- parser: jsoncParser,
36
- },
37
- rules: {
38
- // https://nx.dev/docs/technologies/eslint/eslint-plugin/guides/dependency-checks
39
- '@nx/dependency-checks': 'error',
40
- },
41
- },
42
- ];
8
+ * Nx blocks: plugin registration + `@nx/dependency-checks` on every `package.json`.
9
+ *
10
+ * Only `flat/base` (registers the '@nx' plugin, no rules of its own).
11
+ *
12
+ * `flat/typescript`/`flat/javascript` were deliberately NOT used - same call as with eslint-plugin-unicorn's
13
+ * recommended: they bundle the ENTIRE @stylistic plugin (hundreds of formatting rules - indent, quotes,
14
+ * semi, comma-dangle, ...) which would directly fight Prettier, plus a second full copy of
15
+ * @typescript-eslint/recommended that would relitigate rules already configured deliberately here.
16
+ *
17
+ */
18
+ async function nxConfig(option, strict = false) {
19
+ const { enabled } = toolGate(option, strict, {
20
+ tool: "nx",
21
+ has: hasNx,
22
+ strictHas: strict && existsSync(resolve(process.cwd(), "nx.json"))
23
+ });
24
+ if (!enabled) return [];
25
+ return [...(await import("@nx/eslint-plugin")).default.configs["flat/base"], {
26
+ name: "@nx/dependency-checks",
27
+ files: ["**/package.json"],
28
+ languageOptions: { parser: jsoncParser },
29
+ rules: { "@nx/dependency-checks": "error" }
30
+ }];
43
31
  }
32
+ //#endregion
33
+ export { nxConfig, nxPlugin };
@@ -1,4 +1,5 @@
1
- import type { Linter } from 'eslint';
1
+ import { Linter } from "eslint";
2
+ //#region src/configs/prettier.d.ts
2
3
  /**
3
4
  * Prettier compatibility: turns off all rules that would fight the formatter.
4
5
  *
@@ -14,4 +15,4 @@ import type { Linter } from 'eslint';
14
15
  * exported object to improve https://eslint.org/blog/2024/04/eslint-config-inspector/ experience.
15
16
  */
16
17
  export declare function prettierConfig(): Linter.Config[];
17
- //# sourceMappingURL=prettier.d.ts.map
18
+ //#endregion