@tim-code/eslint-config 2.1.0 → 3.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 +11 -1
- package/eslint.config.js +33 -24
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
This config assumes that code can use Node globals unless it is in a `frontend` directory. See below to change this.
|
|
4
4
|
|
|
5
|
-
Version
|
|
5
|
+
Version 3.X.X of this package requires ESLint 10+ (flat config) and `eslint-plugin-import-x` as a peer dependency (replacing `eslint-plugin-import`). Use 2.1.X if you need ESLint 9 support, or 1.4.X if you are using ESLint 8.
|
|
6
|
+
|
|
7
|
+
Version 3.1.X requires `@vitest/eslint-plugin`, which installs `@typescript-eslint/utils`. This version assumes Vitest is used instead of Jest since it drops support for Jest globals.
|
|
8
|
+
|
|
9
|
+
This config makes use of `no-restricted-imports` and `no-restricted-syntax` rules. If another project implements these, they will overwrite this library's functionality.
|
|
6
10
|
|
|
7
11
|
## Install
|
|
8
12
|
|
|
@@ -14,6 +18,12 @@ Then create `eslint.config.js` at project root with the following:
|
|
|
14
18
|
export { default } from "@tim-code/eslint-config"
|
|
15
19
|
```
|
|
16
20
|
|
|
21
|
+
## Tests
|
|
22
|
+
|
|
23
|
+
Test files (`*.test.*`, `*.spec.*` and anything under `test/`) are linted with `@vitest/eslint-plugin`. The rules also generally can work for Jest tests since the APIs match (however, no Jest globals support).
|
|
24
|
+
|
|
25
|
+
Test files may use `null` and `{}`, and have no file or function length limits.
|
|
26
|
+
|
|
17
27
|
## React
|
|
18
28
|
|
|
19
29
|
To fully support React/JSX, install:
|
package/eslint.config.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import js from "@eslint/js"
|
|
2
|
+
import vitest from "@vitest/eslint-plugin"
|
|
2
3
|
import prettierConfig from "eslint-config-prettier/flat"
|
|
3
|
-
import
|
|
4
|
+
import { importX } from "eslint-plugin-import-x"
|
|
4
5
|
import { defineConfig, globalIgnores } from "eslint/config"
|
|
5
6
|
import globals from "globals"
|
|
7
|
+
import { builtinModules } from "node:module"
|
|
8
|
+
|
|
9
|
+
const nodeBuiltins = builtinModules.filter(
|
|
10
|
+
(name) => !name.startsWith("_") && !name.startsWith("node:")
|
|
11
|
+
)
|
|
6
12
|
|
|
7
13
|
export default defineConfig([
|
|
8
14
|
globalIgnores(["dist/**", "dist-old/**", ".aws-sam"]),
|
|
9
|
-
// base: ESLint core + prettier + import/recommended
|
|
15
|
+
// base: ESLint core + prettier + import-x/recommended
|
|
10
16
|
js.configs.all,
|
|
11
17
|
prettierConfig,
|
|
12
|
-
|
|
18
|
+
importX.flatConfigs.recommended,
|
|
13
19
|
{
|
|
14
20
|
files: ["**/*.{js,mjs,cjs,jsx,ts,tsx}"],
|
|
15
21
|
|
|
@@ -32,22 +38,23 @@ export default defineConfig([
|
|
|
32
38
|
reportUnusedDisableDirectives: true,
|
|
33
39
|
},
|
|
34
40
|
|
|
35
|
-
settings: {
|
|
36
|
-
"import/resolver": {
|
|
37
|
-
// default resolver provided by eslint-plugin-import
|
|
38
|
-
node: {},
|
|
39
|
-
// "eslint-import-resolver-exports" plugin
|
|
40
|
-
exports: {},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
|
|
44
41
|
rules: {
|
|
45
42
|
// .js extension needed for relative imports
|
|
46
|
-
"import/extensions": ["error", "ignorePackages"],
|
|
43
|
+
"import-x/extensions": ["error", "ignorePackages"],
|
|
47
44
|
// these rules have poor performance:
|
|
48
|
-
"import/namespace": "off",
|
|
49
|
-
"import/no-named-as-default-member": "off",
|
|
50
|
-
"import/no-named-as-default": "off",
|
|
45
|
+
"import-x/namespace": "off",
|
|
46
|
+
"import-x/no-named-as-default-member": "off",
|
|
47
|
+
"import-x/no-named-as-default": "off",
|
|
48
|
+
// "node:" makes it clear the import is a Node built-in rather than a package
|
|
49
|
+
"no-restricted-imports": [
|
|
50
|
+
"error",
|
|
51
|
+
{
|
|
52
|
+
paths: nodeBuiltins.map((name) => ({
|
|
53
|
+
name,
|
|
54
|
+
message: `Use "node:${name}" instead`,
|
|
55
|
+
})),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
51
58
|
|
|
52
59
|
// functions that return JSX seem to trigger this but the functions aren't necessarily components themselves
|
|
53
60
|
"react/display-name": "off",
|
|
@@ -106,6 +113,8 @@ export default defineConfig([
|
|
|
106
113
|
// when writing such comments during brainstorming, just disable the rule
|
|
107
114
|
// most of the time, want to discourage non-JSDoc block style comments in production
|
|
108
115
|
"multiline-comment-style": ["error", "separate-lines"],
|
|
116
|
+
// eslint-config-prettier turns this off, but "all" never conflicts with Prettier; always use braces
|
|
117
|
+
curly: ["error", "all"],
|
|
109
118
|
// unfortunately can't allow "after-used" for destructuring array
|
|
110
119
|
// "no-unused-vars": ["error", { ignoreRestSiblings: true }],
|
|
111
120
|
|
|
@@ -151,19 +160,19 @@ export default defineConfig([
|
|
|
151
160
|
"require-atomic-updates": "off", // variables can change unexpectedly in parallelism due to another thread... this rule is way too noisy though
|
|
152
161
|
},
|
|
153
162
|
},
|
|
154
|
-
// Jest
|
|
163
|
+
// Test overrides (Vitest assumed; works for Jest as well but no globals)
|
|
155
164
|
{
|
|
156
165
|
files: ["**/*.test.*", "**/*.spec.*", "**/test/**"],
|
|
157
|
-
|
|
158
|
-
globals: {
|
|
159
|
-
...globals.jest,
|
|
160
|
-
},
|
|
161
|
-
},
|
|
166
|
+
plugins: { vitest },
|
|
162
167
|
rules: {
|
|
168
|
+
// catches focused tests (.only), duplicate titles, expects outside of tests, etc.
|
|
169
|
+
...vitest.configs.recommended.rules,
|
|
170
|
+
"vitest/consistent-test-it": ["error", { fn: "it" }], // don't allow both test() and it()
|
|
171
|
+
"vitest/require-to-throw-message": "error", // force toThrow() to check error message
|
|
163
172
|
"max-lines": "off", // test files should not be split up based on length
|
|
164
173
|
"max-lines-per-function": "off", // describe blocks can be quite long; doesn't make sense to split up
|
|
165
|
-
"no-restricted-syntax": "off", // allow null in tests
|
|
166
|
-
"require-unicode-regexp": "off", // regexes are pretty common in
|
|
174
|
+
"no-restricted-syntax": "off", // allow null and {} in tests
|
|
175
|
+
"require-unicode-regexp": "off", // regexes are pretty common in tests; useless rule but annoying
|
|
167
176
|
},
|
|
168
177
|
},
|
|
169
178
|
// frontend/browser overrides
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tim-code/eslint-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "eslint.config.js",
|
|
@@ -8,11 +8,13 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"eslint-config-prettier": ">=10",
|
|
11
|
-
"
|
|
11
|
+
"globals": ">=14"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"eslint": ">=
|
|
15
|
-
"eslint-plugin
|
|
14
|
+
"@eslint/js": ">=10",
|
|
15
|
+
"@vitest/eslint-plugin": ">=1.6",
|
|
16
|
+
"eslint": ">=10",
|
|
17
|
+
"eslint-plugin-import-x": ">=4"
|
|
16
18
|
},
|
|
17
19
|
"publishConfig": {
|
|
18
20
|
"access": "public"
|