@kirill.konshin/lint 0.8.8 → 0.8.10

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.
package/README.md CHANGED
@@ -110,7 +110,7 @@ import { defineLintConfig, tsExts } from '@kirill.konshin/lint/config'; // tsExt
110
110
 
111
111
  export default defineLintConfig({
112
112
  // enabled (default true) = tools are ON unless said otherwise;
113
- // strict (default false) = same-scope package probes only, no workspace evidence scans
113
+ // strict (default false) = probes from cwd only, no workspace evidence scans
114
114
  detection: { enabled: true, strict: false }, // default
115
115
 
116
116
  // ON by default; app roots auto-detected (next.config.*, package.json depending on next, src/{app,pages}/);
@@ -146,8 +146,12 @@ export default defineLintConfig({
146
146
  'vercel-labs/agent-skills': { skills: { 'vercel-react-native-skills': false } }, // a default source, one skill left out
147
147
  'mattpocock/skills': { skills: { tdd: true } }, // an extra source, only this skill
148
148
  '@kirill.konshin/lint': { skills: { 'lint-electron': false } }, // this package's own skills
149
+ 'GoogleChrome/modern-web-guidance': { skills: { 'chrome-extensions': true } }, // an opt-in skill of a default source
149
150
  },
150
151
 
152
+ // graphify code graph, see "graphify"; left out: used when `graphify` is on PATH
153
+ graphify: { version: '0.9.102' }, // true or options: installed into .venv with uv; false: off
154
+
151
155
  // package rules by name: false leaves a rule out
152
156
  rules: { redux: false },
153
157
  });
@@ -301,7 +305,7 @@ https://prettier.io/docs/ignore:
301
305
 
302
306
  `eslint.config.mjs`:
303
307
 
304
- Every tool integration — Next.js, Nx, Turborepo, Storybook, Jest, Vitest, Tailwind — is auto-detected (the detection results are exported as `has*` booleans for debugging). Settings come from [`lint.config.ts`](#lintconfigts); `eslintConfig(overrides)` merges its argument over them:
308
+ Every tool integration — Next.js, Nx, Turborepo, Storybook, Jest, Vitest, Tailwind — is auto-detected (the package probes are exported for debugging as `has*` functions - `hasNext()`, `hasNx()`, ...; they run when a gate needs them, never on import). Settings come from [`lint.config.ts`](#lintconfigts); `eslintConfig(overrides)` merges its argument over them:
305
309
 
306
310
  ```js
307
311
  import { defineConfig } from 'eslint/config';
@@ -487,7 +491,7 @@ In the project root, `lint-prepare`:
487
491
  - Installs the skills of the `skills` map of `lint.config.ts`, merged over the defaults, with the [`skills` CLI](https://github.com/vercel-labs/skills), into `.agents/skills/` and from there into `.claude/skills/`. The map is keyed by source, each value uses the toggle notation; `skills: { name: true | false | 'package' }` picks skills of a source — with no `true` or package entry every skill except the `false` ones; with one, only the skills that are on. A package name gates a skill: it is on when the root or a workspace package declares that package in `dependencies` or `devDependencies` (`'vercel-cli': 'vercel'`), off with `detection: false`; `true` / `false` in `lint.config.ts` overrides the gate:
488
492
  - npm packages (`@scope/name`, or a name without `/`) are dependencies that ship skills: `skills experimental_sync -y -r -a codex claude-code` links every `skills/<name>/` folder of the dependencies of the root and of every workspace package; the map only leaves some out (`--exclude`). Default: this package's own skills (`'@kirill.konshin/lint': true`) — e.g. `lint-repo`, which sets up the tooling above and audits the repo against the rules.
489
493
  - Git sources (`owner/repo`) are installed with `skills add`, at `ref` when set (pin a full 40-character commit SHA). A source whose skills `skills-lock.json` already has at the same ref is not fetched again. `lint.config.ts` owns the remote skills of `skills-lock.json`: a remote skill it no longer lists is removed (`skills remove`).
490
- - Defaults — every project gets them, turn off what it does not need: the [Core Pack](https://skills.sh/p/DxVN7q53wGdAcZQt) (`vercel-labs/agent-skills` incl. `web-design-guidelines`, `vercel/ai`, `shadcn-ui/ui`, `heroui-inc/heroui`, `mui/material-ui` without `material-ui-tailwind`, `neondatabase/agent-skills`) and the official skills of the libraries the rules cover (`vercel/next.js`, `reduxjs/redux-toolkit`, `vercel/turborepo`, `nrwl/nx-ai-agents-config`, `expo/skills`, `microsoft/playwright-cli`). Gated by the `vercel` dependency (projects that install the Vercel CLI): `vercel/vercel` (`vercel-cli`) and `deploy-to-vercel` of `vercel-labs/agent-skills`. Each source lists its skills and pins a commit: `DEFAULT_LINT_CONFIG` in `src/config.ts`.
494
+ - Defaults — every project gets them, turn off what it does not need: the [Core Pack](https://skills.sh/p/DxVN7q53wGdAcZQt) (`vercel-labs/agent-skills` incl. `web-design-guidelines`, `vercel/ai`, `shadcn-ui/ui`, `heroui-inc/heroui`, `mui/material-ui` without `material-ui-tailwind`, `neondatabase/agent-skills`) and the official skills of the libraries the rules cover (`vercel/next.js`, `reduxjs/redux-toolkit`, `vercel/turborepo`, `nrwl/nx-ai-agents-config`, `expo/skills`, `microsoft/playwright-cli`), and [Modern Web Guidance](https://developer.chrome.com/docs/modern-web-guidance) (`GoogleChrome/modern-web-guidance`: `modern-web-guidance`; `chrome-extensions` is opt-in). The Modern Web Guidance skill runs its CLI with `npx`: no dependency to add. Gated by the `vercel` dependency (projects that install the Vercel CLI): `vercel/vercel` (`vercel-cli`) and `deploy-to-vercel` of `vercel-labs/agent-skills`. Each source lists its skills and pins a commit: `DEFAULT_LINT_CONFIG` in `src/config.ts`.
491
495
  - A skill folder of yours with the same name in `.agents/skills/` wins.
492
496
  - A failed CLI run is a warning, the install goes on: run `lint-prepare` again.
493
497
  - On CI (`CI` set) nothing remote is fetched (`--no-remote`, no `skills add`): no network needed.
@@ -498,6 +502,24 @@ In the project root, `lint-prepare`:
498
502
  - Removes dead links (e.g. after renaming a file) and the links it placed before but no longer needs, including what older versions placed (skill links, `commands/`). Each directory gets a generated `.gitignore` listing its links and the skills the `skills` CLI installed, so your own entries stay tracked.
499
503
  - Writes an empty marker pair for each section another tool owns into the generated `AGENTS.md` — currently Vite+ (`<!--VITE PLUS START-->`). The tool fills it, so run it **after** `lint-prepare` in the same install script (`lint-prepare init && vp config`): tools write their own agent content, nothing is copied by hand.
500
504
  - 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.
505
+ - Sets up [graphify](#graphify) when `lint.config.ts` asks for it or finds it.
506
+
507
+ ### graphify
508
+
509
+ [graphify](https://graphify.com) builds a code knowledge graph (`graphify-out/`) that agents query instead of grepping. It is a Python tool (PyPI `graphifyy`), so it is not a dependency: `lint-prepare` sets it up by the `graphify` key of [`lint.config.ts`](#lintconfigts):
510
+
511
+ | `graphify` | Executable | Skill | AGENTS.md section, Claude Code hooks | Root `.gitignore` |
512
+ | ------------------------------ | ------------------------------------------------------------- | ----- | ------------------------------------ | ------------------------- |
513
+ | left out | `graphify` on `PATH` (any install); none: skipped with a note | yes | no | `/graphify-out` |
514
+ | `true`, `{ version: '0.9.x' }` | project `.venv`, created with `uv` (required) | yes | yes | `/graphify-out`, `/.venv` |
515
+ | `false` | none | no | removed | none |
516
+
517
+ - The skills: graphify installs them where skills live (`graphify install --project`): the generic flavor into `.agents/skills/graphify` (Codex), the Claude Code flavor into `.claude/skills/graphify`, which also registers it in `.claude/CLAUDE.md`. Both are git-ignored like the skills the `skills` CLI installs (`lint-prepare` knows them by graphify's `.graphify_version` stamp); `false` removes them and the registration.
518
+ - The graph: `graphify update .` (code only, no LLM, no API key) after everything else. Commit nothing of `graphify-out/`.
519
+ - `true` only, committed, so every clone gets the same: `lint-prepare` writes a `## graphify` heading into the generated `AGENTS.md`, followed by its own `## graphify virtualenv` heading with how to reach `.venv`; then `graphify claude install` fills the `## graphify` section (it replaces up to the next `##` heading) and writes its hooks into `.claude/settings.json`, which `lint-prepare` points at `"$CLAUDE_PROJECT_DIR"/.venv/bin/graphify`. The next generation keeps the section.
520
+ - `graphifyy` version for `.venv`: `GRAPHIFY_VERSION` of `@kirill.konshin/lint/config`, or `version`.
521
+ - Nothing on CI; a failed graphify run is a warning, except a missing `uv` for `true`. `engines.uv` of this package documents the `uv` version.
522
+ - The root `.gitignore` gets a marked block (`# @kirill.konshin/lint: graphify`); it follows `lint.config.ts` only, never what a machine has. Vite+ ignores `graphify-out` too.
501
523
 
502
524
  ### OpenSpec
503
525
 
@@ -673,14 +695,14 @@ Due to limitations package visibility between leaf and root this package has to
673
695
  </tbody>
674
696
  </table>
675
697
 
676
- ¹ the plugins need the tool's package resolvable at lint time (`tailwindcss` for the theme-loading workers, `next` for `eslint-config-next`'s internal `require`s, `storybook` for its plugin's static import, `jest` for version sniffing) — resolvable from the workspace root, or the hard error of step 3 fires.
698
+ ¹ the plugins need the tool's package resolvable at lint time (`tailwindcss` for the theme-loading workers, `next` for `eslint-config-next`'s internal `require`s, `storybook` for its plugin's static import, `jest` for version sniffing) — resolvable from the workspace root, or the hard error of step 3 fires. Exception: `jest` is only needed for the version of `jest/no-deprecated-functions`, so a leaf-only install passes its version in `settings.jest.version`, and with none anywhere that one rule is off.
677
699
 
678
- `vitePlusConfig` runs the same gates (`src/gates.ts`, shared with the ESLint blocks), with three differences: Oxlint JS plugins load from this package, so only `storybook` (its plugin imports `storybook`), `nx` (needs `eslint`) and `tailwind` (needs `eslint`, a known gap, see [Issues](#issues), besides `tailwindcss`) demand a resolvable package; `vitest` is ON unless set to `false` (Vite+ bundles it); `next` needs no package (Oxlint's `nextjs` plugin is native). `typeAware` differs by backend: `eslint.typeAware` is OFF by default (slow), `vitePlus.typeAware` ON.
700
+ `vitePlusConfig` runs the same gates (`src/gates.ts`, shared with the ESLint blocks), with three differences: Oxlint JS plugins load from this package, so only `storybook` (its plugin imports `storybook`), `nx` (needs `eslint`) and `tailwind` (needs `eslint`, a known gap, see [Issues](#issues), besides `tailwindcss`) demand a resolvable package; `vitest` is ON unless set to `false` or Jest is detected (Vite+ bundles Vitest; set both to lint a repo that runs both); `next` needs no package (Oxlint's `nextjs` plugin is native). `typeAware` differs by backend: `eslint.typeAware` is OFF by default (slow), `vitePlus.typeAware` ON.
679
701
 
680
702
  The machinery is controlled by the `detection` key of `lint.config.ts` (same toggle notation as the tools):
681
703
 
682
704
  - `detection: false` — tools are OFF unless explicitly enabled; enabled tools still auto-detect their settings (step 2)
683
- - `detection: { strict: true }` — only step 1 runs: the `has*` package probes **are** the strict detection — no workspace evidence scans (2). Mandatory settings (`cssConfigPath`) must then be explicit, and `nx.json` is checked at **cwd** instead of the workspace root (`hasNx` is the only non-package `has*`)
705
+ - `detection: { strict: true }` — only step 1 runs, from **cwd** instead of the workspace root: each tool's package resolvable from cwd, `nx.json` at cwd — no workspace evidence scans (2). Mandatory settings (`cssConfigPath`) must then be explicit
684
706
  - `detection: { enabled: false, strict: true }` — fully explicit: tools on only when set, probes only
685
707
 
686
708
  Set `LINT_DEBUG=1` to trace the machinery: `has*` probe results, every workspace scan (glob, root, files found) and each tool's gate verdict (supplied options, absolutized & scanned evidence files, effective enabled status + reason).
package/dist/config.d.ts CHANGED
@@ -59,6 +59,15 @@ export type SkillSourceOptions = ToggleOptions & {
59
59
  * `false` is `{ enabled: false }`.
60
60
  */
61
61
  export type SkillsConfig = Record<string, boolean | SkillSourceOptions>;
62
+ /**
63
+ * graphify (https://graphify.com), a code knowledge graph for agents, set up by `lint-prepare`. Left out, it is
64
+ * detected: a `graphify` on `PATH` gets the skill and a graph build. `true` (or options) installs it into the project
65
+ * `.venv` with `uv` and also writes its AGENTS.md section and Claude Code hooks. `false` turns it off.
66
+ */
67
+ export type GraphifyOptions = ToggleOptions & {
68
+ /** Version of the `graphifyy` PyPI package installed into `.venv`, see {@link GRAPHIFY_VERSION}. */
69
+ version?: string;
70
+ };
62
71
  export type LintConfig = {
63
72
  detection?: boolean | DetectionOptions;
64
73
  next?: boolean | NextOptions;
@@ -72,10 +81,14 @@ export type LintConfig = {
72
81
  vitePlus?: VitePlusOptions;
73
82
  /** Skills `lint-prepare` installs, merged over {@link DEFAULT_LINT_CONFIG}. */
74
83
  skills?: SkillsConfig;
84
+ /** Detected when left out, see {@link GraphifyOptions}. */
85
+ graphify?: boolean | GraphifyOptions;
75
86
  /** Package rules by name (file name without `.md`): `false` leaves a rule out. */
76
87
  rules?: Record<string, boolean>;
77
88
  };
78
89
  export declare const LINT_CONFIG_FILE = "lint.config.ts";
90
+ /** The `graphifyy` version `graphify: true` installs into `.venv`, unless `version` overrides it. */
91
+ export declare const GRAPHIFY_VERSION = "0.9.102";
79
92
  /**
80
93
  * The base every resolved config starts from. Every project gets every skill below, except the skills a package name
81
94
  * gates (`'vercel-cli': 'vercel'`), which only the projects depending on that package get; `lint.config.ts` turns off
package/dist/config.js CHANGED
@@ -5,6 +5,8 @@ import { join } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
6
  //#region src/config.ts
7
7
  const LINT_CONFIG_FILE = "lint.config.ts";
8
+ /** The `graphifyy` version `graphify: true` installs into `.venv`, unless `version` overrides it. */
9
+ const GRAPHIFY_VERSION = "0.9.102";
8
10
  /** `{ name: true }` for each name. */
9
11
  const only = (...names) => Object.fromEntries(names.map((name) => [name, true]));
10
12
  /**
@@ -72,6 +74,10 @@ const DEFAULT_LINT_CONFIG = { skills: {
72
74
  "microsoft/playwright-cli": {
73
75
  ref: "b1a5903c5b633b8c9f843ad7b629c2a78437040c",
74
76
  skills: only("playwright-cli")
77
+ },
78
+ "GoogleChrome/modern-web-guidance": {
79
+ ref: "64a6d708f5a43f2cd3fde5d4d7db3905ba1bdf65",
80
+ skills: only("modern-web-guidance")
75
81
  }
76
82
  } };
77
83
  /** Type-checks `lint.config.ts`; returns the config as it is. */
@@ -117,4 +123,4 @@ async function resolveLintConfig(overrides = {}, root = findWorkspaceRoot()) {
117
123
  return mergeLintConfig(mergeLintConfig(DEFAULT_LINT_CONFIG, await loadLintConfig(root)), overrides);
118
124
  }
119
125
  //#endregion
120
- export { DEFAULT_LINT_CONFIG, LINT_CONFIG_FILE, defineLintConfig, loadLintConfig, mergeLintConfig, resolveLintConfig, scanWorkspace, tsExts };
126
+ export { DEFAULT_LINT_CONFIG, GRAPHIFY_VERSION, LINT_CONFIG_FILE, defineLintConfig, loadLintConfig, mergeLintConfig, resolveLintConfig, scanWorkspace, tsExts };
@@ -1,4 +1,5 @@
1
1
  import { GLOBAL_IGNORES, asOptions } from "../lib.js";
2
+ import { coreRules } from "../conventions.js";
2
3
  import { dirname, resolve } from "node:path";
3
4
  import { fileURLToPath } from "node:url";
4
5
  import { includeIgnoreFile as includeIgnoreFile$1 } from "@eslint/config-helpers";
@@ -33,10 +34,7 @@ function baseConfig() {
33
34
  {
34
35
  name: "ESLint overrides",
35
36
  rules: {
36
- "no-restricted-imports": ["error", { paths: [{
37
- name: "next/router",
38
- message: "Please use next/navigation instead of next/router"
39
- }] }],
37
+ ...coreRules,
40
38
  "multiline-comment-style": "off"
41
39
  }
42
40
  }
@@ -1,7 +1,9 @@
1
1
  import { ToggleOptions } from "../config.js";
2
2
  import { Linter } from "eslint";
3
+ import nxPlugin from "@nx/eslint-plugin";
3
4
  //#region src/configs/nx.d.ts
4
- export declare const nxPlugin: typeof import("@nx/eslint-plugin") | null;
5
+ /** `@nx/eslint-plugin`, loaded on demand: it drags in a large part of Nx itself. */
6
+ export declare const loadNxPlugin: () => Promise<typeof nxPlugin>;
5
7
  /**
6
8
  * Nx blocks: plugin registration + `@nx/dependency-checks` on every `package.json`.
7
9
  *
@@ -1,8 +1,8 @@
1
- import { hasNx } from "../lib.js";
2
1
  import { nxGate } from "../gates.js";
3
2
  import * as jsoncParser from "jsonc-eslint-parser";
4
3
  //#region src/configs/nx.ts
5
- const nxPlugin = hasNx ? (await import("@nx/eslint-plugin")).default : null;
4
+ /** `@nx/eslint-plugin`, loaded on demand: it drags in a large part of Nx itself. */
5
+ const loadNxPlugin = async () => (await import("@nx/eslint-plugin")).default;
6
6
  /**
7
7
  * Nx blocks: plugin registration + `@nx/dependency-checks` on every `package.json`.
8
8
  *
@@ -17,7 +17,7 @@ const nxPlugin = hasNx ? (await import("@nx/eslint-plugin")).default : null;
17
17
  async function nxConfig(option, strict = false) {
18
18
  const { enabled } = nxGate(option, strict);
19
19
  if (!enabled) return [];
20
- return [...(await import("@nx/eslint-plugin")).default.configs["flat/base"], {
20
+ return [...(await loadNxPlugin()).configs["flat/base"], {
21
21
  name: "@nx/dependency-checks",
22
22
  files: ["**/package.json"],
23
23
  languageOptions: { parser: jsoncParser },
@@ -25,4 +25,4 @@ async function nxConfig(option, strict = false) {
25
25
  }];
26
26
  }
27
27
  //#endregion
28
- export { nxConfig, nxPlugin };
28
+ export { loadNxPlugin, nxConfig };
@@ -1,3 +1,4 @@
1
+ import { promiseRules } from "../conventions.js";
1
2
  import promisePlugin from "eslint-plugin-promise";
2
3
  //#region src/configs/promise.ts
3
4
  /**
@@ -6,12 +7,7 @@ import promisePlugin from "eslint-plugin-promise";
6
7
  function promiseConfig() {
7
8
  return [promisePlugin.configs["flat/recommended"], {
8
9
  name: "eslint-plugin-promise overrides",
9
- rules: {
10
- "promise/prefer-await-to-then": "warn",
11
- "promise/param-names": "off",
12
- "promise/always-return": "off",
13
- "promise/catch-or-return": "off"
14
- }
10
+ rules: promiseRules
15
11
  }];
16
12
  }
17
13
  //#endregion
@@ -1,7 +1,9 @@
1
1
  import { NextOptions } from "../config.js";
2
2
  import { Linter } from "eslint";
3
+ import nextPlugin from "@next/eslint-plugin-next";
3
4
  //#region src/configs/react.d.ts
4
- export declare const nextPlugin: typeof import("@next/eslint-plugin-next") | null;
5
+ /** `@next/eslint-plugin-next`, loaded on demand: consumers without Next never pay for it. */
6
+ export declare const loadNextPlugin: () => Promise<typeof nextPlugin>;
5
7
  /**
6
8
  * Next.js blocks: the whole `eslint-config-next` flat config, plus `settings.next.rootDir`.
7
9
  *
@@ -31,7 +33,7 @@ export declare function reactBaseConfig(): Linter.Config[];
31
33
  * otherwise. Full evidence-based gate (see `nextGate` in gates.js), mirroring Tailwind: app-root
32
34
  * evidence (see {@link findNextRoots} - `next.config.*`, a `package.json` depending on `next`, a
33
35
  * `src/app`/`src/pages` tree) marks a Next repo even when the `next` package is installed only in
34
- * a leaf app (invisible to `hasNext`) - and because `eslint-config-next` `require`s files INSIDE
36
+ * a leaf app (invisible to `hasNext()`) - and because `eslint-config-next` `require`s files INSIDE
35
37
  * the `next` package, `next` must be resolvable from the workspace root (hoisted); a leaf-only
36
38
  * install is a hard error with hoisting guidance (see `nextGate` in gates.js).
37
39
  *
@@ -1,5 +1,6 @@
1
- import { GLOBAL_IGNORES, findNextRoots, hasNext } from "../lib.js";
2
- import { tsExts } from "../exts.js";
1
+ import { GLOBAL_IGNORES, findNextRoots } from "../lib.js";
2
+ import { tsFiles } from "../exts.js";
3
+ import { declarationFileRules, nextRules, reactRules, typescriptRules } from "../conventions.js";
3
4
  import { nextGate } from "../gates.js";
4
5
  import { dirname } from "node:path";
5
6
  import nextTs from "eslint-config-next/typescript";
@@ -7,7 +8,8 @@ import jsxA11yPlugin from "eslint-plugin-jsx-a11y";
7
8
  import reactPlugin from "eslint-plugin-react";
8
9
  import reactHooksPlugin from "eslint-plugin-react-hooks";
9
10
  //#region src/configs/react.ts
10
- const nextPlugin = hasNext ? (await import("@next/eslint-plugin-next")).default : null;
11
+ /** `@next/eslint-plugin-next`, loaded on demand: consumers without Next never pay for it. */
12
+ const loadNextPlugin = async () => (await import("@next/eslint-plugin-next")).default;
11
13
  /**
12
14
  * Next.js blocks: the whole `eslint-config-next` flat config, plus `settings.next.rootDir`.
13
15
  *
@@ -49,7 +51,7 @@ function reactBaseConfig() {
49
51
  * otherwise. Full evidence-based gate (see `nextGate` in gates.js), mirroring Tailwind: app-root
50
52
  * evidence (see {@link findNextRoots} - `next.config.*`, a `package.json` depending on `next`, a
51
53
  * `src/app`/`src/pages` tree) marks a Next repo even when the `next` package is installed only in
52
- * a leaf app (invisible to `hasNext`) - and because `eslint-config-next` `require`s files INSIDE
54
+ * a leaf app (invisible to `hasNext()`) - and because `eslint-config-next` `require`s files INSIDE
53
55
  * the `next` package, `next` must be resolvable from the workspace root (hoisted); a leaf-only
54
56
  * install is a hard error with hoisting guidance (see `nextGate` in gates.js).
55
57
  *
@@ -73,36 +75,17 @@ function typescriptOverridesConfig() {
73
75
  ...nextTs,
74
76
  {
75
77
  name: "@typescript-eslint overrides",
76
- files: [`**/*.${tsExts}`],
78
+ files: [tsFiles],
77
79
  rules: {
78
80
  "@typescript-eslint/explicit-module-boundary-types": "off",
79
- "@typescript-eslint/no-empty-function": "off",
80
- "@typescript-eslint/no-explicit-any": "off",
81
- "@typescript-eslint/no-require-imports": "off",
82
81
  "@typescript-eslint/no-unused-vars": "off",
83
- "@typescript-eslint/consistent-type-definitions": ["error", "type"],
84
- "@typescript-eslint/consistent-type-imports": ["error", {
85
- prefer: "type-imports",
86
- fixStyle: "inline-type-imports"
87
- }],
88
- "@typescript-eslint/ban-ts-comment": ["error", {
89
- "ts-expect-error": "allow-with-description",
90
- "ts-ignore": true,
91
- "ts-nocheck": true,
92
- "ts-check": false,
93
- minimumDescriptionLength: 3
94
- }],
95
- "@typescript-eslint/prefer-as-const": "error"
82
+ ...typescriptRules
96
83
  }
97
84
  },
98
85
  {
99
86
  name: "@typescript-eslint declaration-file overrides",
100
87
  files: ["**/*.d.ts"],
101
- rules: { "@typescript-eslint/consistent-type-imports": ["error", {
102
- prefer: "type-imports",
103
- fixStyle: "inline-type-imports",
104
- disallowTypeAnnotations: false
105
- }] }
88
+ rules: declarationFileRules
106
89
  }
107
90
  ];
108
91
  }
@@ -116,10 +99,8 @@ function nextOverridesConfig() {
116
99
  return [{
117
100
  name: "eslint-config-next overrides",
118
101
  rules: {
119
- "@next/next/no-html-link-for-pages": "off",
120
- "@next/next/no-img-element": "off",
121
- "import/no-anonymous-default-export": "off",
122
- "jsx-a11y/alt-text": "off",
102
+ ...nextRules,
103
+ ...reactRules,
123
104
  "react/prop-types": "off"
124
105
  }
125
106
  }];
@@ -150,4 +131,4 @@ async function reactConfig(option, strict = false) {
150
131
  ];
151
132
  }
152
133
  //#endregion
153
- export { nextBaseConfig, nextConfig, nextOverridesConfig, nextPlugin, reactBaseConfig, reactConfig, reactSettingsConfig, typescriptOverridesConfig };
134
+ export { loadNextPlugin, nextBaseConfig, nextConfig, nextOverridesConfig, reactBaseConfig, reactConfig, reactSettingsConfig, typescriptOverridesConfig };
@@ -1,20 +1,41 @@
1
- import { tsExts } from "../exts.js";
1
+ import { hasJest } from "../lib.js";
2
+ import { testFiles } from "../exts.js";
3
+ import { testRunnerRules, vitestRules } from "../conventions.js";
2
4
  import { jestGate, vitestGate } from "../gates.js";
3
5
  import { testColocation } from "../testColocation.js";
6
+ import { dirname } from "node:path";
7
+ import { getPackageInfoSync } from "local-pkg";
4
8
  import vitestPlugin from "@vitest/eslint-plugin";
5
9
  import jestPlugin from "eslint-plugin-jest";
6
10
  //#region src/configs/testing.ts
7
11
  /**
12
+ * The major version `jest/no-deprecated-functions` needs, when eslint-plugin-jest cannot find `jest` itself (it
13
+ * resolves `jest` from its own install, the workspace root): read from the install next to a Jest config file. `null`
14
+ * when there is none anywhere - the rule would throw, so it goes off; `undefined` when the plugin finds `jest` itself.
15
+ */
16
+ function jestVersion(configFiles) {
17
+ if (hasJest()) return void 0;
18
+ const version = configFiles.map((file) => getPackageInfoSync("jest", { paths: [dirname(file)] })?.version).find(Boolean);
19
+ return version ? Number.parseInt(version, 10) : null;
20
+ }
21
+ /**
8
22
  * Jest recommended rules, scoped to test files.
9
23
  *
10
24
  */
11
25
  function jestConfig(option, strict = false) {
12
- const { enabled } = jestGate(option, strict);
26
+ const { enabled, files } = jestGate(option, strict);
13
27
  if (!enabled) return [];
28
+ const version = jestVersion(files);
29
+ const recommended = jestPlugin.configs["flat/recommended"];
14
30
  return [{
15
- ...jestPlugin.configs["flat/recommended"],
31
+ ...recommended,
16
32
  name: "Jest Rules",
17
- files: [`**/*.{test,spec}.${tsExts}`]
33
+ files: [testFiles],
34
+ ...version ? { settings: { jest: { version } } } : {},
35
+ ...version === null ? { rules: {
36
+ ...recommended.rules,
37
+ "jest/no-deprecated-functions": "off"
38
+ } } : {}
18
39
  }];
19
40
  }
20
41
  /**
@@ -27,20 +48,15 @@ function vitestConfig(option, strict = false) {
27
48
  return [{
28
49
  ...vitestPlugin.configs.recommended,
29
50
  name: "Vitest Rules",
30
- files: [`**/*.{test,spec}.${tsExts}`],
51
+ files: [testFiles],
31
52
  rules: {
32
53
  ...vitestPlugin.configs.recommended.rules,
33
- "vitest/expect-expect": ["error", { assertFunctionNames: [
34
- "expect",
35
- "assert",
36
- "expectTypeOf",
37
- "assertType"
38
- ] }]
54
+ ...vitestRules
39
55
  }
40
56
  }, {
41
57
  ...vitestPlugin.configs.env,
42
58
  name: "Vitest globals",
43
- files: [`**/*.{test,spec}.${tsExts}`]
59
+ files: [testFiles]
44
60
  }];
45
61
  }
46
62
  /**
@@ -51,18 +67,16 @@ function vitestConfig(option, strict = false) {
51
67
  function testConfig() {
52
68
  return [{
53
69
  name: "Test rules",
54
- files: [`**/*.{test,spec}.${tsExts}`],
70
+ files: [testFiles],
55
71
  plugins: {
56
72
  jest: jestPlugin,
57
73
  vitest: vitestPlugin,
58
74
  local: { rules: { "test-colocation": testColocation } }
59
75
  },
60
76
  rules: {
61
- "jest/consistent-test-it": ["error", { fn: "test" }],
62
- "vitest/consistent-test-it": ["error", { fn: "test" }],
63
- "local/test-colocation": "error",
64
- "jest/no-disabled-tests": "warn",
65
- "vitest/no-disabled-tests": "warn"
77
+ ...testRunnerRules("jest"),
78
+ ...testRunnerRules("vitest"),
79
+ "local/test-colocation": "error"
66
80
  }
67
81
  }];
68
82
  }
@@ -1,10 +1,11 @@
1
1
  import { ToggleOptions } from "../config.js";
2
2
  import { Linter } from "eslint";
3
+ import turboPlugin from "eslint-plugin-turbo";
3
4
  //#region src/configs/turbo.d.ts
4
- export declare const turboPlugin: typeof import("eslint-plugin-turbo") | null;
5
+ /** `eslint-plugin-turbo`, loaded on demand: consumers without Turbo never pay for it. */
6
+ export declare const loadTurboPlugin: () => Promise<typeof turboPlugin>;
5
7
  /**
6
- * Turborepo rules. Probe-only gate (see `turboGate` in gates.js) - no evidence scan, no bridge.
7
- *
8
+ * Turborepo rules. Probe-only gate (see `turboGate` in gates.js) - no evidence scan.
8
9
  */
9
10
  export declare function turboConfig(option?: boolean | ToggleOptions): Promise<Linter.Config[]>;
10
11
  //#endregion
@@ -1,19 +1,17 @@
1
- import { hasTurbo } from "../lib.js";
2
1
  import { turboGate } from "../gates.js";
3
2
  //#region src/configs/turbo.ts
4
- const turboPlugin = hasTurbo ? (await import("eslint-plugin-turbo")).default : null;
3
+ /** `eslint-plugin-turbo`, loaded on demand: consumers without Turbo never pay for it. */
4
+ const loadTurboPlugin = async () => (await import("eslint-plugin-turbo")).default;
5
5
  /**
6
- * Turborepo rules. Probe-only gate (see `turboGate` in gates.js) - no evidence scan, no bridge.
7
- *
6
+ * Turborepo rules. Probe-only gate (see `turboGate` in gates.js) - no evidence scan.
8
7
  */
9
8
  async function turboConfig(option) {
10
9
  const { enabled } = turboGate(option);
11
10
  if (!enabled) return [];
12
- const recommended = (await import("eslint-plugin-turbo")).default.configs?.["flat/recommended"];
13
- return [...Array.isArray(recommended) ? recommended : [recommended ?? {}], {
11
+ return [(await loadTurboPlugin()).configs?.["flat/recommended"] ?? {}, {
14
12
  name: "eslint-plugin-turbo overrides",
15
13
  rules: { "turbo/no-undeclared-env-vars": "warn" }
16
14
  }];
17
15
  }
18
16
  //#endregion
19
- export { turboConfig, turboPlugin };
17
+ export { loadTurboPlugin, turboConfig };
@@ -1,4 +1,4 @@
1
- import { tsExts } from "../exts.js";
1
+ import { tsFiles } from "../exts.js";
2
2
  import { filenameCaseIgnore } from "../conventions.js";
3
3
  import unicornPlugin from "eslint-plugin-unicorn";
4
4
  //#region src/configs/unicorn.ts
@@ -12,7 +12,7 @@ import unicornPlugin from "eslint-plugin-unicorn";
12
12
  function unicornConfig() {
13
13
  return [{
14
14
  name: "Unicorn rules",
15
- files: [`**/*.${tsExts}`],
15
+ files: [tsFiles],
16
16
  plugins: { unicorn: unicornPlugin },
17
17
  rules: {
18
18
  "unicorn/filename-case": ["error", {
@@ -1,4 +1,28 @@
1
+ import { Linter } from "eslint";
1
2
  //#region src/conventions.d.ts
3
+ type Rules = Linter.RulesRecord;
4
+ /** `next/router` is the Pages Router API; App Router code imports `next/navigation`. */
5
+ export declare const coreRules: Rules;
6
+ /** The deliberate TypeScript settings, on top of each linter's recommended set. */
7
+ export declare const typescriptRules: Rules;
8
+ /**
9
+ * Declaration files: `typeof import('pkg')` annotations are the standard mechanism there (tsc itself emits them) -
10
+ * the annotation ban of `consistent-type-imports` is meant for source files.
11
+ */
12
+ export declare const declarationFileRules: Rules;
13
+ /** Next.js rules turned off: plain `<a>` and `<img>` are allowed. */
14
+ export declare const nextRules: Rules;
15
+ /** React-side rules of `eslint-config-next` turned off, for plain React projects too. */
16
+ export declare const reactRules: Rules;
17
+ /** Promise rules: `await` preferred, the rest of the recommended strictness relaxed. */
18
+ export declare const promiseRules: Rules;
19
+ /** Test-runner rules, the same for Jest and Vitest: `test()`, not `it()`, and no skipped tests left behind. */
20
+ export declare const testRunnerRules: (runner: "jest" | "vitest") => Rules;
21
+ /**
22
+ * `expectTypeOf` and `assertType` are assertions too: a type test proves its contract without a runtime expect.
23
+ * Listed here rather than through the plugin's `typecheck` setting, which makes other rules demand type information.
24
+ */
25
+ export declare const vitestRules: Rules;
2
26
  /**
3
27
  * Files that legitimately default-export (framework/tooling conventions): configs, stories, Storybook, Next.js App
4
28
  * Router files and declarations.
@@ -9,4 +33,5 @@ export declare const defaultExportFiles: string[];
9
33
  * `App` entry, declarations follow the package they describe, and electron-builder looks up its own config name.
10
34
  */
11
35
  export declare const filenameCaseIgnore: RegExp[];
12
- //#endregion
36
+ //#endregion
37
+ export {};
@@ -1,5 +1,70 @@
1
1
  import { tsExts } from "./exts.js";
2
2
  //#region src/conventions.ts
3
+ /** `next/router` is the Pages Router API; App Router code imports `next/navigation`. */
4
+ const coreRules = { "no-restricted-imports": ["error", { paths: [{
5
+ name: "next/router",
6
+ message: "Please use next/navigation instead of next/router"
7
+ }] }] };
8
+ const typeImports = {
9
+ prefer: "type-imports",
10
+ fixStyle: "inline-type-imports"
11
+ };
12
+ /** The deliberate TypeScript settings, on top of each linter's recommended set. */
13
+ const typescriptRules = {
14
+ "@typescript-eslint/no-empty-function": "off",
15
+ "@typescript-eslint/no-explicit-any": "off",
16
+ "@typescript-eslint/no-require-imports": "off",
17
+ "@typescript-eslint/consistent-type-definitions": ["error", "type"],
18
+ "@typescript-eslint/consistent-type-imports": ["error", typeImports],
19
+ "@typescript-eslint/ban-ts-comment": ["error", {
20
+ "ts-expect-error": "allow-with-description",
21
+ "ts-ignore": true,
22
+ "ts-nocheck": true,
23
+ "ts-check": false,
24
+ minimumDescriptionLength: 3
25
+ }],
26
+ "@typescript-eslint/prefer-as-const": "error"
27
+ };
28
+ /**
29
+ * Declaration files: `typeof import('pkg')` annotations are the standard mechanism there (tsc itself emits them) -
30
+ * the annotation ban of `consistent-type-imports` is meant for source files.
31
+ */
32
+ const declarationFileRules = { "@typescript-eslint/consistent-type-imports": ["error", {
33
+ ...typeImports,
34
+ disallowTypeAnnotations: false
35
+ }] };
36
+ /** Next.js rules turned off: plain `<a>` and `<img>` are allowed. */
37
+ const nextRules = {
38
+ "@next/next/no-html-link-for-pages": "off",
39
+ "@next/next/no-img-element": "off"
40
+ };
41
+ /** React-side rules of `eslint-config-next` turned off, for plain React projects too. */
42
+ const reactRules = {
43
+ "import/no-anonymous-default-export": "off",
44
+ "jsx-a11y/alt-text": "off"
45
+ };
46
+ /** Promise rules: `await` preferred, the rest of the recommended strictness relaxed. */
47
+ const promiseRules = {
48
+ "promise/prefer-await-to-then": "warn",
49
+ "promise/param-names": "off",
50
+ "promise/always-return": "off",
51
+ "promise/catch-or-return": "off"
52
+ };
53
+ /** Test-runner rules, the same for Jest and Vitest: `test()`, not `it()`, and no skipped tests left behind. */
54
+ const testRunnerRules = (runner) => ({
55
+ [`${runner}/consistent-test-it`]: ["error", { fn: "test" }],
56
+ [`${runner}/no-disabled-tests`]: "warn"
57
+ });
58
+ /**
59
+ * `expectTypeOf` and `assertType` are assertions too: a type test proves its contract without a runtime expect.
60
+ * Listed here rather than through the plugin's `typecheck` setting, which makes other rules demand type information.
61
+ */
62
+ const vitestRules = { "vitest/expect-expect": ["error", { assertFunctionNames: [
63
+ "expect",
64
+ "assert",
65
+ "expectTypeOf",
66
+ "assertType"
67
+ ] }] };
3
68
  /**
4
69
  * Files that legitimately default-export (framework/tooling conventions): configs, stories, Storybook, Next.js App
5
70
  * Router files and declarations.
@@ -50,4 +115,4 @@ const filenameCaseIgnore = [
50
115
  /^electron-builder\..+$/
51
116
  ];
52
117
  //#endregion
53
- export { defaultExportFiles, filenameCaseIgnore };
118
+ export { coreRules, declarationFileRules, defaultExportFiles, filenameCaseIgnore, nextRules, promiseRules, reactRules, testRunnerRules, typescriptRules, vitestRules };
package/dist/exts.d.ts CHANGED
@@ -6,4 +6,7 @@ export declare const prettierExtsRaw = "css,scss,sass,less,yml,yaml,json,json5,j
6
6
  export declare const tsExts = "{js,jsx,ts,tsx,cjs,cts,mjs,mts}";
7
7
  export declare const eslintExts = "*.{js,jsx,ts,tsx,cjs,cts,mjs,mts,md,mdx,htm,html,vue}";
8
8
  export declare const prettierExts = "*.{css,scss,sass,less,yml,yaml,json,json5,jsonc,graphql,graphqls,xml}";
9
+ /** Every code file, and every test file, as globs. */
10
+ export declare const tsFiles = "**/*.{js,jsx,ts,tsx,cjs,cts,mjs,mts}";
11
+ export declare const testFiles = "**/*.{test,spec}.{js,jsx,ts,tsx,cjs,cts,mjs,mts}";
9
12
  //#endregion
package/dist/exts.js CHANGED
@@ -6,5 +6,8 @@ const prettierExtsRaw = "css,scss,sass,less,yml,yaml,json,json5,jsonc,graphql,gr
6
6
  const tsExts = `{${tsExtsRaw}}`;
7
7
  const eslintExts = `*.{${eslintExtsRaw}}`;
8
8
  const prettierExts = `*.{${prettierExtsRaw}}`;
9
+ /** Every code file, and every test file, as globs. */
10
+ const tsFiles = `**/*.${tsExts}`;
11
+ const testFiles = `**/*.{test,spec}.${tsExts}`;
9
12
  //#endregion
10
- export { eslintExts, eslintExtsRaw, markupExtsRaw, prettierExts, prettierExtsRaw, tsExts, tsExtsRaw };
13
+ export { eslintExts, eslintExtsRaw, markupExtsRaw, prettierExts, prettierExtsRaw, testFiles, tsExts, tsExtsRaw, tsFiles };