commit-sheriff 1.4.0 → 1.5.0
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
|
@@ -77,9 +77,9 @@ Run this once per repo, from the repo root (where `package.json` lives). This wo
|
|
|
77
77
|
3. Creates a default `.commitsheriffrc.json` file at the repo root **only if one doesn't already exist** (and only if there's no legacy `package.json` → `commitGuard` block either — see [Configuration](#configuration-commitsheriffrcjson)) — re-running `init` never overwrites your customized config.
|
|
78
78
|
4. Adds a default `lint-staged` block to `package.json` **only if one doesn't already exist**.
|
|
79
79
|
5. Adds a `"prepare": "husky"` npm script if missing, so hooks are (re)installed automatically after `npm install`.
|
|
80
|
-
6. If `react` and `typescript` are both present in your `dependencies`/`devDependencies`, also runs [`add-eslint-react`](#advanced-eslint-module-boundary-template-typescriptreact) automatically, which
|
|
80
|
+
6. If `react` and `typescript` are both present in your `dependencies`/`devDependencies`, also runs [`add-eslint-react`](#advanced-eslint-module-boundary-template-typescriptreact) automatically, which writes the ESLint flat-config module-boundary template (as `eslint.config.mjs` if you have none yet, or as a separate `eslint.config.commit-sheriff.mjs` if you already have one) and **overwrites** `.prettierrc.js` with the latest template. Otherwise it's skipped and you can add it manually later.
|
|
81
81
|
|
|
82
|
-
Re-running `npx commit-sheriff init` later (e.g. after updating the package) is safe for your project-specific settings: it refreshes the hook scripts and (on react+typescript projects) the ESLint/Prettier templates to the latest version, but leaves your `.commitsheriffrc.json` / `lint-staged` config alone. If you've hand-edited `.
|
|
82
|
+
Re-running `npx commit-sheriff init` later (e.g. after updating the package) is safe for your project-specific settings: it refreshes the hook scripts and (on react+typescript projects) the ESLint/Prettier templates to the latest version, but leaves your `.commitsheriffrc.json` / `lint-staged` config alone. If you've hand-edited `.prettierrc.js`, or `eslint.config.mjs` in the no-existing-config case, back them up first — those get overwritten on every re-run (the side-file case, `eslint.config.commit-sheriff.mjs`, is also overwritten each time, but your own `eslint.config.mjs` is never touched there).
|
|
83
83
|
|
|
84
84
|
## Commit message format
|
|
85
85
|
|
|
@@ -257,37 +257,64 @@ other through a public barrel file, never through deep/internal paths:
|
|
|
257
257
|
npx commit-sheriff add-eslint-react
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
-
This
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
-
|
|
265
|
-
|
|
266
|
-
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
260
|
+
This ships as a **flat config** (`eslint.config.*`, ESLint 9+ format), not the legacy
|
|
261
|
+
`.eslintrc.js` format — see [why](#why-flat-config) below. Where it lands depends on what your
|
|
262
|
+
project already has:
|
|
263
|
+
|
|
264
|
+
- **No `eslint.config.*` yet** → written directly as `eslint.config.mjs` (your main config).
|
|
265
|
+
- **You already have one** (e.g. Next.js's own `create-next-app`-generated `eslint.config.mjs`)
|
|
266
|
+
→ left untouched; the module-boundary rules go into a separate
|
|
267
|
+
`eslint.config.commit-sheriff.mjs` instead, printed with a snippet to import + spread it into
|
|
268
|
+
your existing config:
|
|
269
|
+
|
|
270
|
+
```js
|
|
271
|
+
import moduleBoundaries from "./eslint.config.commit-sheriff.mjs";
|
|
272
|
+
export default [
|
|
273
|
+
...compat.extends("next/core-web-vitals", "next/typescript"),
|
|
274
|
+
...moduleBoundaries,
|
|
275
|
+
];
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Either way, `.prettierrc.js` is also written/refreshed, **always overwriting** whatever is
|
|
279
|
+
already there at that filename (same behavior as the `commit-msg`/`pre-commit` hooks — re-running
|
|
280
|
+
`add-eslint-react` refreshes it to the latest version of the template). If you've customized it
|
|
281
|
+
by hand, back it up under a different name first — your edits will be replaced. The same applies
|
|
282
|
+
to `eslint.config.mjs` when it's the one written directly (the no-existing-config case above); the
|
|
283
|
+
side-file case never touches your own config.
|
|
271
284
|
|
|
272
285
|
The module list for the boundary rule isn't hardcoded — it's read straight from the `modules`
|
|
273
286
|
array in your root `.commitsheriffrc.json` (the same list the commit-msg/branch-name hooks use
|
|
274
287
|
for the `[MODULE]` tag), lowercased. For older installs still using `package.json`'s
|
|
275
288
|
`commitGuard.modules`, that's used as a fallback. If neither is set, a small illustrative default
|
|
276
|
-
(`auth`, `billing`, `reports`, `settings`) is used — open
|
|
277
|
-
fill in `modules` in `.commitsheriffrc.json` and it picks it up automatically.
|
|
289
|
+
(`auth`, `billing`, `reports`, `settings`) is used — open the generated config and replace it, or
|
|
290
|
+
just fill in `modules` in `.commitsheriffrc.json` and it picks it up automatically.
|
|
278
291
|
|
|
279
292
|
This template assumes a `src/app/<module>/...` folder layout with `<module>.public.ts` barrel
|
|
280
|
-
files; adjust the paths inside
|
|
293
|
+
files; adjust the paths inside the generated config if your structure differs.
|
|
281
294
|
|
|
282
295
|
It doesn't install any dependencies for you — install what your project needs, e.g.:
|
|
283
296
|
|
|
284
297
|
```bash
|
|
285
298
|
npm install --save-dev typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin \
|
|
286
|
-
eslint-plugin-sonarjs eslint-plugin-import eslint-plugin-prettier
|
|
287
|
-
eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y \
|
|
288
|
-
eslint-plugin-testing-library eslint-plugin
|
|
299
|
+
@eslint/js @eslint/eslintrc eslint-plugin-sonarjs eslint-plugin-import eslint-plugin-prettier \
|
|
300
|
+
eslint-config-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y \
|
|
301
|
+
eslint-plugin-testing-library @vitest/eslint-plugin eslint-plugin-jest prettier
|
|
289
302
|
```
|
|
290
303
|
|
|
304
|
+
#### Why flat config?
|
|
305
|
+
|
|
306
|
+
ESLint 9+ looks for `eslint.config.*` first and, if one is found, **ignores `.eslintrc.js`
|
|
307
|
+
entirely** — there's no fallback. Since frameworks like Next.js already scaffold their own
|
|
308
|
+
`eslint.config.mjs`, a legacy-only `.eslintrc.js` template would sit right next to it and never
|
|
309
|
+
actually run (this was a real bug: an unused `useState` import went completely unflagged because
|
|
310
|
+
the module-boundary config was silently dead). The flat config here uses `FlatCompat` (the same
|
|
311
|
+
official migration helper Next.js's own generated config uses internally) so the exact same rule
|
|
312
|
+
set works natively under ESLint 9+, in both the standalone and merge-into-existing-config cases.
|
|
313
|
+
|
|
314
|
+
A legacy `.eslintrc.js` version of this template (`eslintrc.module-boundaries.js`) still ships
|
|
315
|
+
inside the package for reference/manual use on pure ESLint 8 projects with no flat config support
|
|
316
|
+
at all, but the CLI no longer writes it by default.
|
|
317
|
+
|
|
291
318
|
## Examples
|
|
292
319
|
|
|
293
320
|
**Minimal project (no modules)** — `.commitsheriffrc.json`:
|
package/bin/commit-sheriff.js
CHANGED
|
@@ -148,6 +148,8 @@ const ESLINT_REACT_DEV_DEPS = [
|
|
|
148
148
|
"typescript",
|
|
149
149
|
"@typescript-eslint/parser",
|
|
150
150
|
"@typescript-eslint/eslint-plugin",
|
|
151
|
+
"@eslint/js",
|
|
152
|
+
"@eslint/eslintrc",
|
|
151
153
|
"eslint-plugin-sonarjs",
|
|
152
154
|
"eslint-plugin-import",
|
|
153
155
|
"eslint-plugin-prettier",
|
|
@@ -156,29 +158,67 @@ const ESLINT_REACT_DEV_DEPS = [
|
|
|
156
158
|
"eslint-plugin-react-hooks",
|
|
157
159
|
"eslint-plugin-jsx-a11y",
|
|
158
160
|
"eslint-plugin-testing-library",
|
|
159
|
-
"eslint-plugin
|
|
161
|
+
"@vitest/eslint-plugin",
|
|
160
162
|
"eslint-plugin-jest",
|
|
161
163
|
"prettier",
|
|
162
164
|
];
|
|
163
165
|
|
|
166
|
+
const FLAT_CONFIG_CANDIDATES = [
|
|
167
|
+
"eslint.config.js",
|
|
168
|
+
"eslint.config.mjs",
|
|
169
|
+
"eslint.config.cjs",
|
|
170
|
+
"eslint.config.ts",
|
|
171
|
+
];
|
|
172
|
+
const FLAT_CONFIG_SIDE_FILE = "eslint.config.commit-sheriff.mjs";
|
|
173
|
+
|
|
174
|
+
function hasFlatEslintConfig() {
|
|
175
|
+
return FLAT_CONFIG_CANDIDATES.some((name) => fs.existsSync(path.join(cwd, name)));
|
|
176
|
+
}
|
|
177
|
+
|
|
164
178
|
function copyTemplateOverwrite(templateName, destName) {
|
|
165
179
|
const src = path.join(__dirname, "..", "templates", templateName);
|
|
166
180
|
const dest = path.join(cwd, destName);
|
|
167
181
|
const existed = fs.existsSync(dest);
|
|
168
182
|
fs.copyFileSync(src, dest);
|
|
169
183
|
console.log(existed ? `✔ ${destName} yeniləndi (üzərinə yazıldı)` : `✔ ${destName} yazıldı`);
|
|
184
|
+
return dest;
|
|
170
185
|
}
|
|
171
186
|
|
|
172
187
|
function addEslintReact() {
|
|
173
|
-
|
|
188
|
+
// ESLint 9+ prioritizes flat config (`eslint.config.*`) and completely ignores a legacy
|
|
189
|
+
// `.eslintrc.js` when one is present — no fallback. Frameworks like Next.js already scaffold
|
|
190
|
+
// their own `eslint.config.mjs`, so if we wrote only `.eslintrc.js` here it would silently
|
|
191
|
+
// never run for the majority of modern projects. We therefore ship the flat-config template
|
|
192
|
+
// as the primary artifact, and decide where it lands based on what the project already has.
|
|
193
|
+
const flatConfigAlreadyExists = hasFlatEslintConfig();
|
|
194
|
+
|
|
195
|
+
if (flatConfigAlreadyExists) {
|
|
196
|
+
copyTemplateOverwrite("eslint.config.module-boundaries.mjs", FLAT_CONFIG_SIDE_FILE);
|
|
197
|
+
console.log(
|
|
198
|
+
`\n• Layihədə artıq öz eslint.config.* faylınız var — ona toxunulmadı.\n` +
|
|
199
|
+
` Modul-sərhəd qaydaları ayrıca ${FLAT_CONFIG_SIDE_FILE} faylına yazıldı.\n` +
|
|
200
|
+
` Özünüzün eslint.config.* faylınıza əlavə edin, məsələn:\n\n` +
|
|
201
|
+
` import moduleBoundaries from "./${FLAT_CONFIG_SIDE_FILE}";\n` +
|
|
202
|
+
` export default [\n` +
|
|
203
|
+
` ...compat.extends("next/core-web-vitals", "next/typescript"),\n` +
|
|
204
|
+
` ...moduleBoundaries,\n` +
|
|
205
|
+
` ];\n`,
|
|
206
|
+
);
|
|
207
|
+
} else {
|
|
208
|
+
copyTemplateOverwrite("eslint.config.module-boundaries.mjs", "eslint.config.mjs");
|
|
209
|
+
console.log(
|
|
210
|
+
"\n• Layihədə eslint.config.* yox idi — eslint.config.mjs olaraq birbaşa yazıldı.\n",
|
|
211
|
+
);
|
|
212
|
+
}
|
|
174
213
|
copyTemplateOverwrite("prettier.module-boundaries.js", ".prettierrc.js");
|
|
175
214
|
console.log(
|
|
176
|
-
"
|
|
215
|
+
"Bu şablon TypeScript/React + modul-sərhəd (module-boundary) qaydaları üçündür.\n" +
|
|
177
216
|
`Modul siyahısı ${CONFIG_FILE_NAME}.modules-dən avtomatik oxunur (boşdursa nümunə\n` +
|
|
178
|
-
"siyahı istifadə olunur —
|
|
179
|
-
"Diqqət: .
|
|
180
|
-
"üzərinə yazılır (commit-msg/pre-commit hook-ları kimi)
|
|
181
|
-
"dəyişiklikləri qorumaq istəsəniz, əvvəlcə fərqli adla
|
|
217
|
+
"siyahı istifadə olunur — şablon faylı içindəki şərhi oxuyun).\n\n" +
|
|
218
|
+
"Diqqət: eslint.config.* (və ya yuxarıdakı side-file) və .prettierrc.js hər dəfə\n" +
|
|
219
|
+
"şablonun ən son versiyası ilə üzərinə yazılır (commit-msg/pre-commit hook-ları kimi)\n" +
|
|
220
|
+
"— özünüzə uyğun etdiyiniz dəyişiklikləri qorumaq istəsəniz, əvvəlcə fərqli adla\n" +
|
|
221
|
+
"backup götürün.\n\n" +
|
|
182
222
|
"Lazımi devDependencies (özünüz quraşdırın, layihənizin real versiyalarına uyğun):\n" +
|
|
183
223
|
` npm install --save-dev ${ESLINT_REACT_DEV_DEPS.join(" ")}\n`,
|
|
184
224
|
);
|
package/package.json
CHANGED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced ESLint config (flat config format) — enforces module boundaries in a modular
|
|
3
|
+
* TypeScript/React app. This is the flat-config (ESLint 9+, `eslint.config.*`) counterpart of
|
|
4
|
+
* the rules previously shipped only as a legacy `.eslintrc.js`.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists: ESLint 9+ looks for `eslint.config.*` (flat config) first and, if one is
|
|
7
|
+
* found, ignores `.eslintrc.js` entirely — it does NOT fall back to it. Frameworks like Next.js
|
|
8
|
+
* (`create-next-app`) already scaffold their own `eslint.config.mjs`, so a legacy `.eslintrc.js`
|
|
9
|
+
* sitting next to it is silently dead: none of its rules (including the module-boundary ones)
|
|
10
|
+
* ever run. This file avoids that trap by speaking flat config natively.
|
|
11
|
+
*
|
|
12
|
+
* Assumptions this template makes (edit as needed):
|
|
13
|
+
* - Feature modules live under `src/app/<module>/` (e.g. `src/app/auth/`).
|
|
14
|
+
* - Each module exposes its public surface via a `<module>.public.ts` barrel file; anything
|
|
15
|
+
* else under `src/app/<module>/modules/**` or `src/app/<module>/shared/**` is internal and
|
|
16
|
+
* must not be imported directly from another module.
|
|
17
|
+
* - Shared/base code lives under `src/app/_shared/**` and `src/packages/**` and must never
|
|
18
|
+
* import from a feature module (that would invert the dependency direction).
|
|
19
|
+
* - `src/packages/routing/AppRoutes.tsx` and `src/packages/routing/config/modules.registry.ts`
|
|
20
|
+
* are the one place allowed to import every module directly (that's the whole point of a
|
|
21
|
+
* router/registry), so the boundary rule is turned off just for those two files.
|
|
22
|
+
*
|
|
23
|
+
* Module list: instead of hardcoding module names, this reads `modules` from the repo's
|
|
24
|
+
* `.commitsheriffrc.json` (the same list used by the commit-sheriff commit-msg/branch-name
|
|
25
|
+
* hooks — see README), so the two conventions (module tags in commits/branches, and module
|
|
26
|
+
* boundaries in imports) stay in sync automatically. For older installs that still keep their
|
|
27
|
+
* config under `package.json`'s `commitGuard` block, that location is used as a fallback. If
|
|
28
|
+
* neither is found, a small illustrative default is used instead — replace it with your real
|
|
29
|
+
* module names.
|
|
30
|
+
*
|
|
31
|
+
* How to use this file:
|
|
32
|
+
* - If your project has NO `eslint.config.*` yet, `commit-sheriff add-eslint-react` writes
|
|
33
|
+
* this content directly as your `eslint.config.mjs` — nothing else to do.
|
|
34
|
+
* - If your project ALREADY has an `eslint.config.*` (e.g. Next.js's own), this content is
|
|
35
|
+
* instead written to `eslint.config.commit-sheriff.mjs` alongside it, and you import + spread
|
|
36
|
+
* it into your existing config so nothing gets silently overwritten:
|
|
37
|
+
*
|
|
38
|
+
* import moduleBoundaries from "./eslint.config.commit-sheriff.mjs";
|
|
39
|
+
* export default [
|
|
40
|
+
* ...compat.extends("next/core-web-vitals", "next/typescript"),
|
|
41
|
+
* ...moduleBoundaries,
|
|
42
|
+
* ];
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
import { fileURLToPath } from "node:url";
|
|
46
|
+
import path from "node:path";
|
|
47
|
+
import fs from "node:fs";
|
|
48
|
+
import js from "@eslint/js";
|
|
49
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
50
|
+
|
|
51
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
52
|
+
const __dirname = path.dirname(__filename);
|
|
53
|
+
|
|
54
|
+
// `recommendedConfig`/`allConfig` are required so FlatCompat can resolve the bare
|
|
55
|
+
// "eslint:recommended" / "eslint:all" strings used in `extends` below — without them it throws
|
|
56
|
+
// "Missing parameter 'recommendedConfig' in FlatCompat constructor" as soon as `.config()` runs.
|
|
57
|
+
const compat = new FlatCompat({
|
|
58
|
+
baseDirectory: __dirname,
|
|
59
|
+
recommendedConfig: js.configs.recommended,
|
|
60
|
+
allConfig: js.configs.all,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
function loadAppModules() {
|
|
64
|
+
try {
|
|
65
|
+
const rcPath = path.join(__dirname, ".commitsheriffrc.json");
|
|
66
|
+
const rc = JSON.parse(fs.readFileSync(rcPath, "utf8"));
|
|
67
|
+
if (Array.isArray(rc.modules) && rc.modules.length) {
|
|
68
|
+
return rc.modules.map((m) => String(m).toLowerCase());
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// fall through to the legacy package.json lookup below
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const pkgPath = path.join(__dirname, "package.json");
|
|
75
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
76
|
+
const modules = pkg.commitGuard && pkg.commitGuard.modules;
|
|
77
|
+
if (Array.isArray(modules) && modules.length) {
|
|
78
|
+
return modules.map((m) => String(m).toLowerCase());
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
// fall through to the illustrative default below
|
|
82
|
+
}
|
|
83
|
+
return ["auth", "billing", "reports", "settings"]; // example only — replace with your modules
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const APP_MODULES = loadAppModules();
|
|
87
|
+
const MODULE_INTERNALS = ["modules", "shared"];
|
|
88
|
+
|
|
89
|
+
const restrictImports = (group, message) => ({
|
|
90
|
+
"no-restricted-imports": ["error", { patterns: [{ group, message }] }],
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const moduleBoundaryConfigs = [
|
|
94
|
+
// A module reaches another module's internals only through `<module>.public.ts`, so the
|
|
95
|
+
// surface between modules stays explicit. `routing/` stays open on purpose: route enums are
|
|
96
|
+
// dependency-free leaves, while the barrel pulls in services that instantiate on import.
|
|
97
|
+
...APP_MODULES.map((appModule) => ({
|
|
98
|
+
files: [`src/app/${appModule}/**`],
|
|
99
|
+
rules: restrictImports(
|
|
100
|
+
APP_MODULES.filter((other) => other !== appModule).flatMap((other) =>
|
|
101
|
+
MODULE_INTERNALS.map((internal) => `~/app/${other}/${internal}/**`),
|
|
102
|
+
),
|
|
103
|
+
"Cross-module import: use the other module's '<module>.public.ts' barrel instead of a deep path.",
|
|
104
|
+
),
|
|
105
|
+
})),
|
|
106
|
+
{
|
|
107
|
+
files: ["src/app/_shared/**", "src/packages/**"],
|
|
108
|
+
rules: restrictImports(
|
|
109
|
+
APP_MODULES.map((appModule) => `~/app/${appModule}/**`),
|
|
110
|
+
"Base layers must not depend on a feature module: move the shared piece down into _shared or packages instead.",
|
|
111
|
+
),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
files: [
|
|
115
|
+
"src/packages/routing/AppRoutes.tsx",
|
|
116
|
+
"src/packages/routing/config/modules.registry.ts",
|
|
117
|
+
],
|
|
118
|
+
rules: { "no-restricted-imports": "off" },
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const moduleBoundaryConfig = [
|
|
123
|
+
{
|
|
124
|
+
ignores: [
|
|
125
|
+
"coverage/**",
|
|
126
|
+
"dist/**",
|
|
127
|
+
"build/**",
|
|
128
|
+
"node_modules/**",
|
|
129
|
+
"**/*.d.ts",
|
|
130
|
+
"**/*.config.js",
|
|
131
|
+
"**/*.config.mjs",
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
// FlatCompat translates the same legacy-style `extends`/`env`/`parserOptions`/`plugins`/`rules`
|
|
135
|
+
// block ESLint's own docs recommend for migrating a single rich config to flat format — this
|
|
136
|
+
// keeps every rule identical to the previous .eslintrc.js version, just in flat shape.
|
|
137
|
+
...compat.config({
|
|
138
|
+
parser: "@typescript-eslint/parser",
|
|
139
|
+
parserOptions: {
|
|
140
|
+
ecmaVersion: "latest",
|
|
141
|
+
sourceType: "module",
|
|
142
|
+
ecmaFeatures: { jsx: true },
|
|
143
|
+
project: true,
|
|
144
|
+
},
|
|
145
|
+
env: { browser: true, es2021: true, node: true },
|
|
146
|
+
settings: {
|
|
147
|
+
react: { version: "detect" },
|
|
148
|
+
linkComponents: [
|
|
149
|
+
{ name: "RouterLink", linkAttribute: ["href", "to"] },
|
|
150
|
+
{ name: "Link", linkAttribute: ["href", "to"] },
|
|
151
|
+
],
|
|
152
|
+
jest: { version: "29.0" },
|
|
153
|
+
},
|
|
154
|
+
extends: [
|
|
155
|
+
"eslint:recommended",
|
|
156
|
+
"plugin:@typescript-eslint/recommended",
|
|
157
|
+
"plugin:sonarjs/recommended-legacy",
|
|
158
|
+
"plugin:import/recommended",
|
|
159
|
+
"plugin:import/typescript",
|
|
160
|
+
"plugin:prettier/recommended",
|
|
161
|
+
"plugin:react/recommended",
|
|
162
|
+
"plugin:react-hooks/recommended",
|
|
163
|
+
"plugin:jsx-a11y/recommended",
|
|
164
|
+
"plugin:testing-library/react",
|
|
165
|
+
"plugin:@vitest/legacy-recommended",
|
|
166
|
+
"plugin:jest/recommended",
|
|
167
|
+
],
|
|
168
|
+
plugins: [
|
|
169
|
+
"@typescript-eslint",
|
|
170
|
+
"sonarjs",
|
|
171
|
+
"import",
|
|
172
|
+
"prettier",
|
|
173
|
+
"react",
|
|
174
|
+
"react-hooks",
|
|
175
|
+
"jsx-a11y",
|
|
176
|
+
"testing-library",
|
|
177
|
+
"@vitest",
|
|
178
|
+
"jest",
|
|
179
|
+
],
|
|
180
|
+
rules: {
|
|
181
|
+
"prettier/prettier": ["error", { endOfLine: "auto" }],
|
|
182
|
+
/** React-specific rules */
|
|
183
|
+
"react/hook-use-state": ["warn", { allowDestructuredState: true }],
|
|
184
|
+
"react/react-in-jsx-scope": ["off"],
|
|
185
|
+
"react/no-array-index-key": ["error"],
|
|
186
|
+
"react/display-name": ["off"],
|
|
187
|
+
"react/prop-types": ["off"],
|
|
188
|
+
/** Accessibility rules */
|
|
189
|
+
"jsx-a11y/anchor-is-valid": [
|
|
190
|
+
"error",
|
|
191
|
+
{
|
|
192
|
+
components: ["Link", "RouterLink"],
|
|
193
|
+
specialLink: ["to"],
|
|
194
|
+
aspects: ["noHref", "invalidHref", "preferButton"],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
/** Best practices and coding style */
|
|
198
|
+
"no-console": process.env.NODE_ENV === "production" ? "error" : "warn",
|
|
199
|
+
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "warn",
|
|
200
|
+
"prefer-const": ["error"],
|
|
201
|
+
"no-use-before-define": ["error", { functions: false, classes: true, variables: true }],
|
|
202
|
+
"no-nested-ternary": ["error"],
|
|
203
|
+
/** SonarJS rules */
|
|
204
|
+
"sonarjs/cognitive-complexity": ["error"],
|
|
205
|
+
"sonarjs/no-inverted-boolean-check": ["off"],
|
|
206
|
+
"sonarjs/no-duplicate-string": ["off"],
|
|
207
|
+
/** Import rules */
|
|
208
|
+
"import/no-anonymous-default-export": "off",
|
|
209
|
+
"import/no-cycle": ["off"],
|
|
210
|
+
"import/namespace": ["off"],
|
|
211
|
+
"import/no-named-as-default": ["off"],
|
|
212
|
+
"import/no-unresolved": ["off", { ignore: ["^src/"] }],
|
|
213
|
+
/** TypeScript-specific rules */
|
|
214
|
+
"@typescript-eslint/explicit-module-boundary-types": ["off"],
|
|
215
|
+
"@typescript-eslint/no-explicit-any": ["error"],
|
|
216
|
+
"@typescript-eslint/no-unsafe-return": ["warn"],
|
|
217
|
+
"@typescript-eslint/no-unsafe-call": ["warn"],
|
|
218
|
+
"@typescript-eslint/no-unsafe-member-access": ["warn"],
|
|
219
|
+
"@typescript-eslint/no-unsafe-assignment": ["warn"],
|
|
220
|
+
"@typescript-eslint/prefer-optional-chain": ["error"],
|
|
221
|
+
"@typescript-eslint/prefer-nullish-coalescing": ["warn"],
|
|
222
|
+
"@typescript-eslint/no-unused-vars": [
|
|
223
|
+
"error",
|
|
224
|
+
{
|
|
225
|
+
argsIgnorePattern: "^_",
|
|
226
|
+
varsIgnorePattern: "^_",
|
|
227
|
+
caughtErrorsIgnorePattern: "^_",
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
"@typescript-eslint/no-restricted-types": [
|
|
231
|
+
"error",
|
|
232
|
+
{
|
|
233
|
+
types: {
|
|
234
|
+
Array: {
|
|
235
|
+
message: "Use yourType[] instead. So for Array<string> you need to use string[]",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
"@typescript-eslint/consistent-type-definitions": ["warn", "interface"],
|
|
241
|
+
"@typescript-eslint/naming-convention": [
|
|
242
|
+
"error",
|
|
243
|
+
{
|
|
244
|
+
selector: "variable",
|
|
245
|
+
types: ["boolean"],
|
|
246
|
+
format: ["PascalCase"],
|
|
247
|
+
prefix: ["is", "should", "has", "can", "did", "will", "are"],
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
/** File size constraints */
|
|
251
|
+
"max-lines": ["warn", { max: 250, skipComments: true, skipBlankLines: true }],
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
254
|
+
{
|
|
255
|
+
files: ["*.js", "**/*.styles.ts"],
|
|
256
|
+
rules: {
|
|
257
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
258
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
259
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
260
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
files: ["**/*.styles.ts"],
|
|
265
|
+
rules: {
|
|
266
|
+
"@typescript-eslint/no-unsafe-return": "off",
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
...moduleBoundaryConfigs,
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
export default moduleBoundaryConfig;
|