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