eslint-config-typed 1.8.1 → 2.0.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 +349 -202
- package/dist/configs/browser.d.mts +3 -0
- package/dist/configs/browser.d.mts.map +1 -0
- package/dist/configs/browser.mjs +26 -0
- package/dist/configs/browser.mjs.map +1 -0
- package/dist/configs/cypress.d.mts +1 -1
- package/dist/configs/cypress.d.mts.map +1 -1
- package/dist/configs/cypress.mjs +2 -3
- package/dist/configs/cypress.mjs.map +1 -1
- package/dist/configs/index.d.mts +2 -0
- package/dist/configs/index.d.mts.map +1 -1
- package/dist/configs/index.mjs +12 -10
- package/dist/configs/index.mjs.map +1 -1
- package/dist/configs/jest.d.mts +1 -1
- package/dist/configs/jest.d.mts.map +1 -1
- package/dist/configs/jest.mjs +2 -3
- package/dist/configs/jest.mjs.map +1 -1
- package/dist/configs/nodejs.d.mts +3 -0
- package/dist/configs/nodejs.d.mts.map +1 -0
- package/dist/configs/nodejs.mjs +36 -0
- package/dist/configs/nodejs.mjs.map +1 -0
- package/dist/configs/playwright.d.mts +1 -1
- package/dist/configs/playwright.d.mts.map +1 -1
- package/dist/configs/playwright.mjs +2 -3
- package/dist/configs/playwright.mjs.map +1 -1
- package/dist/configs/plugins.d.mts.map +1 -1
- package/dist/configs/plugins.mjs +1 -19
- package/dist/configs/plugins.mjs.map +1 -1
- package/dist/configs/preact.d.mts +1 -1
- package/dist/configs/preact.d.mts.map +1 -1
- package/dist/configs/preact.mjs +30 -4
- package/dist/configs/preact.mjs.map +1 -1
- package/dist/configs/react-base.d.mts +1 -1
- package/dist/configs/react-base.d.mts.map +1 -1
- package/dist/configs/react-base.mjs +20 -24
- package/dist/configs/react-base.mjs.map +1 -1
- package/dist/configs/react.d.mts +1 -1
- package/dist/configs/react.d.mts.map +1 -1
- package/dist/configs/react.mjs +4 -4
- package/dist/configs/react.mjs.map +1 -1
- package/dist/configs/testing-library.d.mts +1 -1
- package/dist/configs/testing-library.d.mts.map +1 -1
- package/dist/configs/testing-library.mjs +2 -3
- package/dist/configs/testing-library.mjs.map +1 -1
- package/dist/configs/typescript-without-rules.d.mts +1 -1
- package/dist/configs/typescript-without-rules.d.mts.map +1 -1
- package/dist/configs/typescript-without-rules.mjs +2 -2
- package/dist/configs/typescript-without-rules.mjs.map +1 -1
- package/dist/configs/typescript.d.mts +2 -1
- package/dist/configs/typescript.d.mts.map +1 -1
- package/dist/configs/typescript.mjs +27 -20
- package/dist/configs/typescript.mjs.map +1 -1
- package/dist/configs/vitest.d.mts +1 -1
- package/dist/configs/vitest.d.mts.map +1 -1
- package/dist/configs/vitest.mjs +2 -3
- package/dist/configs/vitest.mjs.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 +18 -37
- package/dist/entry-point.mjs.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +17 -35
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/custom/custom.d.mts +3 -0
- package/dist/plugins/custom/custom.d.mts.map +1 -0
- package/dist/plugins/custom/custom.mjs +8 -0
- package/dist/plugins/custom/custom.mjs.map +1 -0
- package/dist/plugins/custom/index.d.mts +2 -0
- package/dist/plugins/custom/index.d.mts.map +1 -0
- package/dist/{custom-rules → plugins/custom}/index.mjs +0 -1
- package/dist/{custom-rules → plugins/custom}/index.mjs.map +1 -1
- package/dist/plugins/custom/rules/index.d.mts +2 -0
- package/dist/plugins/custom/rules/index.d.mts.map +1 -0
- package/dist/plugins/custom/rules/index.mjs +2 -0
- package/dist/plugins/custom/rules/index.mjs.map +1 -0
- package/dist/plugins/custom/rules/no-restricted-syntax2.d.mts.map +1 -0
- package/dist/{custom-rules → plugins/custom/rules}/no-restricted-syntax2.mjs +1 -1
- package/dist/plugins/custom/rules/no-restricted-syntax2.mjs.map +1 -0
- package/dist/plugins/custom/rules/rules.d.mts +4 -0
- package/dist/plugins/custom/rules/rules.d.mts.map +1 -0
- package/dist/plugins/custom/rules/rules.mjs +8 -0
- package/dist/plugins/custom/rules/rules.mjs.map +1 -0
- package/dist/plugins/index.d.mts +1 -0
- package/dist/plugins/index.d.mts.map +1 -1
- package/dist/plugins/index.mjs +1 -20
- package/dist/plugins/index.mjs.map +1 -1
- package/dist/plugins/total-functions/index.d.mts +0 -1
- package/dist/plugins/total-functions/index.d.mts.map +1 -1
- package/dist/plugins/total-functions/index.mjs +0 -18
- package/dist/plugins/total-functions/index.mjs.map +1 -1
- package/dist/plugins/total-functions/rules/no-unsafe-optional-property-assignment.mjs +1 -1
- package/dist/plugins/total-functions/rules/no-unsafe-optional-property-assignment.mjs.map +1 -1
- package/dist/plugins/total-functions/rules/rules.d.mts +10 -8
- package/dist/plugins/total-functions/rules/rules.d.mts.map +1 -1
- package/dist/plugins/total-functions/rules/rules.mjs +12 -8
- package/dist/plugins/total-functions/rules/rules.mjs.map +1 -1
- package/dist/plugins/tree-shakable/index.d.mts +0 -1
- package/dist/plugins/tree-shakable/index.d.mts.map +1 -1
- package/dist/plugins/tree-shakable/index.mjs +0 -2
- package/dist/plugins/tree-shakable/index.mjs.map +1 -1
- package/dist/rules/eslint-array-func-rules.d.mts +8 -2
- package/dist/rules/eslint-array-func-rules.d.mts.map +1 -1
- package/dist/rules/eslint-array-func-rules.mjs.map +1 -1
- package/dist/rules/eslint-cypress-rules.d.mts +14 -2
- package/dist/rules/eslint-cypress-rules.d.mts.map +1 -1
- package/dist/rules/eslint-cypress-rules.mjs.map +1 -1
- package/dist/rules/eslint-functional-rules.d.mts +32 -5
- package/dist/rules/eslint-functional-rules.d.mts.map +1 -1
- package/dist/rules/eslint-functional-rules.mjs +47 -40
- package/dist/rules/eslint-functional-rules.mjs.map +1 -1
- package/dist/rules/eslint-import-rules.d.mts +64 -2
- package/dist/rules/eslint-import-rules.d.mts.map +1 -1
- package/dist/rules/eslint-import-rules.mjs.map +1 -1
- package/dist/rules/eslint-jest-rules.d.mts +73 -2
- package/dist/rules/eslint-jest-rules.d.mts.map +1 -1
- package/dist/rules/eslint-jest-rules.mjs.map +1 -1
- package/dist/rules/eslint-jsx-a11y-rules.d.mts +47 -2
- package/dist/rules/eslint-jsx-a11y-rules.d.mts.map +1 -1
- package/dist/rules/eslint-jsx-a11y-rules.mjs.map +1 -1
- package/dist/rules/eslint-playwright-rules.d.mts +56 -2
- package/dist/rules/eslint-playwright-rules.d.mts.map +1 -1
- package/dist/rules/eslint-playwright-rules.mjs.map +1 -1
- package/dist/rules/eslint-plugin-rules.d.mts +35 -2
- package/dist/rules/eslint-plugin-rules.d.mts.map +1 -1
- package/dist/rules/eslint-plugin-rules.mjs.map +1 -1
- package/dist/rules/eslint-plugin-sort-destructure-keys-rules.d.mts +3 -2
- package/dist/rules/eslint-plugin-sort-destructure-keys-rules.d.mts.map +1 -1
- package/dist/rules/eslint-plugin-sort-destructure-keys-rules.mjs.map +1 -1
- package/dist/rules/eslint-prefer-arrow-functions-rules.d.mts +11 -2
- package/dist/rules/eslint-prefer-arrow-functions-rules.d.mts.map +1 -1
- package/dist/rules/eslint-prefer-arrow-functions-rules.mjs.map +1 -1
- package/dist/rules/eslint-promise-rules.d.mts +21 -2
- package/dist/rules/eslint-promise-rules.d.mts.map +1 -1
- package/dist/rules/eslint-promise-rules.mjs.map +1 -1
- package/dist/rules/eslint-react-hooks-rules.d.mts +31 -2
- package/dist/rules/eslint-react-hooks-rules.d.mts.map +1 -1
- package/dist/rules/eslint-react-hooks-rules.mjs.map +1 -1
- package/dist/rules/eslint-react-perf-rules.d.mts +6 -2
- package/dist/rules/eslint-react-perf-rules.d.mts.map +1 -1
- package/dist/rules/eslint-react-perf-rules.mjs.map +1 -1
- package/dist/rules/eslint-react-refresh-rules.d.mts +3 -2
- package/dist/rules/eslint-react-refresh-rules.d.mts.map +1 -1
- package/dist/rules/eslint-react-refresh-rules.mjs.map +1 -1
- package/dist/rules/eslint-react-rules.d.mts +142 -2
- package/dist/rules/eslint-react-rules.d.mts.map +1 -1
- package/dist/rules/eslint-react-rules.mjs.map +1 -1
- package/dist/rules/eslint-rules.d.mts +442 -31
- package/dist/rules/eslint-rules.d.mts.map +1 -1
- package/dist/rules/eslint-rules.mjs +114 -74
- package/dist/rules/eslint-rules.mjs.map +1 -1
- package/dist/rules/eslint-security-rules.d.mts +16 -2
- package/dist/rules/eslint-security-rules.d.mts.map +1 -1
- package/dist/rules/eslint-security-rules.mjs.map +1 -1
- package/dist/rules/eslint-testing-library-rules.d.mts +34 -2
- package/dist/rules/eslint-testing-library-rules.d.mts.map +1 -1
- package/dist/rules/eslint-testing-library-rules.mjs.map +1 -1
- package/dist/rules/eslint-total-functions-rules.d.mts +16 -2
- package/dist/rules/eslint-total-functions-rules.d.mts.map +1 -1
- package/dist/rules/eslint-total-functions-rules.mjs +2 -0
- package/dist/rules/eslint-total-functions-rules.mjs.map +1 -1
- package/dist/rules/eslint-tree-shakable-rules.d.mts +3 -2
- package/dist/rules/eslint-tree-shakable-rules.d.mts.map +1 -1
- package/dist/rules/eslint-tree-shakable-rules.mjs.map +1 -1
- package/dist/rules/eslint-unicorn-rules.d.mts +186 -2
- package/dist/rules/eslint-unicorn-rules.d.mts.map +1 -1
- package/dist/rules/eslint-unicorn-rules.mjs +29 -31
- package/dist/rules/eslint-unicorn-rules.mjs.map +1 -1
- package/dist/rules/eslint-vitest-rules.d.mts +62 -2
- package/dist/rules/eslint-vitest-rules.d.mts.map +1 -1
- package/dist/rules/eslint-vitest-rules.mjs.map +1 -1
- package/dist/rules/index.mjs +3 -3
- package/dist/rules/typescript-eslint-rules.d.mts +316 -4
- package/dist/rules/typescript-eslint-rules.d.mts.map +1 -1
- package/dist/rules/typescript-eslint-rules.mjs +111 -57
- package/dist/rules/typescript-eslint-rules.mjs.map +1 -1
- package/dist/types/define-config.d.mts +3 -0
- package/dist/types/define-config.d.mts.map +1 -0
- package/dist/types/define-config.mjs +4 -0
- package/dist/types/define-config.mjs.map +1 -0
- package/dist/types/define-known-rules.d.mts +2 -2
- package/dist/types/define-known-rules.d.mts.map +1 -1
- package/dist/types/define-known-rules.mjs.map +1 -1
- package/dist/types/flat-config.d.mts +1 -1
- package/dist/types/flat-config.d.mts.map +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -1
- package/dist/types/rules/eslint-custom-rules.d.mts +62 -0
- package/dist/types/rules/eslint-custom-rules.d.mts.map +1 -0
- package/dist/types/rules/eslint-custom-rules.mjs +2 -0
- package/dist/types/rules/eslint-custom-rules.mjs.map +1 -0
- package/dist/types/rules/eslint-total-functions-rules.d.mts +64 -32
- package/dist/types/rules/eslint-total-functions-rules.d.mts.map +1 -1
- package/dist/types/rules/index.d.mts +1 -0
- package/dist/types/rules/index.d.mts.map +1 -1
- package/package.json +10 -3
- package/src/configs/browser.mts +24 -0
- package/src/configs/cypress.mts +1 -3
- package/src/configs/index.mts +2 -0
- package/src/configs/jest.mts +1 -3
- package/src/configs/nodejs.mts +34 -0
- package/src/configs/playwright.mts +1 -1
- package/src/configs/plugins.mts +1 -2
- package/src/configs/preact.mts +29 -4
- package/src/configs/react-base.mts +20 -24
- package/src/configs/react.mts +3 -3
- package/src/configs/testing-library.mts +1 -1
- package/src/configs/typescript-without-rules.mts +1 -1
- package/src/configs/typescript.mts +31 -19
- package/src/configs/vitest.mts +1 -3
- package/src/entry-point.mts +109 -1
- package/src/index.mts +0 -1
- package/src/plugins/custom/custom.mts +6 -0
- package/src/plugins/custom/index.mts +1 -0
- package/src/plugins/custom/rules/index.mts +1 -0
- package/src/{custom-rules → plugins/custom/rules}/no-restricted-syntax2.mts +1 -1
- package/src/plugins/custom/rules/rules.mts +6 -0
- package/src/plugins/index.mts +1 -0
- package/src/plugins/total-functions/index.mts +0 -1
- package/src/plugins/total-functions/rules/no-unsafe-optional-property-assignment.mts +1 -1
- package/src/plugins/total-functions/rules/rules.mts +12 -8
- package/src/plugins/tree-shakable/index.mts +0 -1
- package/src/rules/eslint-array-func-rules.mts +2 -2
- package/src/rules/eslint-cypress-rules.mts +2 -2
- package/src/rules/eslint-functional-rules.mts +52 -47
- package/src/rules/eslint-import-rules.mts +2 -2
- package/src/rules/eslint-jest-rules.mts +2 -2
- package/src/rules/eslint-jsx-a11y-rules.mts +2 -2
- package/src/rules/eslint-playwright-rules.mts +2 -2
- package/src/rules/eslint-plugin-rules.mts +2 -2
- package/src/rules/eslint-plugin-sort-destructure-keys-rules.mts +3 -4
- package/src/rules/eslint-prefer-arrow-functions-rules.mts +2 -2
- package/src/rules/eslint-promise-rules.mts +2 -2
- package/src/rules/eslint-react-hooks-rules.mts +2 -2
- package/src/rules/eslint-react-perf-rules.mts +2 -2
- package/src/rules/eslint-react-refresh-rules.mts +2 -2
- package/src/rules/eslint-react-rules.mts +2 -2
- package/src/rules/eslint-rules.mts +126 -79
- package/src/rules/eslint-security-rules.mts +2 -2
- package/src/rules/eslint-testing-library-rules.mts +2 -2
- package/src/rules/eslint-total-functions-rules.mts +5 -2
- package/src/rules/eslint-tree-shakable-rules.mts +2 -2
- package/src/rules/eslint-unicorn-rules.mts +35 -33
- package/src/rules/eslint-vitest-rules.mts +2 -2
- package/src/rules/typescript-eslint-rules.mts +120 -65
- package/src/types/define-config.mts +5 -0
- package/src/types/define-known-rules.mts +4 -0
- package/src/types/flat-config.mts +1 -3
- package/src/types/index.mts +1 -1
- package/src/types/rules/eslint-custom-rules.mts +76 -0
- package/src/types/rules/eslint-total-functions-rules.mts +68 -32
- package/src/types/rules/index.mts +1 -0
- package/dist/custom-rules/custom.d.mts +0 -3
- package/dist/custom-rules/custom.d.mts.map +0 -1
- package/dist/custom-rules/custom.mjs +0 -10
- package/dist/custom-rules/custom.mjs.map +0 -1
- package/dist/custom-rules/index.d.mts +0 -3
- package/dist/custom-rules/index.d.mts.map +0 -1
- package/dist/custom-rules/no-restricted-syntax2.d.mts.map +0 -1
- package/dist/custom-rules/no-restricted-syntax2.mjs.map +0 -1
- package/dist/types/types.d.mts +0 -8
- package/dist/types/types.d.mts.map +0 -1
- package/dist/types/types.mjs +0 -2
- package/dist/types/types.mjs.map +0 -1
- package/src/custom-rules/custom.mts +0 -8
- package/src/custom-rules/index.mts +0 -2
- package/src/types/types.mts +0 -7
- /package/dist/{custom-rules → plugins/custom/rules}/no-restricted-syntax2.d.mts +0 -0
package/README.md
CHANGED
|
@@ -13,6 +13,9 @@ A comprehensive ESLint configuration package with strongly-typed rule definition
|
|
|
13
13
|
- [Requirements](#requirements)
|
|
14
14
|
- [Installation](#installation)
|
|
15
15
|
- [Quick Start](#quick-start)
|
|
16
|
+
- [defineConfig helper](#defineconfig-helper)
|
|
17
|
+
- [defineKnownRules utility](#defineknownrules-utility)
|
|
18
|
+
- [withDefaultOption utility](#withdefaultoption-utility)
|
|
16
19
|
- [Configuration Examples](#configuration-examples)
|
|
17
20
|
- [TypeScript + React Project](#typescript--react-project)
|
|
18
21
|
- [Node.js TypeScript Project](#nodejs-typescript-project)
|
|
@@ -20,27 +23,36 @@ A comprehensive ESLint configuration package with strongly-typed rule definition
|
|
|
20
23
|
- [VS Code Integration](#vs-code-integration)
|
|
21
24
|
- [API Reference](#api-reference)
|
|
22
25
|
- [Configuration Functions](#configuration-functions)
|
|
26
|
+
- [Base Configurations](#base-configurations)
|
|
27
|
+
- [Framework Configurations](#framework-configurations)
|
|
28
|
+
- [Utility Configurations](#utility-configurations)
|
|
23
29
|
- [Rule Collections](#rule-collections)
|
|
24
|
-
- [
|
|
30
|
+
- [Exported Pre-configured Rule Options](#exported-pre-configured-rule-options)
|
|
25
31
|
- [Custom Plugins](#custom-plugins)
|
|
26
|
-
- [Custom Rules](#custom-rules)
|
|
27
32
|
- [Type Definitions](#type-definitions)
|
|
33
|
+
- [Core Types](#core-types)
|
|
34
|
+
- [Rule Types](#rule-types)
|
|
28
35
|
- [Customization](#customization)
|
|
29
36
|
- [Override Specific Rules](#override-specific-rules)
|
|
30
37
|
- [Use Type-Safe Rule Options](#use-type-safe-rule-options)
|
|
31
38
|
- [Target Specific Files](#target-specific-files)
|
|
32
39
|
- [Troubleshooting](#troubleshooting)
|
|
40
|
+
- [Common Issues](#common-issues)
|
|
41
|
+
- [1. ESLint can't find tsconfig.json](#1-eslint-cant-find-tsconfigjson)
|
|
42
|
+
- [2. Import resolution errors](#2-import-resolution-errors)
|
|
43
|
+
- [3. Performance issues](#3-performance-issues)
|
|
44
|
+
- [Known Limitations](#known-limitations)
|
|
33
45
|
- [Contributing](#contributing)
|
|
34
46
|
- [License](#license)
|
|
47
|
+
- [Future Updates](#future-updates)
|
|
35
48
|
|
|
36
49
|
## Features
|
|
37
50
|
|
|
38
51
|
- 🎯 **Type-Safe Configuration**: Fully typed ESLint rules and configurations for better IDE support
|
|
39
52
|
- 📦 **Pre-configured Setups**: Ready-to-use configurations for TypeScript, React, Preact, and popular testing frameworks
|
|
40
|
-
- 🔧 **Custom Rules**: Additional custom ESLint rules for enhanced code quality
|
|
41
|
-
- 🚀 **Zero Configuration**: Works out of the box with sensible defaults
|
|
42
|
-
- 🔄 **ESLint Flat Config Support**: Built for the modern ESLint flat configuration system
|
|
43
53
|
- 📝 **Comprehensive Type Definitions**: Complete TypeScript types for all ESLint rules and options
|
|
54
|
+
- 🔄 **ESLint Flat Config Support**: Built for the modern ESLint flat configuration system
|
|
55
|
+
- 🔧 **Custom Rules**: Additional custom ESLint rules for enhanced code quality
|
|
44
56
|
|
|
45
57
|
## Requirements
|
|
46
58
|
|
|
@@ -51,7 +63,7 @@ A comprehensive ESLint configuration package with strongly-typed rule definition
|
|
|
51
63
|
## Installation
|
|
52
64
|
|
|
53
65
|
```sh
|
|
54
|
-
npm
|
|
66
|
+
npm add -D eslint-config-typed
|
|
55
67
|
# or
|
|
56
68
|
yarn add -D eslint-config-typed
|
|
57
69
|
# or
|
|
@@ -66,50 +78,53 @@ Create an `eslint.config.js` file in your project root:
|
|
|
66
78
|
|
|
67
79
|
```js
|
|
68
80
|
import {
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
defineConfig,
|
|
82
|
+
eslintConfigForTypeScript,
|
|
83
|
+
eslintConfigForVitest,
|
|
84
|
+
defineKnownRules,
|
|
71
85
|
} from 'eslint-config-typed';
|
|
72
|
-
import * as path from 'node:path';
|
|
73
|
-
import * as url from 'node:url';
|
|
86
|
+
// import * as path from 'node:path';
|
|
87
|
+
// import * as url from 'node:url';
|
|
74
88
|
|
|
75
89
|
const thisDir = import.meta.dirname;
|
|
76
90
|
// or path.dirname(url.fileURLToPath(import.meta.url));
|
|
77
91
|
|
|
78
|
-
|
|
79
|
-
const defineConfig = () => [
|
|
92
|
+
export default defineConfig([
|
|
80
93
|
{
|
|
81
94
|
// config with just ignores is the replacement for `.eslintignore`
|
|
82
95
|
ignores: ['**/build/**', '**/dist/**', 'src/some/file/to/ignore.ts'],
|
|
83
96
|
},
|
|
84
|
-
|
|
97
|
+
|
|
98
|
+
// Base config for TypeScript & JavaScript code
|
|
99
|
+
...eslintConfigForTypeScript({
|
|
85
100
|
tsconfigRootDir: thisDir,
|
|
86
101
|
tsconfigFileName: './tsconfig.json',
|
|
87
102
|
packageDirs: [thisDir],
|
|
88
103
|
|
|
89
|
-
// If you are using
|
|
104
|
+
// If you are using a monorepo and the root package.json is located at ../../../:
|
|
90
105
|
// packageDirs: [path.resolve(thisDir, '../../..'), thisDir],
|
|
91
106
|
}),
|
|
92
|
-
|
|
107
|
+
eslintConfigForVitest(),
|
|
93
108
|
|
|
94
109
|
// You can override per-rule settings if necessary.
|
|
95
110
|
{
|
|
96
|
-
rules: {
|
|
111
|
+
rules: defineKnownRules({
|
|
97
112
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
98
113
|
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
|
|
99
114
|
'react-hooks/exhaustive-deps': 'warn',
|
|
100
|
-
'functional/no-let': [
|
|
101
|
-
|
|
115
|
+
'functional/no-let': [
|
|
116
|
+
'error',
|
|
117
|
+
{
|
|
118
|
+
allowInForLoopInit: true,
|
|
119
|
+
allowInFunctions: false,
|
|
120
|
+
ignoreIdentifierPattern: ignorePattern.filter(
|
|
121
|
+
(p) => p !== '^draft',
|
|
122
|
+
),
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}),
|
|
102
126
|
},
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
/** @type {import('eslint-config-typed').EslintFunctionalRulesOption['functional/no-let']} */
|
|
106
|
-
const noLetOptions = {
|
|
107
|
-
allowInForLoopInit: false,
|
|
108
|
-
allowInFunctions: false,
|
|
109
|
-
ignoreIdentifierPattern: ignorePattern.filter((p) => p !== '^draft'),
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export default defineConfig();
|
|
127
|
+
]);
|
|
113
128
|
```
|
|
114
129
|
|
|
115
130
|
Add a lint script to your `package.json`:
|
|
@@ -131,83 +146,156 @@ npm run lint
|
|
|
131
146
|
npm run lint:fix
|
|
132
147
|
```
|
|
133
148
|
|
|
149
|
+
### defineConfig helper
|
|
150
|
+
|
|
151
|
+
`defineConfig` wraps your flat configuration array so JavaScript config files get full IntelliSense without relying on JSDoc casts. It keeps literal types intact while returning the config unchanged at runtime.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
import { defineConfig, eslintConfigForTypeScript } from 'eslint-config-typed';
|
|
155
|
+
|
|
156
|
+
export default defineConfig([
|
|
157
|
+
...eslintConfigForTypeScript({
|
|
158
|
+
tsconfigRootDir: import.meta.dirname,
|
|
159
|
+
tsconfigFileName: './tsconfig.json',
|
|
160
|
+
packageDirs: [import.meta.dirname],
|
|
161
|
+
}),
|
|
162
|
+
{
|
|
163
|
+
rules: defineKnownRules({
|
|
164
|
+
// ...
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
]);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This is equivalent to:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
import { eslintConfigForTypeScript } from 'eslint-config-typed';
|
|
174
|
+
|
|
175
|
+
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig[]} */
|
|
176
|
+
export default [
|
|
177
|
+
...eslintConfigForTypeScript({
|
|
178
|
+
tsconfigRootDir: import.meta.dirname,
|
|
179
|
+
tsconfigFileName: './tsconfig.json',
|
|
180
|
+
packageDirs: [import.meta.dirname],
|
|
181
|
+
}),
|
|
182
|
+
{
|
|
183
|
+
rules: defineKnownRules({
|
|
184
|
+
// ...
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
];
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### defineKnownRules utility
|
|
191
|
+
|
|
192
|
+
`defineKnownRules` is a helper designed for the `rules` field in ESLint flat configs. It keeps the returned object untouched while giving you type-safe rule names and option inference in editors. When you wrap your overrides with this function you can rely on:
|
|
193
|
+
|
|
194
|
+
- autocomplete and early feedback for rule identifiers, eliminating typo-prone string literals;
|
|
195
|
+
- strongly typed options for every plugin rule that ships with `eslint-config-typed`, so you can discover valid properties without leaving your editor;
|
|
196
|
+
- a zero-cost runtime helper—because the object is returned as-is, it blends seamlessly into any flat config block.
|
|
197
|
+
|
|
198
|
+
### withDefaultOption utility
|
|
199
|
+
|
|
200
|
+
`withDefaultOption` is a companion helper that highlights rules which ship with option objects. It maps the familiar severity strings to the numeric values ESLint expects: `withDefaultOption('error')` returns `2`, and `withDefaultOption('warn')` returns `1`. Within `defineKnownRules`, rules that provide options require one of these helpers when you want to keep the defaults and only adjust severity. This convention visually distinguishes rules that contain options, reminding users that a rule has configurable options.
|
|
201
|
+
|
|
202
|
+
`defineKnownRules` also reserves `0` for deprecated rules. The resulting severity matrix looks like this:
|
|
203
|
+
|
|
204
|
+
| Rule type | Allowed severity values in `defineKnownRules` |
|
|
205
|
+
| :------------------- | :------------------------------------------------------------- |
|
|
206
|
+
| Deprecated rule | `0` |
|
|
207
|
+
| Rule without options | `"off"`, `"warn"`, `"error"` |
|
|
208
|
+
| Rule with options | `"off"`, `1`, `2`, `["warn", <option>]`, `["error", <option>]` |
|
|
209
|
+
|
|
134
210
|
## Configuration Examples
|
|
135
211
|
|
|
136
212
|
### TypeScript + React Project
|
|
137
213
|
|
|
138
214
|
```js
|
|
139
215
|
import {
|
|
140
|
-
|
|
141
|
-
|
|
216
|
+
defineConfig,
|
|
217
|
+
eslintConfigForTypeScript,
|
|
218
|
+
eslintConfigForReact,
|
|
219
|
+
eslintConfigForNodeJs,
|
|
220
|
+
defineKnownRules,
|
|
142
221
|
} from 'eslint-config-typed';
|
|
143
|
-
import * as path from 'node:path';
|
|
144
|
-
import * as url from 'node:url';
|
|
145
222
|
|
|
146
223
|
const thisDir = import.meta.dirname;
|
|
147
224
|
|
|
148
|
-
export default [
|
|
225
|
+
export default defineConfig([
|
|
149
226
|
{ ignores: ['**/dist/**', '**/build/**', '**/.next/**'] },
|
|
150
|
-
...
|
|
227
|
+
...eslintConfigForTypeScript({
|
|
151
228
|
tsconfigRootDir: thisDir,
|
|
152
229
|
tsconfigFileName: './tsconfig.json',
|
|
153
230
|
packageDirs: [thisDir],
|
|
154
231
|
}),
|
|
155
|
-
|
|
156
|
-
]
|
|
232
|
+
eslintConfigForReact(['src/**']),
|
|
233
|
+
eslintConfigForNodeJs(['scripts/**', 'configs/**']),
|
|
234
|
+
{
|
|
235
|
+
files: ['scripts/**', 'configs/**'],
|
|
236
|
+
rules: defineKnownRules({
|
|
237
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
238
|
+
'no-await-in-loop': 'off',
|
|
239
|
+
'import/no-unassigned-import': 'off',
|
|
240
|
+
'import/no-internal-modules': 'off',
|
|
241
|
+
'import/no-default-export': 'off',
|
|
242
|
+
'import/no-extraneous-dependencies': 'off',
|
|
243
|
+
}),
|
|
244
|
+
},
|
|
245
|
+
]);
|
|
157
246
|
```
|
|
158
247
|
|
|
159
248
|
### Node.js TypeScript Project
|
|
160
249
|
|
|
161
250
|
```js
|
|
162
|
-
import {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
251
|
+
import {
|
|
252
|
+
defineConfig,
|
|
253
|
+
eslintConfigForTypeScript,
|
|
254
|
+
eslintConfigForNodeJs,
|
|
255
|
+
defineKnownRules,
|
|
256
|
+
} from 'eslint-config-typed';
|
|
167
257
|
|
|
168
|
-
export default [
|
|
258
|
+
export default defineConfig([
|
|
169
259
|
{ ignores: ['**/dist/**', '**/node_modules/**'] },
|
|
170
|
-
...
|
|
171
|
-
tsconfigRootDir:
|
|
260
|
+
...eslintConfigForTypeScript({
|
|
261
|
+
tsconfigRootDir: import.meta.dirname,
|
|
172
262
|
tsconfigFileName: './tsconfig.json',
|
|
173
|
-
packageDirs: [
|
|
263
|
+
packageDirs: [import.meta.dirname],
|
|
174
264
|
}),
|
|
265
|
+
eslintConfigForNodeJs(),
|
|
175
266
|
{
|
|
176
|
-
rules: {
|
|
267
|
+
rules: defineKnownRules({
|
|
177
268
|
// Allow console in Node.js
|
|
178
269
|
'no-console': 'off',
|
|
179
270
|
// Allow process.env access
|
|
180
271
|
'no-process-env': 'off',
|
|
181
|
-
},
|
|
272
|
+
}),
|
|
182
273
|
},
|
|
183
|
-
];
|
|
274
|
+
]);
|
|
184
275
|
```
|
|
185
276
|
|
|
186
277
|
### React + Testing Libraries
|
|
187
278
|
|
|
188
279
|
```js
|
|
189
280
|
import {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
281
|
+
defineConfig,
|
|
282
|
+
eslintConfigForTypeScript,
|
|
283
|
+
eslintConfigForReact,
|
|
284
|
+
eslintConfigForVitest,
|
|
285
|
+
eslintConfigForTestingLibrary,
|
|
194
286
|
} from 'eslint-config-typed';
|
|
195
|
-
import * as path from 'node:path';
|
|
196
|
-
import * as url from 'node:url';
|
|
197
287
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
export default [
|
|
288
|
+
export default defineConfig([
|
|
201
289
|
{ ignores: ['**/dist/**', '**/coverage/**'] },
|
|
202
|
-
...
|
|
203
|
-
tsconfigRootDir:
|
|
290
|
+
...eslintConfigForTypeScript({
|
|
291
|
+
tsconfigRootDir: import.meta.dirname,
|
|
204
292
|
tsconfigFileName: './tsconfig.json',
|
|
205
|
-
packageDirs: [
|
|
293
|
+
packageDirs: [import.meta.dirname],
|
|
206
294
|
}),
|
|
207
|
-
...
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
];
|
|
295
|
+
...eslintConfigForReact(),
|
|
296
|
+
eslintConfigForVitest(),
|
|
297
|
+
eslintConfigForTestingLibrary(),
|
|
298
|
+
]);
|
|
211
299
|
```
|
|
212
300
|
|
|
213
301
|
## VS Code Integration
|
|
@@ -234,92 +322,112 @@ Add the following to `.vscode/settings.json` for proper ESLint integration:
|
|
|
234
322
|
|
|
235
323
|
These functions return arrays of ESLint flat configurations:
|
|
236
324
|
|
|
237
|
-
####
|
|
325
|
+
#### Base Configurations
|
|
238
326
|
|
|
239
|
-
- **`
|
|
327
|
+
- **`eslintConfigForTypeScript(options)`** - TypeScript configuration with strict type checking rules
|
|
240
328
|
- `options.tsconfigRootDir`: Root directory containing tsconfig.json
|
|
241
329
|
- `options.tsconfigFileName`: Path to tsconfig.json file
|
|
242
330
|
- `options.packageDirs`: Array of package directories for import resolution
|
|
243
|
-
- **`
|
|
244
|
-
- **`
|
|
245
|
-
- **`eslintFlatConfigForReactBase(options?)`** - Base React configuration without specific framework rules
|
|
331
|
+
- **`eslintConfigForBrowser`** - Browser configuration (Turn off Node.js-specific rules)
|
|
332
|
+
- **`eslintConfigForNodeJs`** - Node.js configuration (Turn off browser-specific rules)
|
|
246
333
|
|
|
247
|
-
####
|
|
334
|
+
#### Framework Configurations
|
|
248
335
|
|
|
249
|
-
- **`
|
|
250
|
-
-
|
|
251
|
-
- **`
|
|
252
|
-
-
|
|
253
|
-
- **`
|
|
336
|
+
- **`eslintConfigForReact(options?)`** - React configuration with hooks and JSX rules
|
|
337
|
+
- `eslintConfigForBrowser` is included in this configuration
|
|
338
|
+
- **`eslintConfigForPreact(options?)`** - Preact configuration (lighter React alternative)
|
|
339
|
+
- `eslintConfigForBrowser` is included in this configuration
|
|
340
|
+
- **`eslintConfigForVitest(options?)`** - Vitest testing framework configuration
|
|
341
|
+
- **`eslintConfigForJest(options?)`** - Jest testing framework configuration
|
|
342
|
+
- **`eslintConfigForTestingLibrary(options?)`** - Testing Library configuration
|
|
343
|
+
- **`eslintConfigForPlaywright(options?)`** - Playwright E2E testing configuration
|
|
344
|
+
- **`eslintConfigForCypress(options?)`** - Cypress E2E testing configuration
|
|
254
345
|
|
|
255
346
|
#### Utility Configurations
|
|
256
347
|
|
|
257
|
-
- **`
|
|
348
|
+
- **`eslintConfigForTypeScriptWithoutRules(options)`** - TypeScript parser & plugins setup without any rules
|
|
258
349
|
|
|
259
350
|
### Rule Collections
|
|
260
351
|
|
|
261
352
|
Pre-configured rule sets that can be imported and customized:
|
|
262
353
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
354
|
+
| Rule set | Plugin name | Description |
|
|
355
|
+
| :----------------------------------------- | :------------------------------------- | :----------------------------------- |
|
|
356
|
+
| **`eslintRules`** | (eslint) | Core ESLint rules |
|
|
357
|
+
| **`typescriptEslintRules`** | `@typescript-eslint/eslint-plugin` | TypeScript-specific ESLint rules |
|
|
358
|
+
| **`eslintFunctionalRules`** | `eslint-plugin-functional` | Functional programming style rules |
|
|
359
|
+
| **`eslintTotalFunctionsRules`** | `eslint-plugin-total-functions` | Functional programming style rules |
|
|
360
|
+
| **`eslintUnicornRules`** | `eslint-plugin-unicorn` | Unicorn plugin rules for better code |
|
|
361
|
+
| **`eslintArrayFuncRules`** | `eslint-plugin-array-func` | Array function preference rules |
|
|
362
|
+
| **`eslintPreferArrowFunctionRules`** | `eslint-plugin-prefer-arrow-functions` | Arrow function preference rules |
|
|
363
|
+
| **`eslintPluginSortDestructureKeysRules`** | `eslint-plugin-sort-destructure-keys` | Object destructuring rules |
|
|
364
|
+
| **`eslintPromiseRules`** | `eslint-plugin-promise` | Promise handling rules |
|
|
365
|
+
| **`eslintImportsRules`** | `eslint-plugin-import` | Import/export rules |
|
|
366
|
+
| **`eslintSecurityRules`** | `eslint-plugin-security` | Security best practices |
|
|
367
|
+
| **`eslintTreeShakableRules`** | `eslint-plugin-tree-shakable` | Tree-shaking optimization rules |
|
|
368
|
+
| **`eslintReactRules`** | `eslint-plugin-react` | React-specific rules |
|
|
369
|
+
| **`eslintReactHooksRules`** | `eslint-plugin-react-hooks` | React Hooks rules |
|
|
370
|
+
| **`eslintReactPerfRules`** | `eslint-plugin-react-perf` | React performance optimization rules |
|
|
371
|
+
| **`eslintReactRefreshRules`** | `eslint-plugin-react-refresh` | React Refresh (HMR) rules |
|
|
372
|
+
| **`eslintJsxA11yRules`** | `eslint-plugin-jsx-a11y` | Accessibility rules for JSX |
|
|
373
|
+
| **`eslintVitestRules`** | `eslint-plugin-vitest` | Vitest-specific rules |
|
|
374
|
+
| **`eslintJestRules`** | `eslint-plugin-jest` | Jest-specific rules |
|
|
375
|
+
| **`eslintTestingLibraryRules`** | `eslint-plugin-testing-library` | Testing Library rules |
|
|
376
|
+
| **`eslintPlaywrightRules`** | `eslint-plugin-playwright` | Playwright-specific rules |
|
|
377
|
+
| **`eslintCypressRules`** | `eslint-plugin-cypress` | Cypress-specific rules |
|
|
378
|
+
| **`eslintPluginRules`** | `eslint-plugin-eslint-plugin` | eslint-plugin development rules |
|
|
379
|
+
|
|
380
|
+
### Exported Pre-configured Rule Options
|
|
381
|
+
|
|
382
|
+
| Pre-configured rule option | Rule | Description |
|
|
383
|
+
| :-------------------------------- | :---------------------- | :---------------------------------------------- |
|
|
384
|
+
| **`restrictedGlobals`** | `no-restricted-globals` | Array of restricted global variables |
|
|
385
|
+
| **`restrictedGlobalsForBrowser`** | `no-restricted-globals` | Browser-environment-specific restricted globals |
|
|
386
|
+
|
|
387
|
+
You can find other pre-configured rule options by traversing the pre-defined rules object like this:
|
|
388
|
+
|
|
389
|
+
- `typescriptEslintRules['@typescript-eslint/no-restricted-types'][1].types`
|
|
390
|
+
- `eslintRules['no-restricted-syntax'].slice(1)`
|
|
391
|
+
|
|
392
|
+
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.
|
|
297
393
|
|
|
298
394
|
### Custom Plugins
|
|
299
395
|
|
|
396
|
+
- **`eslintPluginTotalFunctions`**
|
|
397
|
+
- `eslint-plugin-total-functions` with support for Flat Config
|
|
398
|
+
- **`eslintPluginTreeShakable`**
|
|
399
|
+
- `eslint-plugin-tree-shakable` with support for Flat Config
|
|
300
400
|
- **`eslintPluginCustom`** - Custom ESLint plugin with additional rules
|
|
301
|
-
-
|
|
302
|
-
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
-
|
|
314
|
-
|
|
315
|
-
-
|
|
316
|
-
|
|
317
|
-
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
401
|
+
- Currently, this plugin only provides the `custom/no-restricted-syntax` rule (which duplicates ESLint's `no-restricted-syntax` rule).
|
|
402
|
+
- Can be used to set the error level to `error` or `warn` as needed.
|
|
403
|
+
|
|
404
|
+
Example:
|
|
405
|
+
|
|
406
|
+
```js
|
|
407
|
+
import { eslintRules } from 'eslint-config-typed';
|
|
408
|
+
|
|
409
|
+
export default defineConfig([
|
|
410
|
+
// ...
|
|
411
|
+
{
|
|
412
|
+
rules: defineKnownRules({
|
|
413
|
+
'no-restricted-syntax': [
|
|
414
|
+
'warn',
|
|
415
|
+
...eslintRules['no-restricted-syntax'].slice(1),
|
|
416
|
+
],
|
|
417
|
+
'custom/no-restricted-syntax': [
|
|
418
|
+
'error',
|
|
419
|
+
{
|
|
420
|
+
// Restrict import style of React
|
|
421
|
+
selector:
|
|
422
|
+
"ImportDeclaration[source.value='react'][specifiers.0.type!='ImportNamespaceSpecifier']",
|
|
423
|
+
message:
|
|
424
|
+
"React should be imported as `import * as React from 'react'.",
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
}),
|
|
428
|
+
},
|
|
429
|
+
]);
|
|
430
|
+
```
|
|
323
431
|
|
|
324
432
|
### Type Definitions
|
|
325
433
|
|
|
@@ -331,49 +439,56 @@ All rules and configurations come with complete TypeScript type definitions:
|
|
|
331
439
|
- **`ESLintPlugin`** - ESLint plugin type
|
|
332
440
|
- **`Rule`** - ESLint rule definition type
|
|
333
441
|
- **`Rules`** - Collection of rules type
|
|
334
|
-
- **`RestrictedImportsOption`** - Type for restricted imports configuration
|
|
335
442
|
|
|
336
443
|
#### Rule Types
|
|
337
444
|
|
|
338
445
|
Each plugin provides typed rule definitions:
|
|
339
446
|
|
|
340
|
-
-
|
|
341
|
-
- **`
|
|
342
|
-
- **`
|
|
343
|
-
- **`
|
|
344
|
-
- **`
|
|
345
|
-
- **`
|
|
346
|
-
- **`
|
|
347
|
-
- **`
|
|
348
|
-
- **`
|
|
349
|
-
- **`
|
|
350
|
-
- **`
|
|
351
|
-
- **`
|
|
352
|
-
- **`
|
|
353
|
-
- **`
|
|
354
|
-
-
|
|
355
|
-
- **`
|
|
356
|
-
- **`
|
|
357
|
-
- **`
|
|
358
|
-
- **`
|
|
359
|
-
- **`
|
|
360
|
-
-
|
|
361
|
-
- **`
|
|
362
|
-
- **`
|
|
363
|
-
- **`
|
|
447
|
+
- General rules
|
|
448
|
+
- **`EslintRules`** & **`EslintRulesOption`**
|
|
449
|
+
- **`TypeScriptEslintRules`** & **`TypeScriptEslintRulesOption`**
|
|
450
|
+
- **`EslintFunctionalRules`** & **`EslintFunctionalRulesOption`**
|
|
451
|
+
- **`EslintTotalFunctionsRules`** (no options)
|
|
452
|
+
- **`EslintUnicornRules`** & **`EslintUnicornRulesOption`**
|
|
453
|
+
- **`EslintArrayFuncRules`** (no options)
|
|
454
|
+
- **`EslintPreferArrowFunctionRules`** & **`EslintPreferArrowFunctionRulesOption`**
|
|
455
|
+
- **`EslintPluginSortDestructureKeysRules`** & **`EslintPluginSortDestructureKeysRulesOption`**
|
|
456
|
+
- **`EslintPromiseRules`** & **`EslintPromiseRulesOption`**
|
|
457
|
+
- **`EslintImportsRules`** & **`EslintImportsRulesOption`**
|
|
458
|
+
- **`EslintStrictDependenciesRules`** & **`EslintStrictDependenciesRulesOption`**
|
|
459
|
+
- **`EslintSecurityRules`** (no options)
|
|
460
|
+
- **`EslintTreeShakableRules`** (no options)
|
|
461
|
+
- React & JSX
|
|
462
|
+
- **`EslintReactRules`** & **`EslintReactRulesOption`**
|
|
463
|
+
- **`EslintReactHooksRules`** & **`EslintReactHooksRulesOption`**
|
|
464
|
+
- **`EslintReactPerfRules`** & **`EslintReactPerfRulesOption`**
|
|
465
|
+
- **`EslintReactRefreshRules`** & **`EslintReactRefreshRulesOption`**
|
|
466
|
+
- **`EslintJsxA11yRules`** & **`EslintJsxA11yRulesOption`**
|
|
467
|
+
- Testing
|
|
468
|
+
- **`EslintVitestRules`** & **`EslintVitestRulesOption`**
|
|
469
|
+
- **`EslintJestRules`** & **`EslintJestRulesOption`**
|
|
470
|
+
- **`EslintPlaywrightRules`** & **`EslintPlaywrightRulesOption`**
|
|
471
|
+
- **`EslintCypressRules`** & **`EslintCypressRulesOption`**
|
|
472
|
+
- **`EslintTestingLibraryRules`** & **`EslintTestingLibraryRulesOption`**
|
|
473
|
+
- Others
|
|
474
|
+
- **`EslintPluginRules`** & **`EslintPluginRulesOption`**
|
|
364
475
|
|
|
365
476
|
## Customization
|
|
366
477
|
|
|
478
|
+
The pre-configured rules of `eslint-config-typed` are opinionated settings that prioritize strictness and enable as many non-conflicting rules as possible. Therefore, it is intended to be used by downgrading the severity of unnecessary rules in the config file from `"error"` to `"warn"` or `"off"`, or by overriding option settings.
|
|
479
|
+
|
|
367
480
|
### Override Specific Rules
|
|
368
481
|
|
|
369
482
|
You can override any rule by adding a configuration object after the preset configurations:
|
|
370
483
|
|
|
371
484
|
```js
|
|
372
|
-
|
|
373
|
-
|
|
485
|
+
import { typescriptEslintRules } from 'eslint-config-typed';
|
|
486
|
+
|
|
487
|
+
export default defineConfig([
|
|
488
|
+
...eslintConfigForTypeScript(options),
|
|
374
489
|
{
|
|
375
|
-
rules: {
|
|
376
|
-
// Downgrade to warning
|
|
490
|
+
rules: defineKnownRules({
|
|
491
|
+
// Downgrade to warning (Option settings are inherited)
|
|
377
492
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
378
493
|
// Disable a rule
|
|
379
494
|
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
|
|
@@ -385,57 +500,86 @@ export default [
|
|
|
385
500
|
allowInFunctions: false,
|
|
386
501
|
},
|
|
387
502
|
],
|
|
388
|
-
|
|
503
|
+
|
|
504
|
+
// Update rule options
|
|
505
|
+
'@typescript-eslint/no-restricted-types': [
|
|
506
|
+
'error',
|
|
507
|
+
{
|
|
508
|
+
types: {
|
|
509
|
+
...typescriptEslintRules[
|
|
510
|
+
'@typescript-eslint/no-restricted-types'
|
|
511
|
+
][1].types,
|
|
512
|
+
Function: "Don't use Function type",
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
],
|
|
516
|
+
}),
|
|
389
517
|
},
|
|
390
|
-
];
|
|
518
|
+
]);
|
|
391
519
|
```
|
|
392
520
|
|
|
393
521
|
### Use Type-Safe Rule Options
|
|
394
522
|
|
|
395
523
|
Leverage TypeScript for type-safe rule configuration:
|
|
396
524
|
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
const noLetOptions = {
|
|
400
|
-
allowInForLoopInit: false,
|
|
401
|
-
allowInFunctions: false,
|
|
402
|
-
};
|
|
525
|
+
```ts
|
|
526
|
+
// configs/restricted-syntax-defs.mjs
|
|
403
527
|
|
|
404
|
-
|
|
405
|
-
|
|
528
|
+
import { eslintRules } from 'eslint-config-typed';
|
|
529
|
+
|
|
530
|
+
/** @type {import("eslint-config-typed").EslintRulesOption["no-restricted-syntax"]} */
|
|
531
|
+
export const restrictedSyntax = [
|
|
532
|
+
...eslintRules['no-restricted-syntax'].slice(1),
|
|
406
533
|
{
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
534
|
+
// Restrict type annotation style for React.useMemo
|
|
535
|
+
selector:
|
|
536
|
+
"TSTypeAnnotation[parent.parent.type='CallExpression'][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='useMemo']",
|
|
537
|
+
message:
|
|
538
|
+
'The variable type T should be annotated as `React.useMemo<T>` or `const v: T = React.useMemo(...)`.',
|
|
410
539
|
},
|
|
411
540
|
];
|
|
412
541
|
```
|
|
413
542
|
|
|
543
|
+
```ts
|
|
544
|
+
// eslint.config.js
|
|
545
|
+
|
|
546
|
+
import { restrictedSyntax } from './configs/restricted-syntax-defs.mjs';
|
|
547
|
+
|
|
548
|
+
export default defineConfig([
|
|
549
|
+
...eslintConfigForTypeScript(options),
|
|
550
|
+
{
|
|
551
|
+
rules: defineKnownRules({
|
|
552
|
+
'no-restricted-syntax': ['error', restrictedSyntax],
|
|
553
|
+
}),
|
|
554
|
+
},
|
|
555
|
+
]);
|
|
556
|
+
```
|
|
557
|
+
|
|
414
558
|
### Target Specific Files
|
|
415
559
|
|
|
416
560
|
Apply different rules to different file patterns:
|
|
417
561
|
|
|
418
562
|
```js
|
|
419
|
-
export default [
|
|
420
|
-
...
|
|
563
|
+
export default defineConfig([
|
|
564
|
+
...eslintConfigForTypeScript(options),
|
|
421
565
|
{
|
|
422
566
|
files: ['**/*.test.ts', '**/*.spec.ts'],
|
|
423
|
-
rules: {
|
|
567
|
+
rules: defineKnownRules({
|
|
424
568
|
// Allow any in tests
|
|
425
569
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
426
570
|
// Allow console in tests
|
|
427
571
|
'no-console': 'off',
|
|
428
|
-
},
|
|
572
|
+
}),
|
|
429
573
|
},
|
|
430
574
|
{
|
|
431
|
-
files: ['
|
|
432
|
-
rules: {
|
|
575
|
+
files: ['scripts/**/*.ts'],
|
|
576
|
+
rules: defineKnownRules({
|
|
433
577
|
// Allow console in scripts
|
|
434
|
-
'no-
|
|
435
|
-
'no-
|
|
436
|
-
},
|
|
578
|
+
'no-await-in-loop': 'off',
|
|
579
|
+
'import/no-unassigned-import': 'off',
|
|
580
|
+
}),
|
|
437
581
|
},
|
|
438
|
-
];
|
|
582
|
+
]);
|
|
439
583
|
```
|
|
440
584
|
|
|
441
585
|
## Troubleshooting
|
|
@@ -449,11 +593,13 @@ Ensure the paths are correct:
|
|
|
449
593
|
```js
|
|
450
594
|
const thisDir = import.meta.dirname;
|
|
451
595
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
596
|
+
export default defineConfig([
|
|
597
|
+
...eslintConfigForTypeScript({
|
|
598
|
+
tsconfigRootDir: thisDir, // Must be absolute path
|
|
599
|
+
tsconfigFileName: './tsconfig.json', // Relative to tsconfigRootDir
|
|
600
|
+
packageDirs: [thisDir],
|
|
601
|
+
}),
|
|
602
|
+
]);
|
|
457
603
|
```
|
|
458
604
|
|
|
459
605
|
#### 2. Import resolution errors
|
|
@@ -461,24 +607,25 @@ const thisDir = import.meta.dirname;
|
|
|
461
607
|
The `packageDirs` option helps ESLint resolve imports correctly in monorepos:
|
|
462
608
|
|
|
463
609
|
```js
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
610
|
+
export default defineConfig([
|
|
611
|
+
...eslintConfigForTypeScript({
|
|
612
|
+
tsconfigRootDir: thisDir,
|
|
613
|
+
tsconfigFileName: './tsconfig.json',
|
|
614
|
+
packageDirs: [
|
|
615
|
+
path.resolve(thisDir, '../../..'), // Monorepo root
|
|
616
|
+
thisDir, // Current package
|
|
617
|
+
],
|
|
618
|
+
}),
|
|
619
|
+
]);
|
|
472
620
|
```
|
|
473
621
|
|
|
474
|
-
#### 3.
|
|
475
|
-
|
|
476
|
-
If you encounter rule conflicts, the last configuration wins. Place your overrides after the preset configurations.
|
|
477
|
-
|
|
478
|
-
#### 4. Performance issues
|
|
622
|
+
#### 3. Performance issues
|
|
479
623
|
|
|
480
624
|
For large projects, consider:
|
|
481
625
|
|
|
626
|
+
- Using `TIMING=1 eslint` to identify heavy rules
|
|
627
|
+
- Using `NODE_OPTIONS='--max-old-space-size=<memory-size-MB>' eslint` to increase the maximum memory available
|
|
628
|
+
- Separate heavy rules into a separate config and prepare a dedicated command
|
|
482
629
|
- Using `.eslintignore` or `ignores` patterns to skip generated files
|
|
483
630
|
- Running ESLint with `--cache` flag
|
|
484
631
|
- Limiting the scope of type-aware rules
|