@tim-code/eslint-config 1.4.0 → 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 CHANGED
@@ -71,3 +71,25 @@ Instead, if there are no JS files in the project directory that require Node:
71
71
  ## Why not eslint-babel?
72
72
 
73
73
  `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.
@@ -0,0 +1,171 @@
1
+ import js from "@eslint/js"
2
+ import prettierConfig from "eslint-config-prettier/flat"
3
+ import importPlugin from "eslint-plugin-import"
4
+ import globals from "globals"
5
+
6
+ /** @type {import("eslint").Linter.FlatConfig[]} */
7
+ export default [
8
+ // base: ESLint core + prettier + import/recommended
9
+ js.configs.all,
10
+ prettierConfig,
11
+ importPlugin.flatConfigs.recommended,
12
+ {
13
+ files: ["**/*.{js,mjs,cjs,jsx,ts,tsx}"],
14
+
15
+ languageOptions: {
16
+ // es6 seems to be needed for Promise
17
+ ecmaVersion: 2022,
18
+ sourceType: "module",
19
+ parserOptions: {
20
+ ecmaFeatures: {
21
+ jsx: true, // enable JSX parsing everywhere
22
+ },
23
+ },
24
+ globals: {
25
+ ...globals.nodeBuiltin,
26
+ ...globals.es2021,
27
+ },
28
+ },
29
+
30
+ linterOptions: {
31
+ reportUnusedDisableDirectives: true,
32
+ },
33
+
34
+ settings: {
35
+ "import/resolver": {
36
+ // default resolver provided by eslint-plugin-import
37
+ node: {},
38
+ // "eslint-import-resolver-exports" plugin
39
+ exports: {},
40
+ },
41
+ },
42
+
43
+ rules: {
44
+ // .js extension needed for relative imports
45
+ "import/extensions": ["error", "ignorePackages"],
46
+ // these rules have poor performance:
47
+ "import/namespace": "off",
48
+ "import/no-named-as-default-member": "off",
49
+ "import/no-named-as-default": "off",
50
+
51
+ // functions that return JSX seem to trigger this but the functions aren't necessarily components themselves
52
+ "react/display-name": "off",
53
+ // much easier to read some punctuation such as " and ' versus the escaped forms " and '
54
+ "react/no-unescaped-entities": "off",
55
+ // prop types is not necessary
56
+ "react/prop-types": "off",
57
+ // requiring React is no longer necessary
58
+ "react/react-in-jsx-scope": "off",
59
+
60
+ // null should be avoided entirely if possible
61
+ "no-restricted-syntax": [
62
+ "error",
63
+ {
64
+ selector:
65
+ ":not(BinaryExpression:matches([operator='!=='],[operator='===']), CallExpression[callee.object.name='Object'][callee.property.name='create']) > Literal[value=null]",
66
+ message:
67
+ 'Usage of "null" is discouraged except when used because of legacy APIs; use "undefined" instead',
68
+ },
69
+ ],
70
+
71
+ // modified rules
72
+ // four parameter functions seem more reasonable than three
73
+ "max-params": ["error", 4],
74
+ // sometimes need to pass an empty function as a callback
75
+ "no-empty-function": ["error", { allow: ["arrowFunctions"] }],
76
+ // function keyword is more readable in general but "fat arrow" is more concise; disables function(){} syntax
77
+ "func-style": ["error", "declaration", { allowArrowFunctions: true }],
78
+ // default is 50 lines which is sometimes limiting with Prettier's formatting (parameter destructuring can take up 10 lines for example)
79
+ // adding comments or blanks should not trigger this warning
80
+ // doubled from 75 to allow almost all usages in pluto where it was commonly disabled
81
+ // it is common in Jest tests to trigger this; going to up further to see if that helps, already questionably useful
82
+ "max-lines-per-function": [
83
+ "error",
84
+ { max: 200, skipBlankLines: true, skipComments: true },
85
+ ],
86
+ // allow mix of reassigned and const variables
87
+ "prefer-const": ["error", { destructuring: "all" }],
88
+ // never allow "yoda" conditions except for range
89
+ yoda: ["error", "never", { exceptRange: true }],
90
+ // unclear why assignment expressions cannot be used
91
+ "prefer-destructuring": ["error", { AssignmentExpression: { array: false } }],
92
+ // 300 lines is too low
93
+ "max-lines": ["error", { max: 600 }],
94
+ // allow bracket notation for capitalized keys, which are more likely to correlate with an object being used as a map
95
+ "dot-notation": ["error", { allowPattern: "^[A-Z]" }],
96
+ // multi assign is confusing with declarations but non-declarations are okay
97
+ "no-multi-assign": ["error", { ignoreNonDeclaration: true }],
98
+ // although using block style comments is easiest for writing a paragraph, JSDoc is usually preferred
99
+ // when writing such comments during brainstorming, just disable the rule
100
+ // most of the time, want to discourage non-JSDoc block style comments in production
101
+ "multiline-comment-style": ["error", "separate-lines"],
102
+ // unfortunately can't allow "after-used" for destructuring array
103
+ // "no-unused-vars": ["error", { ignoreRestSiblings: true }],
104
+
105
+ // unsure
106
+ "no-labels": "off", // useful to be able to break/continue an outer loop; otherwise have to write more code
107
+ "no-nested-ternary": "off", // ideally would allow just two levels of nesting; saves quite a bit of code
108
+
109
+ // rule is too idealistic
110
+ camelcase: "off", // useful to allow non-camel case for compatibility like destructuring JSON
111
+ "sort-keys": "off", // too burdensome; doesn't affect order of destructured properties i.e. ({b, a}) => ({a, b}) would be fine
112
+ "sort-vars": "off", // let results, index
113
+ "no-param-reassign": "off", // a common pattern is to coerce parameters; noisy to rename parameters slightly differently
114
+ "no-magic-numbers": "off", // does not allow 1, 2, -1; also sometimes noisy to name every constant (for example in time calculations)
115
+ "id-length": "off", // single character variables can sometimes be useful: i, j, x, y, $, _
116
+ "no-plusplus": "off", // ++ is too common of a language feature (C++)
117
+ "no-underscore-dangle": "off", // difficult to come up with other names for named default parameters
118
+ "max-statements": "off", // max 10 statements is way too low; unclear why number of statements is a good measurement
119
+ "class-methods-use-this": "off", // allow a static method to be called like an instance method
120
+ "arrow-body-style": "off", // does not allow braces to be used with a multi-line fat arrow expression
121
+
122
+ // rule conflicts with another tool
123
+ "one-var": "off", // with Prettier, comma appears on the same line as declaration, making code less readable
124
+ "sort-imports": "off", // rely on IDE to sort imports; IDE sorts capitalizations differently than eslint expects
125
+ "new-cap": "off", // React functions can begin with capital letter
126
+
127
+ // bad rules
128
+ "init-declarations": "off", // doesn't make sense for let and subsequent assignment in if/else; const implies this rule anyway
129
+ "no-ternary": "off", // ternary is a useful language feature
130
+ "no-undefined": "off", // actually undefined should be used over null
131
+ "capitalized-comments": "off", // comments are not always sentences
132
+ "prefer-named-capture-group": "off", // named capture groups are too new
133
+ "no-continue": "off", // continue is a useful language feature
134
+ "no-inline-comments": "off", // not adhered to in this file for example
135
+ "line-comment-position": "off", // relates to above rule
136
+ "no-loop-func": "off", // this is only a concern with var declarations
137
+ "max-classes-per-file": "off", // one class per file discourages small classes
138
+ "lines-between-class-members": "off", // discourages smaller classes
139
+ "guard-for-in": "off", // warning about language feature; reasons to avoid it are too theoretical: works fine in nearly all cases
140
+
141
+ // disabled too often
142
+ "no-console": "off", // console error was already allowed; when is console.log actually bad?
143
+ "no-await-in-loop": "off", // warning about language feature, unavoidable
144
+ "require-atomic-updates": "off", // variables can change unexpectedly in parallelism due to another thread... this rule is way too noisy though
145
+ },
146
+ },
147
+ // Jest/test overrides
148
+ {
149
+ files: ["**/*.test.*", "**/*.spec.*", "**/test/**"],
150
+ languageOptions: {
151
+ globals: {
152
+ ...globals.jest,
153
+ },
154
+ },
155
+ rules: {
156
+ "max-lines": "off", // test files should not be split up based on length
157
+ "max-lines-per-function": "off", // describe blocks can be quite long; doesn't make sense to split up
158
+ "no-restricted-syntax": "off", // allow null in tests
159
+ "require-unicode-regexp": "off", // regexes are pretty common in Jest; useless rule but annoying
160
+ },
161
+ },
162
+ // frontend/browser overrides
163
+ {
164
+ files: ["**/frontend/**"],
165
+ languageOptions: {
166
+ globals: {
167
+ ...globals.browser,
168
+ },
169
+ },
170
+ },
171
+ ]
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@tim-code/eslint-config",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
- "main": ".eslintrc.js",
5
+ "main": "eslint.config.js",
6
6
  "author": "",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "eslint-config-prettier": ">= 9",
9
+ "eslint-config-prettier": ">=10",
10
10
  "eslint-import-resolver-exports": "^1.0.0-beta.5"
11
11
  },
12
12
  "peerDependencies": {
13
- "eslint": ">=8 <9",
14
- "eslint-plugin-import": ">= 2"
13
+ "eslint": ">=9",
14
+ "eslint-plugin-import": ">=2"
15
15
  },
16
16
  "publishConfig": {
17
17
  "access": "public"
package/.eslintrc.js DELETED
@@ -1,148 +0,0 @@
1
- module.exports = {
2
- env: {
3
- // es6 seems to be needed for Promise
4
- es6: true,
5
- node: true,
6
- },
7
- root: true,
8
- parserOptions: {
9
- ecmaVersion: 2022,
10
- sourceType: "module",
11
- ecmaFeatures: {
12
- jsx: true,
13
- },
14
- },
15
- reportUnusedDisableDirectives: true,
16
- extends: ["eslint:all", "prettier", "plugin:import/recommended"],
17
- overrides: [
18
- {
19
- files: ["**/*.test.*", "**/*.spec.*", "**/test/**"],
20
- env: {
21
- jest: true,
22
- },
23
- rules: {
24
- "max-lines": "off", // test files should not be split up based on length
25
- "max-lines-per-function": "off", // describe blocks can be quite long; doesn't make sense to split up
26
- "no-restricted-syntax": "off", // allow null in tests
27
- "require-unicode-regexp": "off", // regexes are pretty common in Jest; useless rule but annoying
28
- },
29
- },
30
- {
31
- files: ["**/frontend/**"],
32
- env: {
33
- browser: true,
34
- },
35
- },
36
- ],
37
- settings: {
38
- "import/resolver": {
39
- // default resolver provided by eslint-plugin-import
40
- node: {},
41
- // "eslint-import-resolver-exports" plugin
42
- exports: {},
43
- },
44
- },
45
- rules: {
46
- // .js extension needed for relative imports
47
- "import/extensions": ["error", "ignorePackages"],
48
- // these rules have poor performance:
49
- "import/namespace": "off",
50
- "import/no-named-as-default-member": "off",
51
- "import/no-named-as-default": "off",
52
-
53
- // functions that return JSX seem to trigger this but the functions aren't necessarily components themselves
54
- "react/display-name": "off",
55
- // much easier to read some punctuation such as " and ' versus the escaped forms &quot; and &apos;
56
- "react/no-unescaped-entities": "off",
57
- // prop types is not necessary
58
- "react/prop-types": "off",
59
- // requiring React is no longer necessary
60
- "react/react-in-jsx-scope": "off",
61
-
62
- // null should be avoided entirely if possible
63
- "no-restricted-syntax": [
64
- "error",
65
- {
66
- selector:
67
- ":not(BinaryExpression:matches([operator='!=='],[operator='===']), CallExpression[callee.object.name='Object'][callee.property.name='create']) > Literal[value=null]",
68
- message:
69
- 'Usage of "null" is discouraged except when used because of legacy APIs; use "undefined" instead',
70
- },
71
- ],
72
-
73
- // modified rules
74
- // four parameter functions seem more reasonable than three
75
- "max-params": ["error", 4],
76
- // sometimes need to pass an empty function as a callback
77
- "no-empty-function": ["error", { allow: ["arrowFunctions"] }],
78
- // function keyword is more readable in general but "fat arrow" is more concise; disables function(){} syntax
79
- "func-style": ["error", "declaration", { allowArrowFunctions: true }],
80
- // default is 50 lines which is sometimes limiting with Prettier's formatting (parameter destructuring can take up 10 lines for example)
81
- // adding comments or blanks should not trigger this warning
82
- // doubled from 75 to allow almost all usages in pluto where it was commonly disabled
83
- // it is common in Jest tests to trigger this; going to up further to see if that helps, already questionably useful
84
- "max-lines-per-function": [
85
- "error",
86
- { max: 200, skipBlankLines: true, skipComments: true },
87
- ],
88
- // allow mix of reassigned and const variables
89
- "prefer-const": ["error", { destructuring: "all" }],
90
- // never allow "yoda" conditions except for range
91
- yoda: ["error", "never", { exceptRange: true }],
92
- // unclear why assignment expressions cannot be used
93
- "prefer-destructuring": ["error", { AssignmentExpression: { array: false } }],
94
- // 300 lines is too low
95
- "max-lines": ["error", { max: 600 }],
96
- // allow bracket notation for capitalized keys, which are more likely to correlate with an object being used as a map
97
- "dot-notation": ["error", { allowPattern: "^[A-Z]" }],
98
- // multi assign is confusing with declarations but non-declarations are okay
99
- "no-multi-assign": ["error", { ignoreNonDeclaration: true }],
100
- // although using block style comments is easiest for writing a paragraph, JSDoc is usually preferred
101
- // when writing such comments during brainstorming, just disable the rule
102
- // most of the time, want to discourage non-JSDoc block style comments in production
103
- "multiline-comment-style": ["error", "separate-lines"],
104
- // unfortunately can't allow "after-used" for destructuring array
105
- // "no-unused-vars": ["error", { ignoreRestSiblings: true }],
106
-
107
- // unsure
108
- "no-labels": "off", // useful to be able to break/continue an outer loop; otherwise have to write more code
109
- "no-nested-ternary": "off", // ideally would allow just two levels of nesting; saves quite a bit of code
110
-
111
- // rule is too idealistic
112
- camelcase: "off", // useful to allow non-camel case for compatibility like destructuring JSON
113
- "sort-keys": "off", // too burdensome; doesn't affect order of destructured properties i.e. ({b, a}) => ({a, b}) would be fine
114
- "sort-vars": "off", // let results, index
115
- "no-param-reassign": "off", // a common pattern is to coerce parameters; noisy to rename parameters slightly differently
116
- "no-magic-numbers": "off", // does not allow 1, 2, -1; also sometimes noisy to name every constant (for example in time calculations)
117
- "id-length": "off", // single character variables can sometimes be useful: i, j, x, y, $, _
118
- "no-plusplus": "off", // ++ is too common of a language feature (C++)
119
- "no-underscore-dangle": "off", // difficult to come up with other names for named default parameters
120
- "max-statements": "off", // max 10 statements is way too low; unclear why number of statements is a good measurement
121
- "class-methods-use-this": "off", // allow a static method to be called like an instance method
122
- "arrow-body-style": "off", // does not allow braces to be used with a multi-line fat arrow expression
123
-
124
- // rule conflicts with another tool
125
- "one-var": "off", // with Prettier, comma appears on the same line as declaration, making code less readable
126
- "sort-imports": "off", // rely on IDE to sort imports; IDE sorts capitalizations differently than eslint expects
127
- "new-cap": "off", // React functions can begin with capital letter
128
-
129
- // bad rules
130
- "init-declarations": "off", // doesn't make sense for let and subsequent assignment in if/else; const implies this rule anyway
131
- "no-ternary": "off", // ternary is a useful language feature
132
- "no-undefined": "off", // actually undefined should be used over null
133
- "capitalized-comments": "off", // comments are not always sentences
134
- "prefer-named-capture-group": "off", // named capture groups are too new
135
- "no-continue": "off", // continue is a useful language feature
136
- "no-inline-comments": "off", // not adhered to in this file for example
137
- "line-comment-position": "off", // relates to above rule
138
- "no-loop-func": "off", // this is only a concern with var declarations
139
- "max-classes-per-file": "off", // one class per file discourages small classes
140
- "lines-between-class-members": "off", // discourages smaller classes
141
- "guard-for-in": "off", // warning about language feature; reasons to avoid it are too theoretical: works fine in nearly all cases
142
-
143
- // disabled too often
144
- "no-console": "off", // console error was already allowed; when is console.log actually bad?
145
- "no-await-in-loop": "off", // warning about language feature, unavoidable
146
- "require-atomic-updates": "off", // variables can change unexpectedly in parallelism due to another thread... this rule is way too noisy though
147
- },
148
- }