@kirill.konshin/lint 0.8.9 → 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 +5 -5
- package/dist/configs/base.js +2 -4
- package/dist/configs/nx.d.ts +3 -1
- package/dist/configs/nx.js +4 -4
- package/dist/configs/promise.js +2 -6
- package/dist/configs/react.d.ts +4 -2
- package/dist/configs/react.js +12 -31
- package/dist/configs/testing.js +32 -18
- package/dist/configs/turbo.d.ts +4 -3
- package/dist/configs/turbo.js +5 -7
- package/dist/configs/unicorn.js +2 -2
- package/dist/conventions.d.ts +26 -1
- package/dist/conventions.js +66 -1
- package/dist/exts.d.ts +3 -0
- package/dist/exts.js +4 -1
- package/dist/gates.d.ts +5 -5
- package/dist/gates.js +36 -24
- package/dist/graphify.d.ts +10 -5
- package/dist/graphify.js +35 -40
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -8
- package/dist/lib.d.ts +37 -21
- package/dist/lib.js +104 -71
- package/dist/lintPrepare.d.ts +11 -8
- package/dist/lintPrepare.js +39 -37
- package/dist/runCommand.d.ts +24 -0
- package/dist/runCommand.js +12 -0
- package/dist/textBlocks.d.ts +7 -0
- package/dist/textBlocks.js +12 -0
- package/dist/vitePlus.js +34 -68
- package/package.json +1 -1
- package/skills/spec-tools/scripts/cli.js +700 -627
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) =
|
|
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}/);
|
|
@@ -305,7 +305,7 @@ https://prettier.io/docs/ignore:
|
|
|
305
305
|
|
|
306
306
|
`eslint.config.mjs`:
|
|
307
307
|
|
|
308
|
-
Every tool integration — Next.js, Nx, Turborepo, Storybook, Jest, Vitest, Tailwind — is auto-detected (the
|
|
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:
|
|
309
309
|
|
|
310
310
|
```js
|
|
311
311
|
import { defineConfig } from 'eslint/config';
|
|
@@ -695,14 +695,14 @@ Due to limitations package visibility between leaf and root this package has to
|
|
|
695
695
|
</tbody>
|
|
696
696
|
</table>
|
|
697
697
|
|
|
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.
|
|
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.
|
|
699
699
|
|
|
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` (Vite+ bundles
|
|
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.
|
|
701
701
|
|
|
702
702
|
The machinery is controlled by the `detection` key of `lint.config.ts` (same toggle notation as the tools):
|
|
703
703
|
|
|
704
704
|
- `detection: false` — tools are OFF unless explicitly enabled; enabled tools still auto-detect their settings (step 2)
|
|
705
|
-
- `detection: { strict: true }` — only step 1 runs
|
|
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
|
|
706
706
|
- `detection: { enabled: false, strict: true }` — fully explicit: tools on only when set, probes only
|
|
707
707
|
|
|
708
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/configs/base.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/dist/configs/nx.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
*
|
package/dist/configs/nx.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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 {
|
|
28
|
+
export { loadNxPlugin, nxConfig };
|
package/dist/configs/promise.js
CHANGED
|
@@ -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
|
package/dist/configs/react.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
*
|
package/dist/configs/react.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GLOBAL_IGNORES, findNextRoots
|
|
2
|
-
import {
|
|
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
|
-
|
|
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: [
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
120
|
-
|
|
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,
|
|
134
|
+
export { loadNextPlugin, nextBaseConfig, nextConfig, nextOverridesConfig, reactBaseConfig, reactConfig, reactSettingsConfig, typescriptOverridesConfig };
|
package/dist/configs/testing.js
CHANGED
|
@@ -1,20 +1,41 @@
|
|
|
1
|
-
import {
|
|
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
|
-
...
|
|
31
|
+
...recommended,
|
|
16
32
|
name: "Jest Rules",
|
|
17
|
-
files: [
|
|
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: [
|
|
51
|
+
files: [testFiles],
|
|
31
52
|
rules: {
|
|
32
53
|
...vitestPlugin.configs.recommended.rules,
|
|
33
|
-
|
|
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: [
|
|
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: [
|
|
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
|
|
62
|
-
"vitest
|
|
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
|
}
|
package/dist/configs/turbo.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
package/dist/configs/turbo.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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 {
|
|
17
|
+
export { loadTurboPlugin, turboConfig };
|
package/dist/configs/unicorn.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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: [
|
|
15
|
+
files: [tsFiles],
|
|
16
16
|
plugins: { unicorn: unicornPlugin },
|
|
17
17
|
rules: {
|
|
18
18
|
"unicorn/filename-case": ["error", {
|
package/dist/conventions.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/conventions.js
CHANGED
|
@@ -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 };
|
package/dist/gates.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare function nextGate(option: boolean | NextOptions | undefined, stri
|
|
|
14
14
|
files: string[];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* Storybook: a `.storybook/main.*` marks a Storybook repo
|
|
18
|
-
*
|
|
17
|
+
* Storybook: a `.storybook/main.*` marks a Storybook repo; `eslint-plugin-storybook` statically imports `storybook`,
|
|
18
|
+
* so it must be resolvable from the workspace root.
|
|
19
19
|
*/
|
|
20
20
|
export declare function storybookGate(option: boolean | ToggleOptions | undefined, strict: boolean): {
|
|
21
21
|
enabled: boolean;
|
|
@@ -29,11 +29,11 @@ export declare function turboGate(option: boolean | ToggleOptions | undefined):
|
|
|
29
29
|
files: string[];
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
* Nx: `nx.json` at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
33
|
-
* the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
32
|
+
* Nx: in use when `nx.json` is at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
33
|
+
* resolvable, checked on its own - the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
34
34
|
*/
|
|
35
35
|
export declare function nxGate(option: boolean | ToggleOptions | undefined, strict: boolean, { packageName }?: {
|
|
36
|
-
packageName?: string
|
|
36
|
+
packageName?: string;
|
|
37
37
|
}): {
|
|
38
38
|
enabled: boolean;
|
|
39
39
|
options: {};
|
package/dist/gates.js
CHANGED
|
@@ -10,7 +10,7 @@ import { globSync } from "glob";
|
|
|
10
10
|
function nextGate(option, strict, { requirePackage = true } = {}) {
|
|
11
11
|
return toolGate(option, strict, {
|
|
12
12
|
tool: "next",
|
|
13
|
-
has: hasNext,
|
|
13
|
+
has: hasNext(),
|
|
14
14
|
packageName: "next",
|
|
15
15
|
requirePackage,
|
|
16
16
|
absolutizeOptions: ({ rootDir }) => (Array.isArray(rootDir) ? rootDir : [rootDir]).filter((dir) => Boolean(dir)).flatMap((dir) => {
|
|
@@ -22,52 +22,64 @@ function nextGate(option, strict, { requirePackage = true } = {}) {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* `
|
|
25
|
+
* A tool marked by a config file: the file anywhere in the workspace marks the repo even when the tool's package
|
|
26
|
+
* (`tool`) sits in a leaf package.
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function configFileGate(option, strict, spec) {
|
|
29
|
+
const { tool, has, file, dot, requirePackage } = spec;
|
|
29
30
|
return toolGate(option, strict, {
|
|
31
|
+
tool,
|
|
32
|
+
has,
|
|
33
|
+
packageName: tool,
|
|
34
|
+
requirePackage,
|
|
35
|
+
scan: () => scanWorkspace(file, GLOBAL_IGNORES, { dot })
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Storybook: a `.storybook/main.*` marks a Storybook repo; `eslint-plugin-storybook` statically imports `storybook`,
|
|
40
|
+
* so it must be resolvable from the workspace root.
|
|
41
|
+
*/
|
|
42
|
+
function storybookGate(option, strict) {
|
|
43
|
+
return configFileGate(option, strict, {
|
|
30
44
|
tool: "storybook",
|
|
31
|
-
has: hasStorybook,
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
has: hasStorybook(),
|
|
46
|
+
file: ".storybook/main.*",
|
|
47
|
+
dot: true
|
|
34
48
|
});
|
|
35
49
|
}
|
|
36
50
|
/** Turborepo: probe only, never strict - no evidence scan. */
|
|
37
51
|
function turboGate(option) {
|
|
38
52
|
return toolGate(option, false, {
|
|
39
53
|
tool: "turbo",
|
|
40
|
-
has: hasTurbo
|
|
54
|
+
has: hasTurbo()
|
|
41
55
|
});
|
|
42
56
|
}
|
|
43
57
|
/**
|
|
44
|
-
* Nx: `nx.json` at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
45
|
-
* the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
58
|
+
* Nx: in use when `nx.json` is at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
59
|
+
* resolvable, checked on its own - the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
46
60
|
*/
|
|
47
|
-
function nxGate(option, strict, { packageName
|
|
61
|
+
function nxGate(option, strict, { packageName } = {}) {
|
|
48
62
|
return toolGate(option, strict, {
|
|
49
63
|
tool: "nx",
|
|
50
|
-
has: hasNx,
|
|
64
|
+
has: hasNx(),
|
|
51
65
|
strictHas: strict && existsSync(resolve(process.cwd(), "nx.json")),
|
|
52
|
-
|
|
66
|
+
packageName
|
|
53
67
|
});
|
|
54
68
|
}
|
|
55
69
|
function jestGate(option, strict) {
|
|
56
|
-
return
|
|
70
|
+
return configFileGate(option, strict, {
|
|
57
71
|
tool: "jest",
|
|
58
|
-
has: hasJest,
|
|
59
|
-
|
|
60
|
-
requirePackage: false
|
|
61
|
-
scan: () => scanWorkspace("jest.config.*", GLOBAL_IGNORES)
|
|
72
|
+
has: hasJest(),
|
|
73
|
+
file: "jest.config.*",
|
|
74
|
+
requirePackage: false
|
|
62
75
|
});
|
|
63
76
|
}
|
|
64
77
|
function vitestGate(option, strict) {
|
|
65
|
-
return
|
|
78
|
+
return configFileGate(option, strict, {
|
|
66
79
|
tool: "vitest",
|
|
67
|
-
has: hasVitest,
|
|
68
|
-
|
|
69
|
-
requirePackage: false
|
|
70
|
-
scan: () => scanWorkspace("{vitest,vite}.config.*", GLOBAL_IGNORES)
|
|
80
|
+
has: hasVitest(),
|
|
81
|
+
file: "{vitest,vite}.config.*",
|
|
82
|
+
requirePackage: false
|
|
71
83
|
});
|
|
72
84
|
}
|
|
73
85
|
/**
|
|
@@ -106,7 +118,7 @@ function findTailwindEntry(ignores) {
|
|
|
106
118
|
function tailwindGate(option, strict = false) {
|
|
107
119
|
const { enabled, options, files } = toolGate(option, strict, {
|
|
108
120
|
tool: "tailwind",
|
|
109
|
-
has: hasTailwind,
|
|
121
|
+
has: hasTailwind(),
|
|
110
122
|
packageName: "tailwindcss",
|
|
111
123
|
needs: {
|
|
112
124
|
what: "entry CSS",
|