eslint-config-typed 2.1.0 → 2.2.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 +55 -29
- package/dist/configs/jest.d.mts.map +1 -1
- package/dist/configs/preact.d.mts.map +1 -1
- package/dist/configs/preact.mjs.map +1 -1
- package/dist/configs/react.mjs.map +1 -1
- package/dist/configs/testing-library.d.mts.map +1 -1
- package/dist/configs/typescript-without-rules.mjs +3 -3
- package/dist/configs/typescript-without-rules.mjs.map +1 -1
- package/dist/configs/typescript.d.mts.map +1 -1
- package/dist/configs/typescript.mjs.map +1 -1
- package/dist/configs/vitest.d.mts.map +1 -1
- package/dist/entry-point.d.mts +1 -1
- package/dist/entry-point.d.mts.map +1 -1
- package/dist/entry-point.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/rules/eslint-import-rules.d.mts.map +1 -1
- package/dist/rules/eslint-import-rules.mjs +1 -0
- package/dist/rules/eslint-import-rules.mjs.map +1 -1
- package/dist/rules/eslint-rules.d.mts +67 -3
- package/dist/rules/eslint-rules.d.mts.map +1 -1
- package/dist/rules/eslint-rules.mjs +182 -36
- package/dist/rules/eslint-rules.mjs.map +1 -1
- package/dist/rules/index.mjs +1 -1
- package/package.json +7 -4
- package/src/configs/jest.mts +1 -1
- package/src/configs/preact.mts +36 -35
- package/src/configs/react.mts +1 -1
- package/src/configs/testing-library.mts +1 -1
- package/src/configs/typescript-without-rules.mts +3 -3
- package/src/configs/typescript.mts +74 -72
- package/src/configs/vitest.mts +1 -1
- package/src/entry-point.mts +2 -0
- package/src/rules/eslint-import-rules.mts +2 -0
- package/src/rules/eslint-rules.mts +216 -38
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ A comprehensive ESLint configuration package with strongly-typed rule definition
|
|
|
21
21
|
- [Node.js TypeScript Project](#nodejs-typescript-project)
|
|
22
22
|
- [React + Testing Libraries](#react--testing-libraries)
|
|
23
23
|
- [VS Code Integration](#vs-code-integration)
|
|
24
|
+
- [TypeScript Configuration Files](#typescript-configuration-files)
|
|
24
25
|
- [Included plugins](#included-plugins)
|
|
25
26
|
- [API Reference](#api-reference)
|
|
26
27
|
- [Configuration Functions](#configuration-functions)
|
|
@@ -316,31 +317,54 @@ Add the following to `.vscode/settings.json` for proper ESLint integration:
|
|
|
316
317
|
}
|
|
317
318
|
```
|
|
318
319
|
|
|
320
|
+
## TypeScript Configuration Files
|
|
321
|
+
|
|
322
|
+
You can also write your eslint config in `.ts` or `.mts` format, all you need to do is run `npm add -D jiti`.
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
import {
|
|
326
|
+
eslintConfigForTypeScript,
|
|
327
|
+
eslintConfigForVitest,
|
|
328
|
+
type FlatConfig,
|
|
329
|
+
} from 'eslint-config-typed';
|
|
330
|
+
|
|
331
|
+
export default [
|
|
332
|
+
...eslintConfigForTypeScript({
|
|
333
|
+
tsconfigRootDir: thisDir,
|
|
334
|
+
tsconfigFileName: './tsconfig.json',
|
|
335
|
+
packageDirs: [thisDir],
|
|
336
|
+
}),
|
|
337
|
+
eslintConfigForVitest(),
|
|
338
|
+
] satisfies FlatConfig[];
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
For details, see <https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files>.
|
|
342
|
+
|
|
319
343
|
## Included plugins
|
|
320
344
|
|
|
321
|
-
-
|
|
322
|
-
-
|
|
323
|
-
-
|
|
324
|
-
-
|
|
325
|
-
-
|
|
326
|
-
-
|
|
327
|
-
-
|
|
328
|
-
-
|
|
329
|
-
-
|
|
330
|
-
-
|
|
331
|
-
-
|
|
332
|
-
-
|
|
333
|
-
-
|
|
334
|
-
-
|
|
335
|
-
-
|
|
336
|
-
-
|
|
337
|
-
-
|
|
338
|
-
-
|
|
339
|
-
-
|
|
340
|
-
-
|
|
341
|
-
-
|
|
342
|
-
-
|
|
343
|
-
-
|
|
345
|
+
- @typescript-eslint/eslint-plugin
|
|
346
|
+
- eslint-plugin-unicorn
|
|
347
|
+
- eslint-plugin-functional
|
|
348
|
+
- eslint-plugin-total-functions (Reimplemented in this repository to support flat config)
|
|
349
|
+
- eslint-plugin-array-func
|
|
350
|
+
- eslint-plugin-prefer-arrow-functions
|
|
351
|
+
- eslint-plugin-sort-destructure-keys
|
|
352
|
+
- eslint-plugin-security
|
|
353
|
+
- eslint-plugin-promise
|
|
354
|
+
- eslint-plugin-import
|
|
355
|
+
- eslint-plugin-strict-dependencies
|
|
356
|
+
- eslint-plugin-tree-shakable (Reimplemented in this repository to support flat config)
|
|
357
|
+
- eslint-plugin-react
|
|
358
|
+
- eslint-plugin-react-hooks
|
|
359
|
+
- eslint-plugin-react-perf
|
|
360
|
+
- eslint-plugin-react-refresh
|
|
361
|
+
- eslint-plugin-jsx-a11y
|
|
362
|
+
- eslint-plugin-vitest
|
|
363
|
+
- eslint-plugin-jest
|
|
364
|
+
- eslint-plugin-playwright
|
|
365
|
+
- eslint-plugin-cypress
|
|
366
|
+
- eslint-plugin-testing-library
|
|
367
|
+
- eslint-plugin-eslint-plugin
|
|
344
368
|
|
|
345
369
|
## API Reference
|
|
346
370
|
|
|
@@ -405,15 +429,17 @@ Pre-configured rule sets that can be imported and customized:
|
|
|
405
429
|
|
|
406
430
|
### Exported Pre-configured Rule Options
|
|
407
431
|
|
|
408
|
-
| Pre-configured rule option | Rule | Description
|
|
409
|
-
| :-------------------------------- | :---------------------- |
|
|
410
|
-
| **`restrictedGlobals`** | `no-restricted-globals` | Array of restricted global variables
|
|
411
|
-
| **`restrictedGlobalsForBrowser`** | `no-restricted-globals` | Browser-environment-specific restricted globals
|
|
432
|
+
| Pre-configured rule option | Rule | Description |
|
|
433
|
+
| :-------------------------------- | :---------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
434
|
+
| **`restrictedGlobals`** | `no-restricted-globals` | Array of restricted global variables |
|
|
435
|
+
| **`restrictedGlobalsForBrowser`** | `no-restricted-globals` | Browser-environment-specific restricted globals |
|
|
436
|
+
| **`restrictedSyntax`** | `no-restricted-syntax` | Disallows the `in` operator, `Object.prototype.hasOwnProperty.call` (suggests using `Object.hasOwn`), and `new Array(*)` syntax (suggests using `Array.from`) |
|
|
437
|
+
| **`restrictedSyntaxForReact`** | `no-restricted-syntax` | Rule set to restrict React component styling |
|
|
412
438
|
|
|
413
439
|
You can find other pre-configured rule options by traversing the pre-defined rules object like this:
|
|
414
440
|
|
|
415
|
-
- `typescriptEslintRules['@typescript-eslint/no-
|
|
416
|
-
- `eslintRules['
|
|
441
|
+
- `typescriptEslintRules['@typescript-eslint/no-unused-vars'][1].varsIgnorePattern`
|
|
442
|
+
- `eslintRules['logical-assignment-operators'].slice(1)`
|
|
417
443
|
|
|
418
444
|
The shape of the rule option varies depending on the rule, so please check the contents by tracing the predefined rules each time and extract it.
|
|
419
445
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.d.mts","sourceRoot":"","sources":["../../src/configs/jest.mts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,mBAAmB,GAAI,QAAQ,SAAS,MAAM,EAAE,KAAG,
|
|
1
|
+
{"version":3,"file":"jest.d.mts","sourceRoot":"","sources":["../../src/configs/jest.mts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,mBAAmB,GAAI,QAAQ,SAAS,MAAM,EAAE,KAAG,UAgBnD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preact.d.mts","sourceRoot":"","sources":["../../src/configs/preact.mts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvE,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,MAAM,EAAE,KACxB,SAAS,UAAU,
|
|
1
|
+
{"version":3,"file":"preact.d.mts","sourceRoot":"","sources":["../../src/configs/preact.mts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvE,eAAO,MAAM,qBAAqB,GAChC,QAAQ,SAAS,MAAM,EAAE,KACxB,SAAS,UAAU,EAqCV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preact.mjs","sources":["../../src/configs/preact.mts"],"sourcesContent":[null],"names":[],"mappings":";;;MAGa,qBAAqB,GAAG,CACnC,KAAyB,
|
|
1
|
+
{"version":3,"file":"preact.mjs","sources":["../../src/configs/preact.mts"],"sourcesContent":[null],"names":[],"mappings":";;;MAGa,qBAAqB,GAAG,CACnC,KAAyB,KAEzB;IACE,GAAG,wBAAwB,CAAC,KAAK,CAAC;AAClC,IAAA;AACE,QAAA,IAAI,KAAK,KAAK,SAAS,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACzC,QAAA,QAAQ,EAAE;AACR,YAAA,KAAK,EAAE;AACL,gBAAA,MAAM,EAAE,GAAG;AACX,gBAAA,OAAO,EAAE,QAAQ;AAClB,aAAA;AACF,SAAA;QACD,KAAK,EAAE,gBAAgB,CAAC;AACtB,YAAA,0CAA0C,EAAE;gBAC1C,OAAO;AACP,gBAAA;AACE,oBAAA,KAAK,EAAE;AACL,wBAAA;AACE,4BAAA,IAAI,EAAE,eAAe;AACrB,4BAAA,WAAW,EAAE;gCACX,MAAM;gCACN,UAAU;gCACV,YAAY;gCACZ,SAAS;gCACT,aAAa;gCACb,QAAQ;gCACR,YAAY;gCACZ,WAAW;gCACX,iBAAiB;gCACjB,kBAAkB;AACnB,6BAAA;AACD,4BAAA,OAAO,EAAE,yCAAyC;AACnD,yBAAA;AACF,qBAAA;AACF,iBAAA;AACF,aAAA;SACF,CAAC;AACH,KAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.mjs","sources":["../../src/configs/react.mts"],"sourcesContent":[null],"names":[],"mappings":";;MAGa,oBAAoB,GAAG,CAClC,KAAyB,KAEzB;IACE,GAAG,wBAAwB,CAAC,KAAK,CAAC;AAClC,IAAA;AACE,QAAA,IAAI,KAAK,KAAK,SAAS,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACzC,QAAA,QAAQ,EAAE;AACR,YAAA,KAAK,EAAE;AACL,gBAAA,OAAO,EAAE,QAAQ;AAClB,aAAA;AACF,SAAA;
|
|
1
|
+
{"version":3,"file":"react.mjs","sources":["../../src/configs/react.mts"],"sourcesContent":[null],"names":[],"mappings":";;MAGa,oBAAoB,GAAG,CAClC,KAAyB,KAEzB;IACE,GAAG,wBAAwB,CAAC,KAAK,CAAC;AAClC,IAAA;AACE,QAAA,IAAI,KAAK,KAAK,SAAS,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACzC,QAAA,QAAQ,EAAE;AACR,YAAA,KAAK,EAAE;AACL,gBAAA,OAAO,EAAE,QAAQ;AAClB,aAAA;AACF,SAAA;AACF,KAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing-library.d.mts","sourceRoot":"","sources":["../../src/configs/testing-library.mts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,6BAA6B,GACxC,QAAQ,SAAS,MAAM,EAAE,KACxB,
|
|
1
|
+
{"version":3,"file":"testing-library.d.mts","sourceRoot":"","sources":["../../src/configs/testing-library.mts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,6BAA6B,GACxC,QAAQ,SAAS,MAAM,EAAE,KACxB,UAcU,CAAC"}
|
|
@@ -5,9 +5,9 @@ import { plugins } from './plugins.mjs';
|
|
|
5
5
|
const eslintConfigForTypeScriptWithoutRules = ({ tsconfigFileName, tsconfigRootDir, }) => [
|
|
6
6
|
{
|
|
7
7
|
ignores: [
|
|
8
|
-
'eslint.config.js',
|
|
9
|
-
'eslint.config.*.mjs',
|
|
10
|
-
'eslint.*.config.mjs',
|
|
8
|
+
'eslint.config.{js,ts,mjs,mts,cjs,cts}',
|
|
9
|
+
'eslint.config.*.{js,ts,mjs,mts,cjs,cts}',
|
|
10
|
+
'eslint.*.config.{js,ts,mjs,mts,cjs,cts}',
|
|
11
11
|
'node_modules',
|
|
12
12
|
'**/node_modules/**',
|
|
13
13
|
'dist',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript-without-rules.mjs","sources":["../../src/configs/typescript-without-rules.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKO,MAAM,qCAAqC,GAAG,CAAC,EACpD,gBAAgB,EAChB,eAAe,GAIf,KACA;AACE,IAAA;AACE,QAAA,OAAO,EAAE;YACP,
|
|
1
|
+
{"version":3,"file":"typescript-without-rules.mjs","sources":["../../src/configs/typescript-without-rules.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKO,MAAM,qCAAqC,GAAG,CAAC,EACpD,gBAAgB,EAChB,eAAe,GAIf,KACA;AACE,IAAA;AACE,QAAA,OAAO,EAAE;YACP,uCAAuC;YACvC,yCAAyC;YACzC,yCAAyC;YACzC,cAAc;YACd,oBAAoB;YACpB,MAAM;YACN,OAAO;YACP,UAAU;AACX,SAAA;AACF,KAAA;AACD,IAAA;AACE,QAAA,eAAe,EAAE;AACf,YAAA,WAAW,EAAE,QAAQ;AACrB,YAAA,MAAM,EAAE,sBAAsB;AAC9B,YAAA,aAAa,EAAE;AACb,gBAAA,OAAO,EAAE,gBAAgB;gBACzB,eAAe;AACf,gBAAA,WAAW,EAAE,QAAQ;AACrB,gBAAA,YAAY,EAAE;AACZ,oBAAA,OAAO,EAAE,IAAI;AACb,oBAAA,aAAa,EAAE,IAAI;AACnB,oBAAA,GAAG,EAAE,IAAI;AACV,iBAAA;gBACD,SAAS,EAAE,IAAI;AACf,gBAAA,UAAU,EAAE,QAAQ;AACrB,aAAA;AACD,YAAA,OAAO,EAAE;gBACP,GAAG,OAAO,CAAC,MAAM;AAClB,aAAA;AACF,SAAA;AACD,QAAA,aAAa,EAAE;AACb,YAAA,cAAc,EAAE,KAAK;AACrB,YAAA,6BAA6B,EAAE,IAAI;AACpC,SAAA;QACD,OAAO;AACP,QAAA,QAAQ,EAAE;AACR,YAAA,gBAAgB,EAAE;AAChB,gBAAA,2BAA2B,EAAE;oBAC3B,UAAU;oBACV,KAAK;oBACL,KAAK;oBACL,MAAM;oBACN,MAAM;oBACN,MAAM;oBACN,MAAM;oBACN,MAAM;oBACN,MAAM;AACP,iBAAA;AACF,aAAA;AACD,YAAA,iBAAiB,EAAE;AACjB,gBAAA,UAAU,EAAE;oBACV,cAAc,EAAE,IAAI;;oBAEpB,OAAO,EAAE,CAAC,2BAA2B,CAAC;AACvC,iBAAA;;AAED,gBAAA,IAAI,EAAE;AACJ,oBAAA,UAAU,EAAE;wBACV,UAAU;wBACV,KAAK;wBACL,KAAK;wBACL,MAAM;wBACN,MAAM;wBACN,MAAM;wBACN,MAAM;wBACN,MAAM;wBACN,MAAM;AACP,qBAAA;AACF,iBAAA;AACF,aAAA;;AAED,YAAA,mBAAmB,EAAE;gBACnB,KAAK;gBACL,KAAK;gBACL,MAAM;gBACN,MAAM;gBACN,MAAM;gBACN,MAAM;gBACN,MAAM;gBACN,MAAM;AACP,aAAA;AACD,YAAA,gCAAgC,EAAE;gBAChC,cAAc;gBACd,qBAAqB;AACtB,aAAA;AACF,SAAA;AACF,KAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.d.mts","sourceRoot":"","sources":["../../src/configs/typescript.mts"],"names":[],"mappings":"AAcA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvE,eAAO,MAAM,yBAAyB,GAAI,8EAMvC,QAAQ,CAAC;IACV,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC,KAAG,SAAS,UAAU,
|
|
1
|
+
{"version":3,"file":"typescript.d.mts","sourceRoot":"","sources":["../../src/configs/typescript.mts"],"names":[],"mappings":"AAcA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGvE,eAAO,MAAM,yBAAyB,GAAI,8EAMvC,QAAQ,CAAC;IACV,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC,KAAG,SAAS,UAAU,EA6EZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.mjs","sources":["../../src/configs/typescript.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;AAiBO,MAAM,yBAAyB,GAAG,CAAC,EACxC,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GAOhB,
|
|
1
|
+
{"version":3,"file":"typescript.mjs","sources":["../../src/configs/typescript.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;AAiBO,MAAM,yBAAyB,GAAG,CAAC,EACxC,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GAOhB,KACA;AACE,IAAA,GAAG,qCAAqC,CAAC;QACvC,gBAAgB;QAChB,eAAe;KAChB,CAAC;AACF,IAAA;AACE,QAAA,KAAK,EAAE,KAAK,IAAI,CAAC,uBAAuB,CAAC;QACzC,KAAK,EAAE,gBAAgB,CAAC;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kBAAkB,EAAE,KAAK;SAC1B,CAAC;AACH,KAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.mts","sourceRoot":"","sources":["../../src/configs/vitest.mts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,MAAM,EAAE,KAAG,
|
|
1
|
+
{"version":3,"file":"vitest.d.mts","sourceRoot":"","sources":["../../src/configs/vitest.mts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvE,eAAO,MAAM,qBAAqB,GAAI,QAAQ,SAAS,MAAM,EAAE,KAAG,UAYrD,CAAC"}
|
package/dist/entry-point.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { eslintConfigForTypeScriptWithoutRules, eslintConfigForTypeScript, eslintConfigForBrowser, eslintConfigForNodeJs, eslintConfigForReact, eslintConfigForPreact, eslintConfigForVitest, eslintConfigForJest, eslintConfigForPlaywright, eslintConfigForCypress, eslintConfigForTestingLibrary, eslintRules, typescriptEslintRules, eslintFunctionalRules, eslintTotalFunctionsRules, eslintUnicornRules, eslintArrayFuncRules, eslintPreferArrowFunctionRules, eslintPluginSortDestructureKeysRules, eslintImportsRules, eslintPromiseRules, eslintSecurityRules, eslintTreeShakableRules, eslintReactRules, eslintReactHooksRules, eslintReactPerfRules, eslintReactRefreshRules, eslintVitestRules, eslintJestRules, eslintJsxA11yRules, eslintTestingLibraryRules, eslintCypressRules, eslintPlaywrightRules, eslintPluginRules, restrictedGlobals, restrictedGlobalsForBrowser, eslintPluginCustom, eslintPluginTotalFunctions, eslintPluginTreeShakable, defineConfig, defineKnownRules, withDefaultOption, plugins, type EslintRules, type EslintRulesOption, type TypeScriptEslintRules, type TypeScriptEslintRulesOption, type EslintFunctionalRules, type EslintFunctionalRulesOption, type EslintTotalFunctionsRules, type EslintUnicornRules, type EslintUnicornRulesOption, type EslintArrayFuncRules, type EslintPreferArrowFunctionRules, type EslintPreferArrowFunctionRulesOption, type EslintPluginSortDestructureKeysRules, type EslintPluginSortDestructureKeysRulesOption, type EslintPromiseRules, type EslintPromiseRulesOption, type EslintImportsRules, type EslintImportsRulesOption, type EslintStrictDependenciesRules, type EslintStrictDependenciesRulesOption, type EslintSecurityRules, type EslintTreeShakableRules, type EslintReactRules, type EslintReactRulesOption, type EslintReactHooksRules, type EslintReactHooksRulesOption, type EslintReactPerfRules, type EslintReactPerfRulesOption, type EslintReactRefreshRules, type EslintReactRefreshRulesOption, type EslintJsxA11yRules, type EslintJsxA11yRulesOption, type EslintVitestRules, type EslintVitestRulesOption, type EslintJestRules, type EslintJestRulesOption, type EslintPlaywrightRules, type EslintPlaywrightRulesOption, type EslintCypressRules, type EslintCypressRulesOption, type EslintTestingLibraryRules, type EslintTestingLibraryRulesOption, type EslintPluginRules, type EslintPluginRulesOption, type FlatConfig, type ESLintPlugin, type Rule, type Rules, } from './index.mjs';
|
|
1
|
+
export { eslintConfigForTypeScriptWithoutRules, eslintConfigForTypeScript, eslintConfigForBrowser, eslintConfigForNodeJs, eslintConfigForReact, eslintConfigForPreact, eslintConfigForVitest, eslintConfigForJest, eslintConfigForPlaywright, eslintConfigForCypress, eslintConfigForTestingLibrary, eslintRules, typescriptEslintRules, eslintFunctionalRules, eslintTotalFunctionsRules, eslintUnicornRules, eslintArrayFuncRules, eslintPreferArrowFunctionRules, eslintPluginSortDestructureKeysRules, eslintImportsRules, eslintPromiseRules, eslintSecurityRules, eslintTreeShakableRules, eslintReactRules, eslintReactHooksRules, eslintReactPerfRules, eslintReactRefreshRules, eslintVitestRules, eslintJestRules, eslintJsxA11yRules, eslintTestingLibraryRules, eslintCypressRules, eslintPlaywrightRules, eslintPluginRules, restrictedGlobals, restrictedGlobalsForBrowser, restrictedSyntax, restrictedSyntaxForReact, eslintPluginCustom, eslintPluginTotalFunctions, eslintPluginTreeShakable, defineConfig, defineKnownRules, withDefaultOption, plugins, type EslintRules, type EslintRulesOption, type TypeScriptEslintRules, type TypeScriptEslintRulesOption, type EslintFunctionalRules, type EslintFunctionalRulesOption, type EslintTotalFunctionsRules, type EslintUnicornRules, type EslintUnicornRulesOption, type EslintArrayFuncRules, type EslintPreferArrowFunctionRules, type EslintPreferArrowFunctionRulesOption, type EslintPluginSortDestructureKeysRules, type EslintPluginSortDestructureKeysRulesOption, type EslintPromiseRules, type EslintPromiseRulesOption, type EslintImportsRules, type EslintImportsRulesOption, type EslintStrictDependenciesRules, type EslintStrictDependenciesRulesOption, type EslintSecurityRules, type EslintTreeShakableRules, type EslintReactRules, type EslintReactRulesOption, type EslintReactHooksRules, type EslintReactHooksRulesOption, type EslintReactPerfRules, type EslintReactPerfRulesOption, type EslintReactRefreshRules, type EslintReactRefreshRulesOption, type EslintJsxA11yRules, type EslintJsxA11yRulesOption, type EslintVitestRules, type EslintVitestRulesOption, type EslintJestRules, type EslintJestRulesOption, type EslintPlaywrightRules, type EslintPlaywrightRulesOption, type EslintCypressRules, type EslintCypressRulesOption, type EslintTestingLibraryRules, type EslintTestingLibraryRulesOption, type EslintPluginRules, type EslintPluginRulesOption, type FlatConfig, type ESLintPlugin, type Rule, type Rules, } from './index.mjs';
|
|
2
2
|
//# sourceMappingURL=entry-point.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-point.d.mts","sourceRoot":"","sources":["../src/entry-point.mts"],"names":[],"mappings":"AACA,OAAO,EAEL,qCAAqC,EACrC,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,6BAA6B,EAG7B,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EAClB,oBAAoB,EACpB,8BAA8B,EAC9B,oCAAoC,EACpC,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EAGjB,iBAAiB,EACjB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"entry-point.d.mts","sourceRoot":"","sources":["../src/entry-point.mts"],"names":[],"mappings":"AACA,OAAO,EAEL,qCAAqC,EACrC,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,6BAA6B,EAG7B,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,kBAAkB,EAClB,oBAAoB,EACpB,8BAA8B,EAC9B,oCAAoC,EACpC,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EAGjB,iBAAiB,EACjB,2BAA2B,EAC3B,gBAAgB,EAChB,wBAAwB,EAGxB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EAGxB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EAGjB,OAAO,EAGP,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,oCAAoC,EACzC,KAAK,oCAAoC,EACzC,KAAK,0CAA0C,EAC/C,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,6BAA6B,EAClC,KAAK,mCAAmC,EACxC,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,6BAA6B,EAClC,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,+BAA+B,EACpC,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAG5B,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,KAAK,GACX,MAAM,aAAa,CAAC"}
|
package/dist/entry-point.mjs
CHANGED
|
@@ -20,7 +20,7 @@ export { eslintReactHooksRules } from './rules/eslint-react-hooks-rules.mjs';
|
|
|
20
20
|
export { eslintReactPerfRules } from './rules/eslint-react-perf-rules.mjs';
|
|
21
21
|
export { eslintReactRefreshRules } from './rules/eslint-react-refresh-rules.mjs';
|
|
22
22
|
export { eslintReactRules } from './rules/eslint-react-rules.mjs';
|
|
23
|
-
export { eslintRules, restrictedGlobals, restrictedGlobalsForBrowser } from './rules/eslint-rules.mjs';
|
|
23
|
+
export { eslintRules, restrictedGlobals, restrictedGlobalsForBrowser, restrictedSyntax, restrictedSyntaxForReact } from './rules/eslint-rules.mjs';
|
|
24
24
|
export { eslintSecurityRules } from './rules/eslint-security-rules.mjs';
|
|
25
25
|
export { eslintTestingLibraryRules } from './rules/eslint-testing-library-rules.mjs';
|
|
26
26
|
export { eslintTotalFunctionsRules } from './rules/eslint-total-functions-rules.mjs';
|
package/dist/index.mjs
CHANGED
|
@@ -29,7 +29,7 @@ export { eslintReactHooksRules } from './rules/eslint-react-hooks-rules.mjs';
|
|
|
29
29
|
export { eslintReactPerfRules } from './rules/eslint-react-perf-rules.mjs';
|
|
30
30
|
export { eslintReactRefreshRules } from './rules/eslint-react-refresh-rules.mjs';
|
|
31
31
|
export { eslintReactRules } from './rules/eslint-react-rules.mjs';
|
|
32
|
-
export { eslintRules, restrictedGlobals, restrictedGlobalsForBrowser } from './rules/eslint-rules.mjs';
|
|
32
|
+
export { eslintRules, restrictedGlobals, restrictedGlobalsForBrowser, restrictedSyntax, restrictedSyntaxForReact } from './rules/eslint-rules.mjs';
|
|
33
33
|
export { eslintSecurityRules } from './rules/eslint-security-rules.mjs';
|
|
34
34
|
export { eslintTestingLibraryRules } from './rules/eslint-testing-library-rules.mjs';
|
|
35
35
|
export { eslintTotalFunctionsRules } from './rules/eslint-total-functions-rules.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslint-import-rules.d.mts","sourceRoot":"","sources":["../../src/rules/eslint-import-rules.mts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"eslint-import-rules.d.mts","sourceRoot":"","sources":["../../src/rules/eslint-import-rules.mts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgH7B;;;OAGG;;;;;;;;;CAYkC,CAAC"}
|
|
@@ -50,6 +50,7 @@ const eslintImportsRules = {
|
|
|
50
50
|
'import/no-deprecated': 'off',
|
|
51
51
|
'import/no-extraneous-dependencies': 'off',
|
|
52
52
|
'import/no-mutable-exports': 'error',
|
|
53
|
+
// TODO: https://github.com/noshiro-pf/eslint-config-typed/issues/98
|
|
53
54
|
// 'import/no-unused-modules': ['error', { unusedExports: true }],
|
|
54
55
|
'import/no-unused-modules': 'off',
|
|
55
56
|
// moduleSystems
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslint-import-rules.mjs","sources":["../../src/rules/eslint-import-rules.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEO,MAAM,kBAAkB,GAAG;;AAEhC,IAAA,sBAAsB,EAAE,KAAK;AAE7B,IAAA,cAAc,EAAE,KAAK;AACrB,IAAA,gBAAgB,EAAE,OAAO;AACzB,IAAA,kBAAkB,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAC9C,4BAA4B,EAAE,KAAK;AACnC,IAAA,yBAAyB,EAAE,iBAAiB,CAAC,OAAO,CAAC;AACrD,IAAA,2BAA2B,EAAE,iBAAiB,CAAC,OAAO,CAAC;AACvD,IAAA,4BAA4B,EAAE;QAC5B,OAAO;AACP,QAAA;AACE,YAAA,KAAK,EAAE;gBACL,gBAAgB;gBAChB,cAAc;gBACd,8BAA8B;gBAC9B,kBAAkB;gBAClB,WAAW;gBACX,UAAU;gBACV,YAAY;gBACZ,uBAAuB;gBACvB,gBAAgB;gBAChB,iBAAiB;gBACjB,kBAAkB;gBAClB,gBAAgB;gBAChB,yCAAyC;gBACzC,eAAe;gBACf,aAAa;gBACb,YAAY;gBACZ,YAAY;AACb,aAAA;AACF,SAAA;AACF,KAAA;AACD,IAAA,iCAAiC,EAAE,OAAO;AAC1C,IAAA,uBAAuB,EAAE,OAAO;AAChC,IAAA,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC;AAC7C,IAAA,iCAAiC,EAAE,iBAAiB,CAAC,OAAO,CAAC;AAC7D,IAAA,mCAAmC,EAAE,KAAK;;AAG1C,IAAA,wCAAwC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC;AAEpE,IAAA,6BAA6B,EAAE,iBAAiB,CAAC,OAAO,CAAC;;AAGzD,IAAA,eAAe,EAAE,OAAO;AACxB,IAAA,4BAA4B,EAAE,OAAO;AACrC,IAAA,mCAAmC,EAAE,OAAO;;;AAI5C,IAAA,sBAAsB,EAAE,KAAK;AAE7B,IAAA,mCAAmC,EAAE,KAAK;AAC1C,IAAA,2BAA2B,EAAE,OAAO
|
|
1
|
+
{"version":3,"file":"eslint-import-rules.mjs","sources":["../../src/rules/eslint-import-rules.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAEO,MAAM,kBAAkB,GAAG;;AAEhC,IAAA,sBAAsB,EAAE,KAAK;AAE7B,IAAA,cAAc,EAAE,KAAK;AACrB,IAAA,gBAAgB,EAAE,OAAO;AACzB,IAAA,kBAAkB,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAC9C,4BAA4B,EAAE,KAAK;AACnC,IAAA,yBAAyB,EAAE,iBAAiB,CAAC,OAAO,CAAC;AACrD,IAAA,2BAA2B,EAAE,iBAAiB,CAAC,OAAO,CAAC;AACvD,IAAA,4BAA4B,EAAE;QAC5B,OAAO;AACP,QAAA;AACE,YAAA,KAAK,EAAE;gBACL,gBAAgB;gBAChB,cAAc;gBACd,8BAA8B;gBAC9B,kBAAkB;gBAClB,WAAW;gBACX,UAAU;gBACV,YAAY;gBACZ,uBAAuB;gBACvB,gBAAgB;gBAChB,iBAAiB;gBACjB,kBAAkB;gBAClB,gBAAgB;gBAChB,yCAAyC;gBACzC,eAAe;gBACf,aAAa;gBACb,YAAY;gBACZ,YAAY;AACb,aAAA;AACF,SAAA;AACF,KAAA;AACD,IAAA,iCAAiC,EAAE,OAAO;AAC1C,IAAA,uBAAuB,EAAE,OAAO;AAChC,IAAA,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC;AAC7C,IAAA,iCAAiC,EAAE,iBAAiB,CAAC,OAAO,CAAC;AAC7D,IAAA,mCAAmC,EAAE,KAAK;;AAG1C,IAAA,wCAAwC,EAAE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AAyB,EAAE,KAAK;AAEhC;;;AAGG;AACH,IAAA,0BAA0B,EAAE,OAAO;AAEnC,IAAA,wBAAwB,EAAE,KAAK;AAC/B,IAAA,oCAAoC,EAAE,iBAAiB,CAAC,OAAO,CAAC;AAChE,IAAA,sBAAsB,EAAE,KAAK;AAC7B,IAAA,iCAAiC,EAAE,iBAAiB,CAAC,OAAO,CAAC;AAC7D,IAAA,8BAA8B,EAAE,OAAO;AACvC,IAAA,oCAAoC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;;AAGzD,IAAA,sBAAsB,EAAE,CAAC;;;;;"}
|
|
@@ -69,6 +69,73 @@ export declare const restrictedGlobalsForBrowser: readonly [{
|
|
|
69
69
|
readonly name: "open";
|
|
70
70
|
readonly message: "Don't use confusing globals declared in lib.dom";
|
|
71
71
|
}];
|
|
72
|
+
export declare const restrictedSyntax: readonly [{
|
|
73
|
+
readonly selector: "BinaryExpression[operator='in']";
|
|
74
|
+
readonly message: "use \"Object.hasOwn\" instead.";
|
|
75
|
+
}, {
|
|
76
|
+
readonly selector: "MemberExpression[object.object.object.name='Object'][object.object.property.name='prototype'][object.property.name='hasOwnProperty'][property.name='call']";
|
|
77
|
+
readonly message: "use \"Object.hasOwn\" instead.";
|
|
78
|
+
}, {
|
|
79
|
+
readonly selector: "NewExpression[callee.name='Array']";
|
|
80
|
+
readonly message: "use Array.from instead.";
|
|
81
|
+
}];
|
|
82
|
+
export declare const restrictedSyntaxForReact: {
|
|
83
|
+
readonly importStyle: readonly [{
|
|
84
|
+
readonly selector: "ImportDeclaration[source.value='react'][specifiers.0.type!='ImportNamespaceSpecifier']";
|
|
85
|
+
readonly message: "React should be imported as `import * as React from 'react'`.";
|
|
86
|
+
}, {
|
|
87
|
+
readonly selector: "Identifier[name!='React'][parent.type='ImportNamespaceSpecifier'][parent.parent.type='ImportDeclaration'][parent.parent.source.value='react']";
|
|
88
|
+
readonly message: "The namespace name imported from 'react' must be 'React'.";
|
|
89
|
+
}];
|
|
90
|
+
readonly componentVarTypeAnnotation: readonly [{
|
|
91
|
+
readonly selector: "TSQualifiedName[left.name='React'][right.name='FC']";
|
|
92
|
+
readonly message: "Use React.memo<Props>((props) => { ... }) instead.";
|
|
93
|
+
}, {
|
|
94
|
+
readonly selector: "TSQualifiedName[left.name='React'][right.name='FunctionComponent']";
|
|
95
|
+
readonly message: "Use React.memo<Props>((props) => { ... }) instead.";
|
|
96
|
+
}];
|
|
97
|
+
readonly reactMemoTypeParam: readonly [{
|
|
98
|
+
readonly selector: "MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments=undefined]";
|
|
99
|
+
readonly message: "React.memo should have type parameter `'Props'`.";
|
|
100
|
+
}, {
|
|
101
|
+
readonly selector: "MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments!=undefined][parent.typeArguments.type!='TSTypeParameterInstantiation']";
|
|
102
|
+
readonly message: "React.memo should have type parameter `'Props'`.";
|
|
103
|
+
}, {
|
|
104
|
+
readonly selector: "MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments!=undefined][parent.typeArguments.type='TSTypeParameterInstantiation'][parent.typeArguments.params.0.type!='TSTypeReference']";
|
|
105
|
+
readonly message: "React.memo should have type parameter `'Props'`.";
|
|
106
|
+
}, {
|
|
107
|
+
readonly selector: "MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments!=undefined][parent.typeArguments.type='TSTypeParameterInstantiation'][parent.typeArguments.params.0.type='TSTypeReference'][parent.typeArguments.params.0.typeName.name!='Props']";
|
|
108
|
+
readonly message: "React.memo should have type parameter `'Props'`.";
|
|
109
|
+
}];
|
|
110
|
+
readonly propsTypeAnnotationStyle: readonly [{
|
|
111
|
+
readonly selector: "TSTypeAnnotation[parent.type='Identifier'][parent.parent.type='ArrowFunctionExpression'][parent.parent.parent.type='CallExpression'][parent.parent.parent.callee.object.name='React'][parent.parent.parent.callee.property.name='memo']";
|
|
112
|
+
readonly message: "Replace `React.memo((props: Props) => { ... })` with `React.memo<Props>((props) => { ... })`.";
|
|
113
|
+
}];
|
|
114
|
+
readonly reactMemoPropsArgumentName: readonly [{
|
|
115
|
+
readonly selector: "Identifier[name!='props'][parent.type='ArrowFunctionExpression'][parent.expression!=true][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='memo']";
|
|
116
|
+
readonly message: "The argument name of arrow function passed to React.memo should be 'props'.";
|
|
117
|
+
}, {
|
|
118
|
+
readonly selector: "ObjectPattern[parent.type='ArrowFunctionExpression'][parent.expression!=true][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='memo']";
|
|
119
|
+
readonly message: "The props of a component containing a return statement are limited to a variable named `'props'`.";
|
|
120
|
+
}];
|
|
121
|
+
readonly componentName: {
|
|
122
|
+
readonly maxLength: (maxLength?: number) => {
|
|
123
|
+
selector: string;
|
|
124
|
+
message: string;
|
|
125
|
+
}[];
|
|
126
|
+
readonly regexp: (pattern: string) => {
|
|
127
|
+
selector: string;
|
|
128
|
+
message: string;
|
|
129
|
+
}[];
|
|
130
|
+
};
|
|
131
|
+
readonly reactHooksDefinitionStyle: readonly [{
|
|
132
|
+
readonly selector: "MemberExpression[object.name='React'][property.name='useImperativeHandle']";
|
|
133
|
+
readonly message: "Move logic to parent component instead of using React.useImperativeHandle.";
|
|
134
|
+
}, {
|
|
135
|
+
readonly selector: "TSTypeAnnotation[parent.parent.type='CallExpression'][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='useMemo']";
|
|
136
|
+
readonly message: "The variable type T should be annotated as `React.useMemo<T>` or `const v: T = React.useMemo(...)`.";
|
|
137
|
+
}];
|
|
138
|
+
};
|
|
72
139
|
/** @link https://github.com/eslint/eslint/blob/main/conf/eslint-all.js */
|
|
73
140
|
export declare const eslintRules: {
|
|
74
141
|
/**
|
|
@@ -276,9 +343,6 @@ export declare const eslintRules: {
|
|
|
276
343
|
}, {
|
|
277
344
|
readonly selector: "NewExpression[callee.name='Array']";
|
|
278
345
|
readonly message: "use Array.from instead.";
|
|
279
|
-
}, {
|
|
280
|
-
readonly selector: "MemberExpression[object.name='React'][property.name='useImperativeHandle']";
|
|
281
|
-
readonly message: "pass Observable via props instead.";
|
|
282
346
|
}];
|
|
283
347
|
readonly 'no-return-assign': 2 | 1;
|
|
284
348
|
readonly 'no-self-assign': 2 | 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslint-rules.d.mts","sourceRoot":"","sources":["../../src/rules/eslint-rules.mts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;EA2BiC,CAAC;AAEhE,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDuB,CAAC;AAEhE,0EAA0E;AAC1E,eAAO,MAAM,WAAW;IACtB;;;;;OAKG;;;;IAYH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmKH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgBH;;;;;OAKG
|
|
1
|
+
{"version":3,"file":"eslint-rules.d.mts","sourceRoot":"","sources":["../../src/rules/eslint-rules.mts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;EA2BiC,CAAC;AAEhE,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiDuB,CAAC;AAEhE,eAAO,MAAM,gBAAgB;;;;;;;;;EAgCiC,CAAC;AAE/D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCA+HV,MAAM;;;;mCAmBX,MAAM;;;;;;;;;;;;CAiC3B,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,WAAW;IACtB;;;;;OAKG;;;;IAYH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmKH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgBH;;;;;OAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkDH;;;;;;;;OAQG;;;;IAMH,4GAA4G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyH9E,CAAC"}
|
|
@@ -76,6 +76,186 @@ const restrictedGlobalsForBrowser = [
|
|
|
76
76
|
message: "Don't use confusing globals declared in lib.dom",
|
|
77
77
|
},
|
|
78
78
|
];
|
|
79
|
+
const restrictedSyntax = [
|
|
80
|
+
{
|
|
81
|
+
// ban "in" operator
|
|
82
|
+
selector: "BinaryExpression[operator='in']",
|
|
83
|
+
message: 'use "Object.hasOwn" instead.',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
// ban Object.prototype.hasOwnProperty.call
|
|
87
|
+
selector: "MemberExpression[object.object.object.name='Object'][object.object.property.name='prototype'][object.property.name='hasOwnProperty'][property.name='call']",
|
|
88
|
+
message: 'use "Object.hasOwn" instead.',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
// ban "new Array" expression
|
|
92
|
+
selector: "NewExpression[callee.name='Array']",
|
|
93
|
+
message: 'use Array.from instead.',
|
|
94
|
+
},
|
|
95
|
+
// Covered by @typescript-eslint/consistent-type-assertions or total-functions/no-unsafe-type-assertion
|
|
96
|
+
// {
|
|
97
|
+
// // ban "as"
|
|
98
|
+
// selector: "TSAsExpression[typeAnnotation.typeName.name!='const']",
|
|
99
|
+
// message: "Don't use `as`.",
|
|
100
|
+
// },
|
|
101
|
+
// TODO
|
|
102
|
+
// {
|
|
103
|
+
// selector:
|
|
104
|
+
// "Identifier[name='draft'][parent.parent.callee.name!='produce'][parent.parent.parent.parent.parent.parent.callee.name!='produce']",
|
|
105
|
+
// message:
|
|
106
|
+
// "Don't use the identifier name `draft` except in immer produce function.",
|
|
107
|
+
// },
|
|
108
|
+
];
|
|
109
|
+
const restrictedSyntaxForReact = {
|
|
110
|
+
// [These rules recommends React component style like below]
|
|
111
|
+
//
|
|
112
|
+
// import * as React from "react";
|
|
113
|
+
//
|
|
114
|
+
// type Props = Readonly<{
|
|
115
|
+
// numList: readonly number[];
|
|
116
|
+
// }>;
|
|
117
|
+
//
|
|
118
|
+
// OK
|
|
119
|
+
// export const Ok = React.memo<Props>((props) => {
|
|
120
|
+
// const sum = React.useMemo(
|
|
121
|
+
// () => props.numList.reduce((a, b) => a + b, 0),
|
|
122
|
+
// [props.numList],
|
|
123
|
+
// );
|
|
124
|
+
//
|
|
125
|
+
// return <div>{sum}</div>;
|
|
126
|
+
// });
|
|
127
|
+
//
|
|
128
|
+
// export const NoReturnStatementWithSpread = React.memo<Props>(({ numList }) => <div>{numList.length}</div>); // OK
|
|
129
|
+
//
|
|
130
|
+
// export const NoReturnStatementWithoutSpread = React.memo<Props>((props) => <div>{props.numList.length}</div>); // OK
|
|
131
|
+
// https://typescript-eslint.io/play/#ts=5.9.3&showAST=es&fileType=.tsx&code=JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcARFDvmQNwCwAUKJLIiugDYQAmaAFnCIlyXXqj61GjGAE8wWOAAViYdAF5MObhAB2HGQB4A3ozhwdAVxAAZYKhgAuOJWTa9M81YBGWKAG0AXXoGAF8APmDGAHoouAB5AGlGLAAPFnhcXXt4gGs4DWw8GAA6ECwQCANlCFUwgAo6sBVUAEp8sLgTBjNMnWzUK3zNIuKLVCwAW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xhTAmkkRiNx3MISp1ruIt%2BedBn50AWo4B1ly5UkmSo%2BucCBoLlsqxDWZieRoPsZMLcmCRQhLeE0We31BgjDGEgBoANBJ%2BOqU%2BdcDYKCvCkiQMOlBaDrAWPY18YB1x7KcZ4ChXQspJiXpebMfdbzrwrLWAA3GAaRugKz-M3EEuYRQpSIFRY4zB5w4UQ0YXvFSB8skaSajpT%2BmcOpGRARCeZKzrKKkQOkIQJJhIAAl4p0CQEguQKCQL4H%2BvGZlRQAkAx4jPOY8UHBKlEM4gFmD6yNnfAwi4JiIAsM7GS%2BGIslqu3wO7eCudpbexGenKlsj%2BmQIxEsmZtK5laJNcRO1%2Bim4LmZVpfAfL2RbNQWMaJHS4kFVCGAbkZyhgqnim7Mw0xZjzxBZ67iyZuRZknvK%2BYPylRgGcBgcNQKRUKC9TmR8RZUlKRqIEfg5wQDnCAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDArugDTg2RGwAqkWgALdNADW6ACYBJIjPQAPWQEFo0dCTKUO6XgF8QhoA&tokens=false
|
|
132
|
+
// TODO: Create a separate plugin for these rules
|
|
133
|
+
/* Restrict import style of React */
|
|
134
|
+
importStyle: [
|
|
135
|
+
{
|
|
136
|
+
selector: "ImportDeclaration[source.value='react'][specifiers.0.type!='ImportNamespaceSpecifier']",
|
|
137
|
+
message: "React should be imported as `import * as React from 'react'`.",
|
|
138
|
+
// NOTE: React の import 方法を `import * as React from 'react'` と namespace import のみに限定するルール。
|
|
139
|
+
// import を1回で済ませられて便利なのと、 React.* に対する以降のルールを書きやすくするため。
|
|
140
|
+
// tree-shaking に悪影響は無い。
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
selector: "Identifier[name!='React'][parent.type='ImportNamespaceSpecifier'][parent.parent.type='ImportDeclaration'][parent.parent.source.value='react']",
|
|
144
|
+
message: "The namespace name imported from 'react' must be 'React'.",
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
/* Restrict React component definition style */
|
|
148
|
+
componentVarTypeAnnotation: [
|
|
149
|
+
{
|
|
150
|
+
// Ban "React.FC"
|
|
151
|
+
selector: "TSQualifiedName[left.name='React'][right.name='FC']",
|
|
152
|
+
message: 'Use React.memo<Props>((props) => { ... }) instead.',
|
|
153
|
+
// NOTE: React.FC による型注釈があれば React.memo を使うように促すルール。
|
|
154
|
+
// React.FC で型注釈されていない React.memo 化されていないコンポーネントは別途検出する必要がある。
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
// Ban "React.FunctionComponent"
|
|
158
|
+
selector: "TSQualifiedName[left.name='React'][right.name='FunctionComponent']",
|
|
159
|
+
message: 'Use React.memo<Props>((props) => { ... }) instead.',
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
reactMemoTypeParam: [
|
|
163
|
+
// NOTE: React.memo の型引数を `Props` に限定する。
|
|
164
|
+
// これは 1ファイル1コンポーネントの強制も意味する。
|
|
165
|
+
// 前提: component が React.memo でラップされていること。
|
|
166
|
+
{
|
|
167
|
+
selector:
|
|
168
|
+
// Detects `React.memo(...)`
|
|
169
|
+
"MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments=undefined]",
|
|
170
|
+
message: "React.memo should have type parameter `'Props'`.",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
selector:
|
|
174
|
+
// Detects `React.memo<NotProps>(...)`
|
|
175
|
+
"MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments!=undefined][parent.typeArguments.type!='TSTypeParameterInstantiation']",
|
|
176
|
+
message: "React.memo should have type parameter `'Props'`.",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
selector:
|
|
180
|
+
// Detects `React.memo<{ prop1: number }>(...)`
|
|
181
|
+
"MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments!=undefined][parent.typeArguments.type='TSTypeParameterInstantiation'][parent.typeArguments.params.0.type!='TSTypeReference']",
|
|
182
|
+
message: "React.memo should have type parameter `'Props'`.",
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
selector:
|
|
186
|
+
// Detects `React.memo<NotProps>(...)`, `React.memo<Readonly<{ prop1: number }>>(...)`
|
|
187
|
+
"MemberExpression[object.name='React'][property.name='memo'][parent.typeArguments!=undefined][parent.typeArguments.type='TSTypeParameterInstantiation'][parent.typeArguments.params.0.type='TSTypeReference'][parent.typeArguments.params.0.typeName.name!='Props']",
|
|
188
|
+
message: "React.memo should have type parameter `'Props'`.",
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
propsTypeAnnotationStyle: [
|
|
192
|
+
{
|
|
193
|
+
// Restrict Props type annotation style for React.memo
|
|
194
|
+
selector: "TSTypeAnnotation[parent.type='Identifier'][parent.parent.type='ArrowFunctionExpression'][parent.parent.parent.type='CallExpression'][parent.parent.parent.callee.object.name='React'][parent.parent.parent.callee.property.name='memo']",
|
|
195
|
+
message: 'Replace `React.memo((props: Props) => { ... })` with `React.memo<Props>((props) => { ... })`.',
|
|
196
|
+
// 前提: Arrow function の使用が強制されていること。
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
/* Restrict props argument name to be "props" */
|
|
200
|
+
reactMemoPropsArgumentName: [
|
|
201
|
+
{
|
|
202
|
+
// Restrict props argument name to be "props"
|
|
203
|
+
selector: "Identifier[name!='props'][parent.type='ArrowFunctionExpression'][parent.expression!=true][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='memo']",
|
|
204
|
+
message: "The argument name of arrow function passed to React.memo should be 'props'.",
|
|
205
|
+
// NOTE: component props を "props" という名前に限定する。
|
|
206
|
+
// 前提: component が React.memo でラップされていること。Arrow function の使用が強制されていること。
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
// Restrict props argument to be "props" variable (object destructuring is not allowed)
|
|
210
|
+
selector:
|
|
211
|
+
// Detect `React.memo<Props>(({ prop1, prop2 }) => { ... })`
|
|
212
|
+
"ObjectPattern[parent.type='ArrowFunctionExpression'][parent.expression!=true][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='memo']",
|
|
213
|
+
message: "The props of a component containing a return statement are limited to a variable named `'props'`.",
|
|
214
|
+
// NOTE: return 文を含む component の props を "props" という名前の変数に限定する。
|
|
215
|
+
// 前提: component が React.memo でラップされていること。Arrow function の使用が強制されていること。
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
componentName: {
|
|
219
|
+
maxLength: (maxLength = 42) => [
|
|
220
|
+
{
|
|
221
|
+
// Limit the length of component names ${maxLength} characters
|
|
222
|
+
selector: `Identifier[name=/^.{${maxLength},}$/][parent.type='VariableDeclarator'][parent.init.type='CallExpression'][parent.init.callee.object.name='React'][parent.init.callee.property.name='memo']`,
|
|
223
|
+
message: `The component name length should be less than ${maxLength}. Consider rewrite as \`const Component = React.memo<Props>((props) => { }); export { Component as SomeComponent };\`.`,
|
|
224
|
+
// NOTE:
|
|
225
|
+
// `const Name = React.memo<Props>((props) => {`
|
|
226
|
+
// が1行に収まるようにするためのルール。1行に収まらないとインデントが増えてコンポーネント実装の可読性が下がりやすくなるため。
|
|
227
|
+
// component props の型名や引数名の制約と併せて、 prettier のデフォルト print-width = 80 で export を省いた場合の最大長としてデフォルト値 42 を設定している。
|
|
228
|
+
// 抵触する場合、以下のように書き換える。
|
|
229
|
+
//
|
|
230
|
+
// const Component = React.memo<Props>((props) => {
|
|
231
|
+
// ...
|
|
232
|
+
// });
|
|
233
|
+
//
|
|
234
|
+
// export { Component as SomeComponent };
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
regexp: (pattern) => [
|
|
238
|
+
{
|
|
239
|
+
// Validate that component names match the provided pattern
|
|
240
|
+
selector: `Identifier[name=${pattern}][parent.type='VariableDeclarator'][parent.init.type='CallExpression'][parent.init.callee.object.name='React'][parent.init.callee.property.name='memo']`,
|
|
241
|
+
message: `The component name should match ${pattern}.`,
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
/* Restrict React hooks definition style */
|
|
246
|
+
reactHooksDefinitionStyle: [
|
|
247
|
+
{
|
|
248
|
+
// Ban "React.useImperativeHandle"
|
|
249
|
+
selector: "MemberExpression[object.name='React'][property.name='useImperativeHandle']",
|
|
250
|
+
message: 'Move logic to parent component instead of using React.useImperativeHandle.',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
// Restrict type annotation style for React.useMemo
|
|
254
|
+
selector: "TSTypeAnnotation[parent.parent.type='CallExpression'][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='useMemo']",
|
|
255
|
+
message: 'The variable type T should be annotated as `React.useMemo<T>` or `const v: T = React.useMemo(...)`.',
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
};
|
|
79
259
|
/** @link https://github.com/eslint/eslint/blob/main/conf/eslint-all.js */
|
|
80
260
|
const eslintRules = {
|
|
81
261
|
/**
|
|
@@ -274,41 +454,7 @@ const eslintRules = {
|
|
|
274
454
|
*
|
|
275
455
|
* AST checker: https://typescript-eslint.io/play/#ts=5.9.3&showAST=es&fileType=.ts&code=LAKCA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
|
|
276
456
|
*/
|
|
277
|
-
'no-restricted-syntax': [
|
|
278
|
-
'error',
|
|
279
|
-
{
|
|
280
|
-
// ban "in" operator
|
|
281
|
-
selector: "BinaryExpression[operator='in']",
|
|
282
|
-
message: 'use "Object.hasOwn" instead.',
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
// ban Object.prototype.hasOwnProperty.call
|
|
286
|
-
selector: "MemberExpression[object.object.object.name='Object'][object.object.property.name='prototype'][object.property.name='hasOwnProperty'][property.name='call']",
|
|
287
|
-
message: 'use "Object.hasOwn" instead.',
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
// ban "new Array" expression
|
|
291
|
-
selector: "NewExpression[callee.name='Array']",
|
|
292
|
-
message: 'use Array.from instead.',
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
// ban "React.useImperativeHandle"
|
|
296
|
-
selector: "MemberExpression[object.name='React'][property.name='useImperativeHandle']",
|
|
297
|
-
message: 'pass Observable via props instead.',
|
|
298
|
-
},
|
|
299
|
-
// replaced by @typescript-eslint/consistent-type-assertions and total-functions/no-unsafe-type-assertion
|
|
300
|
-
// {
|
|
301
|
-
// // ban "as"
|
|
302
|
-
// selector: "TSAsExpression[typeAnnotation.typeName.name!='const']",
|
|
303
|
-
// message: "Don't use `as`.",
|
|
304
|
-
// },
|
|
305
|
-
// {
|
|
306
|
-
// selector:
|
|
307
|
-
// "Identifier[name='draft'][parent.parent.callee.name!='produce'][parent.parent.parent.parent.parent.parent.callee.name!='produce']",
|
|
308
|
-
// message:
|
|
309
|
-
// "Don't use the identifier name `draft` except in immer produce function.",
|
|
310
|
-
// },
|
|
311
|
-
],
|
|
457
|
+
'no-restricted-syntax': ['error', ...restrictedSyntax],
|
|
312
458
|
'no-return-assign': withDefaultOption('error'),
|
|
313
459
|
'no-self-assign': withDefaultOption('error'),
|
|
314
460
|
'no-self-compare': 'error',
|
|
@@ -485,5 +631,5 @@ const eslintRules = {
|
|
|
485
631
|
'multiline-comment-style': 0, // disabled
|
|
486
632
|
};
|
|
487
633
|
|
|
488
|
-
export { eslintRules, restrictedGlobals, restrictedGlobalsForBrowser };
|
|
634
|
+
export { eslintRules, restrictedGlobals, restrictedGlobalsForBrowser, restrictedSyntax, restrictedSyntaxForReact };
|
|
489
635
|
//# sourceMappingURL=eslint-rules.mjs.map
|