@tim-code/eslint-config 2.0.2 → 2.0.4

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
@@ -1,22 +1,18 @@
1
1
  # eslint-config
2
2
 
3
- `npm install --save-dev @tim-code/eslint-config`
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
- Then in package.json:
5
+ Version 2.X.X of this package only supports ESLint 9 (flat config). Use 1.4.X if you are using ESLint 8.
6
6
 
7
- ```json
8
- "eslintConfig": {
9
- "extends": [
10
- "@tim-code"
11
- ],
12
- "root": true,
13
- "ignorePatterns": []
14
- }
15
- ```
7
+ ## Install
8
+
9
+ `npm install --save-dev @tim-code/eslint-config`
16
10
 
17
- This assumes that code can use Node globals unless it is in a `frontend` directory. See below to change this.
11
+ Then create `eslint.config.js` at project root with the following:
18
12
 
19
- Note that `root` and `ignorePatterns` are not required but `root` is useful to prevent ESLint from searching for more config files and `ignorePatterns` is often eventually needed to ignore files such as a build directory.
13
+ ```js
14
+ export { default } from "@tim-code/eslint-config"
15
+ ```
20
16
 
21
17
  ## React
22
18
 
@@ -24,72 +20,44 @@ To fully support React/JSX, install:
24
20
 
25
21
  `npm install --save-dev eslint-plugin-react`
26
22
 
27
- Then in `eslintConfig` in package.json:
23
+ Then in `eslint.config.js` in package.json:
28
24
 
29
- ```json
30
- "extends": [
31
- "@tim-code",
32
- "plugin:react/recommended"
33
- ]
34
- ```
25
+ ```js
26
+ import base from "@tim-code/eslint-config"
27
+ import reactPlugin from "eslint-plugin-react"
28
+ import { defineConfig } from "eslint/config"
35
29
 
36
- Because `null` is often used in React code, you may want to disable the warning about `null`:
37
-
38
- ```json
39
- "rules": [
40
- "no-restricted-syntax": "off"
41
- ]
30
+ export default defineConfig([
31
+ reactPlugin.configs.flat.recommended,
32
+ ...base,
33
+ // optionally, allow null in React code
34
+ {
35
+ files: ["**/*.{jsx,tsx}"],
36
+ rules: { "no-restricted-syntax": "off" },
37
+ },
38
+ ])
42
39
  ```
43
40
 
44
41
  ## Make src directory use "browser" globals instead of "node" globals
45
42
 
46
- In `eslintConfig` in package.json:
43
+ In `eslint.config.js` in package.json:
47
44
 
48
- ```json
49
- "overrides": [
45
+ ```js
46
+ export default defineConfig([
47
+ ...base,
50
48
  {
51
- "files": [
52
- "src/**"
53
- ],
54
- "env": {
55
- "node": false,
56
- "browser": true
57
- }
58
- }
59
- ]
60
- ```
61
-
62
- Instead, if there are no JS files in the project directory that require Node:
63
-
64
- ```json
65
- "env": {
66
- "node": false,
67
- "browser": true
68
- }
49
+ files: ["src/**"],
50
+ languageOptions: {
51
+ globals: {
52
+ ...globals.browser,
53
+ // to turn off previously added Node globals:
54
+ ...Object.fromEntries(Object.keys(globals.node).map((key) => [key, "off"])),
55
+ },
56
+ },
57
+ },
58
+ ])
69
59
  ```
70
60
 
71
61
  ## Why not eslint-babel?
72
62
 
73
63
  `eslint-babel` is a more flexible parser but using it is a bit more complex (requires configuration) and introduces another dependency.
74
-
75
- ## ESLint 9
76
-
77
- ESLint 9, released 2024-04-05, switched to using "flat config". This enabled a more script-based integration with plugins (similar to other build tools like Webpack) at the expense of supporting different ways to specify the config as a JSON object. As a result, ESLint 9 dropped support for "eslintConfig" in package.json. See: https://github.com/eslint/eslint/discussions/18131.
78
-
79
- ESLint 8 reached end-of-life on 2024-10-05. The last 8.X.X release was 2024-09-16. How should projects that followed this README migrate to ESLint 9?
80
-
81
- ### Option 1 - Create an eslint.config.js
82
-
83
- It's intended that projects that use ESLint 9 will have their own `eslint.config.js` file, even if they are ultimately just using some other ESLint config. See: https://eslint.org/docs/latest/use/getting-started.
84
-
85
- This does result in cluttering the top-level of the project with yet-another config file.
86
-
87
- ### Option 2 - Disable Flat Config
88
-
89
- It is possible to use old config resolution by setting the environment variable, `ESLINT_USE_FLAT_CONFIG=false`, or when using VSCode ESLint extension, `{ "eslint.useFlatConfig": false }`. At first glance, it seems like this provides a way forward: old repos can use ESLint 9 without rewriting their configs. Unfortunately, this has a significant drawback. Setting this at a user-level scope in VSCode will result in not being able to use flat config in all open projects. This is because when this is false, flat config is completely ignored. Basically, it's impossible to work in some repos that are using ESLint 9 with legacy config and some repos that are using ESLint 9 with flat config, without repo-level overrides.
90
-
91
- A better approach would be for repos that want to use ESLint 9 with legacy config to specify `.vscode/settings.json`. However, if a repo doesn't have that file already, this still amounts to the same as Option 1: adding a config file at the top-level of the project.
92
-
93
- ### Other Options?
94
-
95
- Purposefully so, there are less ways to specify ESLint config in ESLint 9. You could try to pass a command line argument specifying a different config file. However, the VSCode extension doesn't run ESLint through the command line, so you would have to specify it through preferences, similar to Option 2.
package/eslint.config.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import js from "@eslint/js"
2
2
  import prettierConfig from "eslint-config-prettier/flat"
3
3
  import importPlugin from "eslint-plugin-import"
4
- import { defineConfig } from "eslint/config"
4
+ import { defineConfig, globalIgnores } from "eslint/config"
5
5
  import globals from "globals"
6
6
 
7
7
  export default defineConfig([
8
+ globalIgnores(["dist/**", "dist-old/**", ".aws-sam"]),
8
9
  // base: ESLint core + prettier + import/recommended
9
10
  js.configs.all,
10
11
  prettierConfig,
11
12
  importPlugin.flatConfigs.recommended,
12
13
  {
13
14
  files: ["**/*.{js,mjs,cjs,jsx,ts,tsx}"],
14
- ignores: ["dist/**", "dist-old/**"],
15
15
 
16
16
  languageOptions: {
17
17
  // es6 seems to be needed for Promise
@@ -165,6 +165,7 @@ export default defineConfig([
165
165
  files: ["**/frontend/**"],
166
166
  languageOptions: {
167
167
  globals: {
168
+ ...Object.fromEntries(Object.keys(globals.node).map((key) => [key, "off"])),
168
169
  ...globals.browser,
169
170
  },
170
171
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tim-code/eslint-config",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "eslint.config.js",