eslint-config-typed 1.8.1 → 2.1.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 +377 -209
- 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 +12 -3
- 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 +36 -2
- package/dist/rules/eslint-plugin-rules.d.mts.map +1 -1
- package/dist/rules/eslint-plugin-rules.mjs +1 -0
- 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 +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 +189 -2
- package/dist/rules/eslint-unicorn-rules.d.mts.map +1 -1
- package/dist/rules/eslint-unicorn-rules.mjs +33 -32
- 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-plugin-rules.d.mts +17 -0
- package/dist/types/rules/eslint-plugin-rules.d.mts.map +1 -1
- package/dist/types/rules/eslint-react-hooks-rules.d.mts +2 -1
- package/dist/types/rules/eslint-react-hooks-rules.d.mts.map +1 -1
- 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/eslint-unicorn-rules.d.mts +219 -142
- package/dist/types/rules/eslint-unicorn-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 +17 -10
- 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 +11 -2
- 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 +3 -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 +3 -3
- 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 +40 -34
- 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-plugin-rules.mts +18 -0
- package/src/types/rules/eslint-react-hooks-rules.mts +2 -1
- package/src/types/rules/eslint-total-functions-rules.mts +68 -32
- package/src/types/rules/eslint-unicorn-rules.mts +226 -142
- 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,23 +13,36 @@ 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)
|
|
19
22
|
- [React + Testing Libraries](#react--testing-libraries)
|
|
20
23
|
- [VS Code Integration](#vs-code-integration)
|
|
24
|
+
- [Included plugins](#included-plugins)
|
|
21
25
|
- [API Reference](#api-reference)
|
|
22
26
|
- [Configuration Functions](#configuration-functions)
|
|
27
|
+
- [Base Configurations](#base-configurations)
|
|
28
|
+
- [Framework Configurations](#framework-configurations)
|
|
29
|
+
- [Utility Configurations](#utility-configurations)
|
|
23
30
|
- [Rule Collections](#rule-collections)
|
|
24
|
-
- [
|
|
31
|
+
- [Exported Pre-configured Rule Options](#exported-pre-configured-rule-options)
|
|
25
32
|
- [Custom Plugins](#custom-plugins)
|
|
26
|
-
- [Custom Rules](#custom-rules)
|
|
27
33
|
- [Type Definitions](#type-definitions)
|
|
34
|
+
- [Core Types](#core-types)
|
|
35
|
+
- [Rule Types](#rule-types)
|
|
28
36
|
- [Customization](#customization)
|
|
29
37
|
- [Override Specific Rules](#override-specific-rules)
|
|
30
38
|
- [Use Type-Safe Rule Options](#use-type-safe-rule-options)
|
|
31
39
|
- [Target Specific Files](#target-specific-files)
|
|
32
40
|
- [Troubleshooting](#troubleshooting)
|
|
41
|
+
- [Common Issues](#common-issues)
|
|
42
|
+
- [1. ESLint can't find tsconfig.json](#1-eslint-cant-find-tsconfigjson)
|
|
43
|
+
- [2. Import resolution errors](#2-import-resolution-errors)
|
|
44
|
+
- [3. Performance issues](#3-performance-issues)
|
|
45
|
+
- [Known Limitations](#known-limitations)
|
|
33
46
|
- [Contributing](#contributing)
|
|
34
47
|
- [License](#license)
|
|
35
48
|
|
|
@@ -37,10 +50,9 @@ A comprehensive ESLint configuration package with strongly-typed rule definition
|
|
|
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,11 +63,11 @@ 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 eslint-config-typed
|
|
55
67
|
# or
|
|
56
|
-
yarn add -D eslint-config-typed
|
|
68
|
+
yarn add -D eslint eslint-config-typed
|
|
57
69
|
# or
|
|
58
|
-
pnpm add -D eslint-config-typed
|
|
70
|
+
pnpm add -D eslint eslint-config-typed
|
|
59
71
|
```
|
|
60
72
|
|
|
61
73
|
All required ESLint plugins and dependencies are automatically installed.
|
|
@@ -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
|
-
|
|
198
|
-
const thisDir = import.meta.dirname;
|
|
199
287
|
|
|
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
|
|
@@ -228,98 +316,144 @@ Add the following to `.vscode/settings.json` for proper ESLint integration:
|
|
|
228
316
|
}
|
|
229
317
|
```
|
|
230
318
|
|
|
319
|
+
## Included plugins
|
|
320
|
+
|
|
321
|
+
- "@typescript-eslint/eslint-plugin": "8.46.2"
|
|
322
|
+
- "eslint-plugin-unicorn": "62.0.0"
|
|
323
|
+
- "eslint-plugin-functional": "9.0.2"
|
|
324
|
+
- "eslint-plugin-array-func": "5.1.0"
|
|
325
|
+
- "eslint-plugin-prefer-arrow-functions": "3.9.1"
|
|
326
|
+
- "eslint-plugin-sort-destructure-keys": "^2.0.0"
|
|
327
|
+
- "eslint-plugin-security": "3.0.1"
|
|
328
|
+
- "eslint-plugin-promise": "7.2.1"
|
|
329
|
+
- "eslint-plugin-import": "2.32.0"
|
|
330
|
+
- "eslint-plugin-strict-dependencies": "1.3.27"
|
|
331
|
+
- "eslint-plugin-react": "7.37.5"
|
|
332
|
+
- "eslint-plugin-react-hooks": "7.0.1"
|
|
333
|
+
- "eslint-plugin-react-perf": "3.3.3"
|
|
334
|
+
- "eslint-plugin-react-refresh": "0.4.24"
|
|
335
|
+
- "eslint-plugin-jsx-a11y": "6.10.2"
|
|
336
|
+
- "eslint-plugin-vitest": "0.5.4"
|
|
337
|
+
- "eslint-plugin-jest": "29.0.1"
|
|
338
|
+
- "eslint-plugin-playwright": "2.2.2"
|
|
339
|
+
- "eslint-plugin-cypress": "5.2.0"
|
|
340
|
+
- "eslint-plugin-testing-library": "7.13.3"
|
|
341
|
+
- "eslint-plugin-eslint-plugin": "7.2.0"
|
|
342
|
+
- "eslint-plugin-total-functions" (Reimplemented in this repository to support flat config)
|
|
343
|
+
- "eslint-plugin-tree-shakable" (Reimplemented in this repository to support flat config)
|
|
344
|
+
|
|
231
345
|
## API Reference
|
|
232
346
|
|
|
233
347
|
### Configuration Functions
|
|
234
348
|
|
|
235
349
|
These functions return arrays of ESLint flat configurations:
|
|
236
350
|
|
|
237
|
-
####
|
|
351
|
+
#### Base Configurations
|
|
238
352
|
|
|
239
|
-
- **`
|
|
353
|
+
- **`eslintConfigForTypeScript(options)`** - TypeScript configuration with strict type checking rules
|
|
240
354
|
- `options.tsconfigRootDir`: Root directory containing tsconfig.json
|
|
241
355
|
- `options.tsconfigFileName`: Path to tsconfig.json file
|
|
242
356
|
- `options.packageDirs`: Array of package directories for import resolution
|
|
243
|
-
- **`
|
|
244
|
-
- **`
|
|
245
|
-
- **`eslintFlatConfigForReactBase(options?)`** - Base React configuration without specific framework rules
|
|
357
|
+
- **`eslintConfigForBrowser`** - Browser configuration (Turn off Node.js-specific rules)
|
|
358
|
+
- **`eslintConfigForNodeJs`** - Node.js configuration (Turn off browser-specific rules)
|
|
246
359
|
|
|
247
|
-
####
|
|
360
|
+
#### Framework Configurations
|
|
248
361
|
|
|
249
|
-
- **`
|
|
250
|
-
-
|
|
251
|
-
- **`
|
|
252
|
-
-
|
|
253
|
-
- **`
|
|
362
|
+
- **`eslintConfigForReact(options?)`** - React configuration with hooks and JSX rules
|
|
363
|
+
- `eslintConfigForBrowser` is included in this configuration
|
|
364
|
+
- **`eslintConfigForPreact(options?)`** - Preact configuration (lighter React alternative)
|
|
365
|
+
- `eslintConfigForBrowser` is included in this configuration
|
|
366
|
+
- **`eslintConfigForVitest(options?)`** - Vitest testing framework configuration
|
|
367
|
+
- **`eslintConfigForJest(options?)`** - Jest testing framework configuration
|
|
368
|
+
- **`eslintConfigForTestingLibrary(options?)`** - Testing Library configuration
|
|
369
|
+
- **`eslintConfigForPlaywright(options?)`** - Playwright E2E testing configuration
|
|
370
|
+
- **`eslintConfigForCypress(options?)`** - Cypress E2E testing configuration
|
|
254
371
|
|
|
255
372
|
#### Utility Configurations
|
|
256
373
|
|
|
257
|
-
- **`
|
|
374
|
+
- **`eslintConfigForTypeScriptWithoutRules(options)`** - TypeScript parser & plugins setup without any rules
|
|
258
375
|
|
|
259
376
|
### Rule Collections
|
|
260
377
|
|
|
261
378
|
Pre-configured rule sets that can be imported and customized:
|
|
262
379
|
|
|
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
|
-
|
|
380
|
+
| Rule set | Plugin name | Description |
|
|
381
|
+
| :----------------------------------------- | :------------------------------------- | :----------------------------------- |
|
|
382
|
+
| **`eslintRules`** | (eslint) | Core ESLint rules |
|
|
383
|
+
| **`typescriptEslintRules`** | `@typescript-eslint/eslint-plugin` | TypeScript-specific ESLint rules |
|
|
384
|
+
| **`eslintFunctionalRules`** | `eslint-plugin-functional` | Functional programming style rules |
|
|
385
|
+
| **`eslintTotalFunctionsRules`** | `eslint-plugin-total-functions` | Functional programming style rules |
|
|
386
|
+
| **`eslintUnicornRules`** | `eslint-plugin-unicorn` | Unicorn plugin rules for better code |
|
|
387
|
+
| **`eslintArrayFuncRules`** | `eslint-plugin-array-func` | Array function preference rules |
|
|
388
|
+
| **`eslintPreferArrowFunctionRules`** | `eslint-plugin-prefer-arrow-functions` | Arrow function preference rules |
|
|
389
|
+
| **`eslintPluginSortDestructureKeysRules`** | `eslint-plugin-sort-destructure-keys` | Object destructuring rules |
|
|
390
|
+
| **`eslintPromiseRules`** | `eslint-plugin-promise` | Promise handling rules |
|
|
391
|
+
| **`eslintImportsRules`** | `eslint-plugin-import` | Import/export rules |
|
|
392
|
+
| **`eslintSecurityRules`** | `eslint-plugin-security` | Security best practices |
|
|
393
|
+
| **`eslintTreeShakableRules`** | `eslint-plugin-tree-shakable` | Tree-shaking optimization rules |
|
|
394
|
+
| **`eslintReactRules`** | `eslint-plugin-react` | React-specific rules |
|
|
395
|
+
| **`eslintReactHooksRules`** | `eslint-plugin-react-hooks` | React Hooks rules |
|
|
396
|
+
| **`eslintReactPerfRules`** | `eslint-plugin-react-perf` | React performance optimization rules |
|
|
397
|
+
| **`eslintReactRefreshRules`** | `eslint-plugin-react-refresh` | React Refresh (HMR) rules |
|
|
398
|
+
| **`eslintJsxA11yRules`** | `eslint-plugin-jsx-a11y` | Accessibility rules for JSX |
|
|
399
|
+
| **`eslintVitestRules`** | `eslint-plugin-vitest` | Vitest-specific rules |
|
|
400
|
+
| **`eslintJestRules`** | `eslint-plugin-jest` | Jest-specific rules |
|
|
401
|
+
| **`eslintTestingLibraryRules`** | `eslint-plugin-testing-library` | Testing Library rules |
|
|
402
|
+
| **`eslintPlaywrightRules`** | `eslint-plugin-playwright` | Playwright-specific rules |
|
|
403
|
+
| **`eslintCypressRules`** | `eslint-plugin-cypress` | Cypress-specific rules |
|
|
404
|
+
| **`eslintPluginRules`** | `eslint-plugin-eslint-plugin` | eslint-plugin development rules |
|
|
405
|
+
|
|
406
|
+
### Exported Pre-configured Rule Options
|
|
407
|
+
|
|
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 |
|
|
412
|
+
|
|
413
|
+
You can find other pre-configured rule options by traversing the pre-defined rules object like this:
|
|
414
|
+
|
|
415
|
+
- `typescriptEslintRules['@typescript-eslint/no-restricted-types'][1].types`
|
|
416
|
+
- `eslintRules['no-restricted-syntax'].slice(1)`
|
|
417
|
+
|
|
418
|
+
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
419
|
|
|
298
420
|
### Custom Plugins
|
|
299
421
|
|
|
422
|
+
- **`eslintPluginTotalFunctions`**
|
|
423
|
+
- `eslint-plugin-total-functions` with support for Flat Config
|
|
424
|
+
- **`eslintPluginTreeShakable`**
|
|
425
|
+
- `eslint-plugin-tree-shakable` with support for Flat Config
|
|
300
426
|
- **`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
|
-
|
|
427
|
+
- Currently, this plugin only provides the `custom/no-restricted-syntax` rule (which duplicates ESLint's `no-restricted-syntax` rule).
|
|
428
|
+
- Can be used to set the error level to `error` or `warn` as needed.
|
|
429
|
+
|
|
430
|
+
Example:
|
|
431
|
+
|
|
432
|
+
```js
|
|
433
|
+
import { eslintRules } from 'eslint-config-typed';
|
|
434
|
+
|
|
435
|
+
export default defineConfig([
|
|
436
|
+
// ...
|
|
437
|
+
{
|
|
438
|
+
rules: defineKnownRules({
|
|
439
|
+
'no-restricted-syntax': [
|
|
440
|
+
'warn',
|
|
441
|
+
...eslintRules['no-restricted-syntax'].slice(1),
|
|
442
|
+
],
|
|
443
|
+
'custom/no-restricted-syntax': [
|
|
444
|
+
'error',
|
|
445
|
+
{
|
|
446
|
+
// Restrict import style of React
|
|
447
|
+
selector:
|
|
448
|
+
"ImportDeclaration[source.value='react'][specifiers.0.type!='ImportNamespaceSpecifier']",
|
|
449
|
+
message:
|
|
450
|
+
"React should be imported as `import * as React from 'react'.",
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
}),
|
|
454
|
+
},
|
|
455
|
+
]);
|
|
456
|
+
```
|
|
323
457
|
|
|
324
458
|
### Type Definitions
|
|
325
459
|
|
|
@@ -331,49 +465,56 @@ All rules and configurations come with complete TypeScript type definitions:
|
|
|
331
465
|
- **`ESLintPlugin`** - ESLint plugin type
|
|
332
466
|
- **`Rule`** - ESLint rule definition type
|
|
333
467
|
- **`Rules`** - Collection of rules type
|
|
334
|
-
- **`RestrictedImportsOption`** - Type for restricted imports configuration
|
|
335
468
|
|
|
336
469
|
#### Rule Types
|
|
337
470
|
|
|
338
471
|
Each plugin provides typed rule definitions:
|
|
339
472
|
|
|
340
|
-
-
|
|
341
|
-
- **`
|
|
342
|
-
- **`
|
|
343
|
-
- **`
|
|
344
|
-
- **`
|
|
345
|
-
- **`
|
|
346
|
-
- **`
|
|
347
|
-
- **`
|
|
348
|
-
- **`
|
|
349
|
-
- **`
|
|
350
|
-
- **`
|
|
351
|
-
- **`
|
|
352
|
-
- **`
|
|
353
|
-
- **`
|
|
354
|
-
-
|
|
355
|
-
- **`
|
|
356
|
-
- **`
|
|
357
|
-
- **`
|
|
358
|
-
- **`
|
|
359
|
-
- **`
|
|
360
|
-
-
|
|
361
|
-
- **`
|
|
362
|
-
- **`
|
|
363
|
-
- **`
|
|
473
|
+
- General rules
|
|
474
|
+
- **`EslintRules`** & **`EslintRulesOption`**
|
|
475
|
+
- **`TypeScriptEslintRules`** & **`TypeScriptEslintRulesOption`**
|
|
476
|
+
- **`EslintFunctionalRules`** & **`EslintFunctionalRulesOption`**
|
|
477
|
+
- **`EslintTotalFunctionsRules`** (no options)
|
|
478
|
+
- **`EslintUnicornRules`** & **`EslintUnicornRulesOption`**
|
|
479
|
+
- **`EslintArrayFuncRules`** (no options)
|
|
480
|
+
- **`EslintPreferArrowFunctionRules`** & **`EslintPreferArrowFunctionRulesOption`**
|
|
481
|
+
- **`EslintPluginSortDestructureKeysRules`** & **`EslintPluginSortDestructureKeysRulesOption`**
|
|
482
|
+
- **`EslintPromiseRules`** & **`EslintPromiseRulesOption`**
|
|
483
|
+
- **`EslintImportsRules`** & **`EslintImportsRulesOption`**
|
|
484
|
+
- **`EslintStrictDependenciesRules`** & **`EslintStrictDependenciesRulesOption`**
|
|
485
|
+
- **`EslintSecurityRules`** (no options)
|
|
486
|
+
- **`EslintTreeShakableRules`** (no options)
|
|
487
|
+
- React & JSX
|
|
488
|
+
- **`EslintReactRules`** & **`EslintReactRulesOption`**
|
|
489
|
+
- **`EslintReactHooksRules`** & **`EslintReactHooksRulesOption`**
|
|
490
|
+
- **`EslintReactPerfRules`** & **`EslintReactPerfRulesOption`**
|
|
491
|
+
- **`EslintReactRefreshRules`** & **`EslintReactRefreshRulesOption`**
|
|
492
|
+
- **`EslintJsxA11yRules`** & **`EslintJsxA11yRulesOption`**
|
|
493
|
+
- Testing
|
|
494
|
+
- **`EslintVitestRules`** & **`EslintVitestRulesOption`**
|
|
495
|
+
- **`EslintJestRules`** & **`EslintJestRulesOption`**
|
|
496
|
+
- **`EslintPlaywrightRules`** & **`EslintPlaywrightRulesOption`**
|
|
497
|
+
- **`EslintCypressRules`** & **`EslintCypressRulesOption`**
|
|
498
|
+
- **`EslintTestingLibraryRules`** & **`EslintTestingLibraryRulesOption`**
|
|
499
|
+
- Others
|
|
500
|
+
- **`EslintPluginRules`** & **`EslintPluginRulesOption`**
|
|
364
501
|
|
|
365
502
|
## Customization
|
|
366
503
|
|
|
504
|
+
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.
|
|
505
|
+
|
|
367
506
|
### Override Specific Rules
|
|
368
507
|
|
|
369
508
|
You can override any rule by adding a configuration object after the preset configurations:
|
|
370
509
|
|
|
371
510
|
```js
|
|
372
|
-
|
|
373
|
-
|
|
511
|
+
import { typescriptEslintRules } from 'eslint-config-typed';
|
|
512
|
+
|
|
513
|
+
export default defineConfig([
|
|
514
|
+
...eslintConfigForTypeScript(options),
|
|
374
515
|
{
|
|
375
|
-
rules: {
|
|
376
|
-
// Downgrade to warning
|
|
516
|
+
rules: defineKnownRules({
|
|
517
|
+
// Downgrade to warning (Option settings are inherited)
|
|
377
518
|
'@typescript-eslint/no-explicit-any': 'warn',
|
|
378
519
|
// Disable a rule
|
|
379
520
|
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
|
|
@@ -385,57 +526,86 @@ export default [
|
|
|
385
526
|
allowInFunctions: false,
|
|
386
527
|
},
|
|
387
528
|
],
|
|
388
|
-
|
|
529
|
+
|
|
530
|
+
// Update rule options
|
|
531
|
+
'@typescript-eslint/no-restricted-types': [
|
|
532
|
+
'error',
|
|
533
|
+
{
|
|
534
|
+
types: {
|
|
535
|
+
...typescriptEslintRules[
|
|
536
|
+
'@typescript-eslint/no-restricted-types'
|
|
537
|
+
][1].types,
|
|
538
|
+
Function: "Don't use Function type",
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
}),
|
|
389
543
|
},
|
|
390
|
-
];
|
|
544
|
+
]);
|
|
391
545
|
```
|
|
392
546
|
|
|
393
547
|
### Use Type-Safe Rule Options
|
|
394
548
|
|
|
395
549
|
Leverage TypeScript for type-safe rule configuration:
|
|
396
550
|
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
const noLetOptions = {
|
|
400
|
-
allowInForLoopInit: false,
|
|
401
|
-
allowInFunctions: false,
|
|
402
|
-
};
|
|
551
|
+
```ts
|
|
552
|
+
// configs/restricted-syntax-defs.mjs
|
|
403
553
|
|
|
404
|
-
|
|
405
|
-
|
|
554
|
+
import { eslintRules } from 'eslint-config-typed';
|
|
555
|
+
|
|
556
|
+
/** @type {import("eslint-config-typed").EslintRulesOption["no-restricted-syntax"]} */
|
|
557
|
+
export const restrictedSyntax = [
|
|
558
|
+
...eslintRules['no-restricted-syntax'].slice(1),
|
|
406
559
|
{
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
560
|
+
// Restrict type annotation style for React.useMemo
|
|
561
|
+
selector:
|
|
562
|
+
"TSTypeAnnotation[parent.parent.type='CallExpression'][parent.parent.callee.object.name='React'][parent.parent.callee.property.name='useMemo']",
|
|
563
|
+
message:
|
|
564
|
+
'The variable type T should be annotated as `React.useMemo<T>` or `const v: T = React.useMemo(...)`.',
|
|
410
565
|
},
|
|
411
566
|
];
|
|
412
567
|
```
|
|
413
568
|
|
|
569
|
+
```ts
|
|
570
|
+
// eslint.config.js
|
|
571
|
+
|
|
572
|
+
import { restrictedSyntax } from './configs/restricted-syntax-defs.mjs';
|
|
573
|
+
|
|
574
|
+
export default defineConfig([
|
|
575
|
+
...eslintConfigForTypeScript(options),
|
|
576
|
+
{
|
|
577
|
+
rules: defineKnownRules({
|
|
578
|
+
'no-restricted-syntax': ['error', restrictedSyntax],
|
|
579
|
+
}),
|
|
580
|
+
},
|
|
581
|
+
]);
|
|
582
|
+
```
|
|
583
|
+
|
|
414
584
|
### Target Specific Files
|
|
415
585
|
|
|
416
586
|
Apply different rules to different file patterns:
|
|
417
587
|
|
|
418
588
|
```js
|
|
419
|
-
export default [
|
|
420
|
-
...
|
|
589
|
+
export default defineConfig([
|
|
590
|
+
...eslintConfigForTypeScript(options),
|
|
421
591
|
{
|
|
422
592
|
files: ['**/*.test.ts', '**/*.spec.ts'],
|
|
423
|
-
rules: {
|
|
593
|
+
rules: defineKnownRules({
|
|
424
594
|
// Allow any in tests
|
|
425
595
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
426
596
|
// Allow console in tests
|
|
427
597
|
'no-console': 'off',
|
|
428
|
-
},
|
|
598
|
+
}),
|
|
429
599
|
},
|
|
430
600
|
{
|
|
431
|
-
files: ['
|
|
432
|
-
rules: {
|
|
601
|
+
files: ['scripts/**/*.ts'],
|
|
602
|
+
rules: defineKnownRules({
|
|
433
603
|
// Allow console in scripts
|
|
434
|
-
'no-
|
|
435
|
-
'no-
|
|
436
|
-
},
|
|
604
|
+
'no-await-in-loop': 'off',
|
|
605
|
+
'import/no-unassigned-import': 'off',
|
|
606
|
+
}),
|
|
437
607
|
},
|
|
438
|
-
];
|
|
608
|
+
]);
|
|
439
609
|
```
|
|
440
610
|
|
|
441
611
|
## Troubleshooting
|
|
@@ -449,11 +619,13 @@ Ensure the paths are correct:
|
|
|
449
619
|
```js
|
|
450
620
|
const thisDir = import.meta.dirname;
|
|
451
621
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
622
|
+
export default defineConfig([
|
|
623
|
+
...eslintConfigForTypeScript({
|
|
624
|
+
tsconfigRootDir: thisDir, // Must be absolute path
|
|
625
|
+
tsconfigFileName: './tsconfig.json', // Relative to tsconfigRootDir
|
|
626
|
+
packageDirs: [thisDir],
|
|
627
|
+
}),
|
|
628
|
+
]);
|
|
457
629
|
```
|
|
458
630
|
|
|
459
631
|
#### 2. Import resolution errors
|
|
@@ -461,24 +633,25 @@ const thisDir = import.meta.dirname;
|
|
|
461
633
|
The `packageDirs` option helps ESLint resolve imports correctly in monorepos:
|
|
462
634
|
|
|
463
635
|
```js
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
636
|
+
export default defineConfig([
|
|
637
|
+
...eslintConfigForTypeScript({
|
|
638
|
+
tsconfigRootDir: thisDir,
|
|
639
|
+
tsconfigFileName: './tsconfig.json',
|
|
640
|
+
packageDirs: [
|
|
641
|
+
path.resolve(thisDir, '../../..'), // Monorepo root
|
|
642
|
+
thisDir, // Current package
|
|
643
|
+
],
|
|
644
|
+
}),
|
|
645
|
+
]);
|
|
472
646
|
```
|
|
473
647
|
|
|
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
|
|
648
|
+
#### 3. Performance issues
|
|
479
649
|
|
|
480
650
|
For large projects, consider:
|
|
481
651
|
|
|
652
|
+
- Using `TIMING=1 eslint` to identify heavy rules
|
|
653
|
+
- Using `NODE_OPTIONS='--max-old-space-size=<memory-size-MB>' eslint` to increase the maximum memory available
|
|
654
|
+
- Separate heavy rules into a separate config and prepare a dedicated command
|
|
482
655
|
- Using `.eslintignore` or `ignores` patterns to skip generated files
|
|
483
656
|
- Running ESLint with `--cache` flag
|
|
484
657
|
- Limiting the scope of type-aware rules
|
|
@@ -500,8 +673,3 @@ Contributions are welcome! Please check our [GitHub repository](https://github.c
|
|
|
500
673
|
## License
|
|
501
674
|
|
|
502
675
|
This project is licensed under the [Apache License 2.0](./LICENSE).
|
|
503
|
-
|
|
504
|
-
## Future Updates
|
|
505
|
-
|
|
506
|
-
- Enhanced support for `eslint-plugin-functional`
|
|
507
|
-
- Migration from `functional/prefer-readonly-type` to `functional/prefer-immutable-types` and `functional/type-declaration-immutability`
|