@tim-code/eslint-config 3.0.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 CHANGED
@@ -4,6 +4,10 @@ This config assumes that code can use Node globals unless it is in a `frontend`
4
4
 
5
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
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.
10
+
7
11
  ## Install
8
12
 
9
13
  `npm install --save-dev @tim-code/eslint-config`
@@ -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,8 +1,14 @@
1
1
  import js from "@eslint/js"
2
+ import vitest from "@vitest/eslint-plugin"
2
3
  import prettierConfig from "eslint-config-prettier/flat"
3
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"]),
@@ -39,6 +45,16 @@ export default defineConfig([
39
45
  "import-x/namespace": "off",
40
46
  "import-x/no-named-as-default-member": "off",
41
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
+ ],
42
58
 
43
59
  // functions that return JSX seem to trigger this but the functions aren't necessarily components themselves
44
60
  "react/display-name": "off",
@@ -97,6 +113,8 @@ export default defineConfig([
97
113
  // when writing such comments during brainstorming, just disable the rule
98
114
  // most of the time, want to discourage non-JSDoc block style comments in production
99
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"],
100
118
  // unfortunately can't allow "after-used" for destructuring array
101
119
  // "no-unused-vars": ["error", { ignoreRestSiblings: true }],
102
120
 
@@ -142,19 +160,19 @@ export default defineConfig([
142
160
  "require-atomic-updates": "off", // variables can change unexpectedly in parallelism due to another thread... this rule is way too noisy though
143
161
  },
144
162
  },
145
- // Jest/test overrides
163
+ // Test overrides (Vitest assumed; works for Jest as well but no globals)
146
164
  {
147
165
  files: ["**/*.test.*", "**/*.spec.*", "**/test/**"],
148
- languageOptions: {
149
- globals: {
150
- ...globals.jest,
151
- },
152
- },
166
+ plugins: { vitest },
153
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
154
172
  "max-lines": "off", // test files should not be split up based on length
155
173
  "max-lines-per-function": "off", // describe blocks can be quite long; doesn't make sense to split up
156
- "no-restricted-syntax": "off", // allow null in tests
157
- "require-unicode-regexp": "off", // regexes are pretty common in Jest; useless rule but annoying
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
158
176
  },
159
177
  },
160
178
  // frontend/browser overrides
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-code/eslint-config",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "eslint.config.js",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "peerDependencies": {
14
14
  "@eslint/js": ">=10",
15
+ "@vitest/eslint-plugin": ">=1.6",
15
16
  "eslint": ">=10",
16
17
  "eslint-plugin-import-x": ">=4"
17
18
  },