@qlik/eslint-config 1.4.29 → 2.0.0-next.1
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 +122 -213
- package/package.json +6 -24
- package/src/configs/esbrowser.js +0 -21
- package/src/configs/esm.js +6 -27
- package/src/configs/react.js +9 -77
- package/src/configs/shared/base.js +26 -14
- package/src/configs/shared/default-rules/eslint-core.js +455 -0
- package/src/configs/{rules → shared/default-rules}/import-x.js +5 -31
- package/src/configs/{rules → shared/default-rules}/node.js +1 -1
- package/src/configs/shared/default-rules/react.js +22 -0
- package/src/configs/{rules → shared/default-rules}/typescript.js +13 -57
- package/src/configs/shared/node.js +32 -28
- package/src/configs/vitest.js +1 -2
- package/src/index.d.ts +1 -21
- package/src/index.js +1 -21
- package/src/types/index.ts +5 -46
- package/src/utils/config.js +0 -3
- package/src/utils/merge.js +2 -2
- package/src/configs/jest.js +0 -27
- package/src/configs/playwright.js +0 -24
- package/src/configs/rules/eslint-core.js +0 -960
- package/src/configs/rules/react-a11y.js +0 -232
- package/src/configs/rules/react-hooks.js +0 -12
- package/src/configs/rules/react.js +0 -424
- package/src/configs/rules/svelte.js +0 -11
- package/src/configs/svelte.js +0 -56
- package/src/utils/compose.js +0 -63
package/src/configs/react.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
import eslintReact from "@eslint-react/eslint-plugin";
|
|
2
3
|
import prettier from "eslint-config-prettier";
|
|
3
|
-
import jsxA11y from "eslint-plugin-jsx-a11y";
|
|
4
|
-
import eslintPluginReact from "eslint-plugin-react";
|
|
5
|
-
import reactHooks from "eslint-plugin-react-hooks";
|
|
6
4
|
import { mergeConfigs } from "../utils/config.js";
|
|
7
|
-
import reactA11yRules from "./rules/react-a11y.js";
|
|
8
|
-
import reactHooksRules from "./rules/react-hooks.js";
|
|
9
|
-
import reactRules from "./rules/react.js";
|
|
10
5
|
import { baseConfigJS, baseConfigTS } from "./shared/base.js";
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @type {import("../types/index.js").ESLintFlatConfig}
|
|
15
|
-
*/
|
|
16
|
-
const reactBaseConfig = mergeConfigs(
|
|
17
|
-
// base it on the recommended react plugins config
|
|
18
|
-
eslintPluginReact.configs.flat.recommended,
|
|
19
|
-
jsxA11y.flatConfigs.recommended,
|
|
20
|
-
reactHooks.configs.flat["recommended-latest"],
|
|
21
|
-
|
|
22
|
-
// add qlik's recommended react config
|
|
23
|
-
{
|
|
24
|
-
languageOptions: {
|
|
25
|
-
parserOptions: {
|
|
26
|
-
ecmaFeatures: {
|
|
27
|
-
jsx: true,
|
|
28
|
-
},
|
|
29
|
-
jsxPragma: null, // for @typescript/eslint-parser
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
settings: {
|
|
34
|
-
react: {
|
|
35
|
-
version: "detect",
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
rules: {
|
|
40
|
-
...reactRules,
|
|
41
|
-
...reactA11yRules,
|
|
42
|
-
...reactHooksRules,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
);
|
|
6
|
+
import reactRules from "./shared/default-rules/react.js";
|
|
46
7
|
|
|
47
8
|
/**
|
|
48
9
|
* @type {import("../types/index.js").ESLintFlatConfig}
|
|
@@ -50,15 +11,15 @@ const reactBaseConfig = mergeConfigs(
|
|
|
50
11
|
const reactJS = mergeConfigs(
|
|
51
12
|
// base it on the recommended javascript config
|
|
52
13
|
baseConfigJS,
|
|
53
|
-
// add the
|
|
54
|
-
|
|
14
|
+
// add the react config
|
|
15
|
+
eslintReact.configs.strict,
|
|
55
16
|
// add qlik's recommended react config for javascript
|
|
56
17
|
{
|
|
57
18
|
name: "react-js",
|
|
58
19
|
files: ["**/*.js", "**/*.jsx"],
|
|
59
20
|
rules: {
|
|
60
21
|
// turn on/off or modify js rules necessary for react
|
|
61
|
-
|
|
22
|
+
...reactRules,
|
|
62
23
|
},
|
|
63
24
|
},
|
|
64
25
|
prettier,
|
|
@@ -70,48 +31,19 @@ const reactJS = mergeConfigs(
|
|
|
70
31
|
const reactTS = mergeConfigs(
|
|
71
32
|
// base it on the recommended typescript config
|
|
72
33
|
baseConfigTS,
|
|
73
|
-
// add the
|
|
74
|
-
|
|
34
|
+
// add the react config
|
|
35
|
+
eslintReact.configs["strict-typescript"],
|
|
75
36
|
// add qlik's recommended react config for typescript
|
|
76
37
|
{
|
|
77
38
|
name: "react-ts",
|
|
78
39
|
files: ["**/*.ts", "**/*.tsx"],
|
|
79
40
|
rules: {
|
|
80
41
|
// turn on/off or modify js/ts rules necessary for react
|
|
81
|
-
|
|
82
|
-
// avoid double linting of class-methods-use-this in typescript
|
|
83
|
-
"class-methods-use-this": "off",
|
|
84
|
-
"@typescript-eslint/class-methods-use-this": reactBaseConfig.rules?.["class-methods-use-this"] || "off",
|
|
42
|
+
...reactRules,
|
|
85
43
|
},
|
|
86
44
|
},
|
|
87
45
|
prettier,
|
|
88
46
|
);
|
|
89
47
|
|
|
90
|
-
|
|
91
|
-
* Adding commonjs config for .cjs files
|
|
92
|
-
* @type {import("../types/index.js").ESLintFlatConfig}
|
|
93
|
-
*/
|
|
94
|
-
const reactCJS = mergeConfigs(
|
|
95
|
-
baseCjsJS,
|
|
96
|
-
{
|
|
97
|
-
name: "react-cjs",
|
|
98
|
-
files: ["**/*.cjs"],
|
|
99
|
-
},
|
|
100
|
-
prettier,
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Adding commonjs config for .cts files
|
|
105
|
-
* @type {import("../types/index.js").ESLintFlatConfig}
|
|
106
|
-
*/
|
|
107
|
-
const reactCTS = mergeConfigs(
|
|
108
|
-
baseCjsTS,
|
|
109
|
-
{
|
|
110
|
-
name: "react-cts",
|
|
111
|
-
files: ["**/*.cts"],
|
|
112
|
-
},
|
|
113
|
-
prettier,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
export default [reactJS, reactTS, reactCJS, reactCTS];
|
|
48
|
+
export default [reactJS, reactTS];
|
|
117
49
|
export { reactJS, reactTS };
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import js from "@eslint/js";
|
|
2
|
-
import
|
|
3
|
-
import eslintPluginImportX from "eslint-plugin-import-x";
|
|
2
|
+
import { importX } from "eslint-plugin-import-x";
|
|
4
3
|
import globals from "globals";
|
|
5
4
|
import tsconfig from "typescript-eslint";
|
|
6
5
|
import { mergeConfigs } from "../../utils/config.js";
|
|
7
|
-
import eslintCoreRules from "
|
|
8
|
-
import
|
|
9
|
-
import
|
|
6
|
+
import eslintCoreRules from "./default-rules/eslint-core.js";
|
|
7
|
+
import typescriptRules from "./default-rules/typescript.js";
|
|
8
|
+
import importXRules from "./default-rules/import-x.js";
|
|
10
9
|
|
|
11
10
|
/**
|
|
11
|
+
* This is the base config that all other configs in this package extend from.
|
|
12
|
+
* It includes the recommended eslint rules and some basic settings for parsing
|
|
13
|
+
* modern javascript and typescript, as well as some of qlik's custom rules that
|
|
14
|
+
* are not specific to any framework or environment. This config is meant to be
|
|
15
|
+
* extended by other configs and not used directly.
|
|
12
16
|
* @type {import("../../types/index.js").ESLintFlatConfig}
|
|
13
17
|
*/
|
|
14
18
|
const baseConfig = mergeConfigs(
|
|
15
19
|
// basic js config
|
|
16
20
|
js.configs.recommended,
|
|
17
|
-
// import-x
|
|
18
|
-
|
|
21
|
+
// import-x recommended config
|
|
22
|
+
importX.flatConfigs.recommended,
|
|
19
23
|
{
|
|
20
24
|
languageOptions: {
|
|
21
25
|
globals: globals.browser,
|
|
@@ -26,7 +30,7 @@ const baseConfig = mergeConfigs(
|
|
|
26
30
|
sourceType: "module",
|
|
27
31
|
},
|
|
28
32
|
rules: {
|
|
29
|
-
// add
|
|
33
|
+
// add or modify recommended default rules
|
|
30
34
|
...eslintCoreRules,
|
|
31
35
|
...importXRules,
|
|
32
36
|
},
|
|
@@ -34,6 +38,11 @@ const baseConfig = mergeConfigs(
|
|
|
34
38
|
);
|
|
35
39
|
|
|
36
40
|
/**
|
|
41
|
+
* This config is meant to be extended by javascript specific configs, it is not meant to be used directly.
|
|
42
|
+
* Note that we are using the typescript parser to parse javascript files as well,
|
|
43
|
+
* this is because it can handle all modern javascript syntax and features, and it
|
|
44
|
+
* allows us to have a single parser for both javascript and typescript configs.
|
|
45
|
+
* We can turn off typescript specific rules in the javascript configs if needed.
|
|
37
46
|
* @type {import("../../types/index.js").ESLintFlatConfig}
|
|
38
47
|
*/
|
|
39
48
|
const baseConfigJS = mergeConfigs(
|
|
@@ -44,24 +53,27 @@ const baseConfigJS = mergeConfigs(
|
|
|
44
53
|
);
|
|
45
54
|
|
|
46
55
|
/**
|
|
56
|
+
* This config is meant to be extended by typescript specific configs,
|
|
57
|
+
* it is not meant to be used directly.
|
|
47
58
|
* @type {import("../../types/index.js").ESLintFlatConfig}
|
|
48
59
|
*/
|
|
49
60
|
const baseConfigTS = mergeConfigs(
|
|
50
61
|
// base it on base config
|
|
51
62
|
baseConfig,
|
|
63
|
+
// typescript settings for import-x
|
|
64
|
+
importX.flatConfigs.typescript,
|
|
52
65
|
// add recommended typescript config
|
|
53
|
-
...tsconfig.configs.
|
|
54
|
-
// add import-x recommended typescript config
|
|
55
|
-
eslintPluginImportX.flatConfigs.typescript,
|
|
56
|
-
// add qlik's recommended typescript config
|
|
66
|
+
...tsconfig.configs.recommendedTypeChecked,
|
|
57
67
|
{
|
|
58
68
|
languageOptions: {
|
|
59
69
|
parserOptions: {
|
|
60
|
-
parser: tsParser,
|
|
61
70
|
projectService: true,
|
|
62
71
|
},
|
|
63
72
|
},
|
|
64
|
-
rules:
|
|
73
|
+
rules: {
|
|
74
|
+
...typescriptRules,
|
|
75
|
+
// add qlik's recommended typescript config for typescript here if needed
|
|
76
|
+
},
|
|
65
77
|
},
|
|
66
78
|
);
|
|
67
79
|
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import confusingBrowserGlobals from "confusing-browser-globals";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @satisfies {import("../../../types/index.js").ESLintFlatConfig["rules"]}
|
|
6
|
+
*
|
|
7
|
+
* eslint core recommended config https://github.com/eslint/eslint/blob/main/packages/js/src/configs/eslint-recommended.js
|
|
8
|
+
*/
|
|
9
|
+
const rules = {
|
|
10
|
+
// modify/add rules from eslint core package here additionally to the recommended rules
|
|
11
|
+
|
|
12
|
+
// require return statements to either always or never specify values
|
|
13
|
+
// https://eslint.org/docs/rules/consistent-return
|
|
14
|
+
"consistent-return": "error",
|
|
15
|
+
|
|
16
|
+
// require default case in switch statements
|
|
17
|
+
// https://eslint.org/docs/rules/default-case
|
|
18
|
+
"default-case": ["error", { commentPattern: "^no default$" }],
|
|
19
|
+
|
|
20
|
+
// Enforce default clauses in switch statements to be last
|
|
21
|
+
// https://eslint.org/docs/rules/default-case-last
|
|
22
|
+
"default-case-last": "error",
|
|
23
|
+
|
|
24
|
+
// Enforce default parameters to be last
|
|
25
|
+
// https://eslint.org/docs/rules/default-param-last
|
|
26
|
+
"default-param-last": "error",
|
|
27
|
+
|
|
28
|
+
// require the use of === and !==
|
|
29
|
+
// https://eslint.org/docs/rules/eqeqeq
|
|
30
|
+
eqeqeq: ["error", "always", { null: "ignore" }],
|
|
31
|
+
|
|
32
|
+
// disallow the use of alert, confirm, and prompt
|
|
33
|
+
// https://eslint.org/docs/rules/no-alert
|
|
34
|
+
"no-alert": "error",
|
|
35
|
+
|
|
36
|
+
// Disallow returning value in constructor
|
|
37
|
+
// https://eslint.org/docs/rules/no-constructor-return
|
|
38
|
+
"no-constructor-return": "error",
|
|
39
|
+
|
|
40
|
+
// disallow use of eval()
|
|
41
|
+
// https://eslint.org/docs/rules/no-eval
|
|
42
|
+
"no-eval": "error",
|
|
43
|
+
|
|
44
|
+
// disallow adding to native types
|
|
45
|
+
// https://eslint.org/docs/rules/no-extend-native
|
|
46
|
+
"no-extend-native": "error",
|
|
47
|
+
|
|
48
|
+
// disallow unnecessary function binding
|
|
49
|
+
// https://eslint.org/docs/rules/no-extra-bind
|
|
50
|
+
"no-extra-bind": "error",
|
|
51
|
+
|
|
52
|
+
// disallow use of eval()-like methods
|
|
53
|
+
// https://eslint.org/docs/rules/no-implied-eval
|
|
54
|
+
"no-implied-eval": "error",
|
|
55
|
+
|
|
56
|
+
// disallow unnecessary nested blocks
|
|
57
|
+
// https://eslint.org/docs/rules/no-lone-blocks
|
|
58
|
+
"no-lone-blocks": "error",
|
|
59
|
+
|
|
60
|
+
// disallow creation of functions within loops
|
|
61
|
+
// https://eslint.org/docs/rules/no-loop-func
|
|
62
|
+
"no-loop-func": "error",
|
|
63
|
+
|
|
64
|
+
// disallow use of new operator for Function object
|
|
65
|
+
// https://eslint.org/docs/rules/no-new-func
|
|
66
|
+
"no-new-func": "error",
|
|
67
|
+
|
|
68
|
+
// Disallow calls to the Object constructor without an argument
|
|
69
|
+
// https://eslint.org/docs/latest/rules/no-object-constructor
|
|
70
|
+
"no-object-constructor": "error",
|
|
71
|
+
|
|
72
|
+
// disallow use of octal escape sequences in string literals, such as
|
|
73
|
+
// var foo = 'Copyright \251';
|
|
74
|
+
// https://eslint.org/docs/rules/no-octal-escape
|
|
75
|
+
"no-octal-escape": "error",
|
|
76
|
+
|
|
77
|
+
// disallow reassignment of function parameters
|
|
78
|
+
// disallow parameter object manipulation except for specific exclusions
|
|
79
|
+
// rule: https://eslint.org/docs/rules/no-param-reassign.html
|
|
80
|
+
"no-param-reassign": [
|
|
81
|
+
"error",
|
|
82
|
+
{
|
|
83
|
+
props: true,
|
|
84
|
+
ignorePropertyModificationsFor: [
|
|
85
|
+
"prev", // for reduce accumulators
|
|
86
|
+
"acc", // for reduce accumulators
|
|
87
|
+
"accumulator", // for reduce accumulators
|
|
88
|
+
"e", // for e.returnvalue
|
|
89
|
+
"ctx", // for Koa routing
|
|
90
|
+
"context", // for Koa routing
|
|
91
|
+
"req", // for Express requests
|
|
92
|
+
"request", // for Express requests
|
|
93
|
+
"res", // for Express responses
|
|
94
|
+
"response", // for Express responses
|
|
95
|
+
"$scope", // for Angular 1 scopes
|
|
96
|
+
"staticContext", // for ReactRouter context
|
|
97
|
+
"sharedState", // for shared state in reducers
|
|
98
|
+
"state", // for shared state in reducers
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
|
|
103
|
+
// disallow usage of __proto__ property
|
|
104
|
+
// https://eslint.org/docs/rules/no-proto
|
|
105
|
+
"no-proto": "error",
|
|
106
|
+
|
|
107
|
+
// disallow declaring the same variable more than once
|
|
108
|
+
// https://eslint.org/docs/rules/no-redeclare
|
|
109
|
+
"no-redeclare": "error",
|
|
110
|
+
|
|
111
|
+
// disallow certain object properties
|
|
112
|
+
// https://eslint.org/docs/rules/no-restricted-properties
|
|
113
|
+
"no-restricted-properties": [
|
|
114
|
+
"error",
|
|
115
|
+
{
|
|
116
|
+
object: "arguments",
|
|
117
|
+
property: "callee",
|
|
118
|
+
message: "arguments.callee is deprecated",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
object: "global",
|
|
122
|
+
property: "isFinite",
|
|
123
|
+
message: "Please use Number.isFinite instead",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
object: "self",
|
|
127
|
+
property: "isFinite",
|
|
128
|
+
message: "Please use Number.isFinite instead",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
object: "window",
|
|
132
|
+
property: "isFinite",
|
|
133
|
+
message: "Please use Number.isFinite instead",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
object: "global",
|
|
137
|
+
property: "isNaN",
|
|
138
|
+
message: "Please use Number.isNaN instead",
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
object: "self",
|
|
142
|
+
property: "isNaN",
|
|
143
|
+
message: "Please use Number.isNaN instead",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
object: "window",
|
|
147
|
+
property: "isNaN",
|
|
148
|
+
message: "Please use Number.isNaN instead",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
property: "__defineGetter__",
|
|
152
|
+
message: "Please use Object.defineProperty instead.",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
property: "__defineSetter__",
|
|
156
|
+
message: "Please use Object.defineProperty instead.",
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
|
|
160
|
+
// disallow use of assignment in return statement
|
|
161
|
+
// https://eslint.org/docs/rules/no-return-assign
|
|
162
|
+
"no-return-assign": ["error", "always"],
|
|
163
|
+
|
|
164
|
+
// disallow use of `javascript:` urls.
|
|
165
|
+
// https://eslint.org/docs/rules/no-script-url
|
|
166
|
+
"no-script-url": "error",
|
|
167
|
+
|
|
168
|
+
// disallow comparisons where both sides are exactly the same
|
|
169
|
+
// https://eslint.org/docs/rules/no-self-compare
|
|
170
|
+
"no-self-compare": "error",
|
|
171
|
+
|
|
172
|
+
// disallow use of comma operator
|
|
173
|
+
// https://eslint.org/docs/rules/no-sequences
|
|
174
|
+
"no-sequences": "error",
|
|
175
|
+
|
|
176
|
+
// restrict what can be thrown as an exception
|
|
177
|
+
// https://eslint.org/docs/rules/no-throw-literal
|
|
178
|
+
"no-throw-literal": "error",
|
|
179
|
+
|
|
180
|
+
// disallow unmodified conditions of loops
|
|
181
|
+
// https://eslint.org/docs/rules/no-unmodified-loop-condition
|
|
182
|
+
"no-unmodified-loop-condition": "error",
|
|
183
|
+
|
|
184
|
+
// disallow usage of expressions in statement position
|
|
185
|
+
// https://eslint.org/docs/rules/no-unused-expressions
|
|
186
|
+
"no-unused-expressions": [
|
|
187
|
+
"error",
|
|
188
|
+
{
|
|
189
|
+
allowShortCircuit: false,
|
|
190
|
+
allowTernary: false,
|
|
191
|
+
allowTaggedTemplates: false,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
|
|
195
|
+
// disallow unnecessary .call() and .apply()
|
|
196
|
+
// https://eslint.org/docs/rules/no-useless-call
|
|
197
|
+
"no-useless-call": "error",
|
|
198
|
+
|
|
199
|
+
// disallow useless string concatenation
|
|
200
|
+
// https://eslint.org/docs/rules/no-useless-concat
|
|
201
|
+
"no-useless-concat": "error",
|
|
202
|
+
|
|
203
|
+
// disallow redundant return; keywords
|
|
204
|
+
// https://eslint.org/docs/rules/no-useless-return
|
|
205
|
+
"no-useless-return": "error",
|
|
206
|
+
|
|
207
|
+
// require using Error objects as Promise rejection reasons
|
|
208
|
+
// https://eslint.org/docs/rules/prefer-promise-reject-errors
|
|
209
|
+
"prefer-promise-reject-errors": ["error", { allowEmptyReject: true }],
|
|
210
|
+
|
|
211
|
+
// Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call()
|
|
212
|
+
// https://eslint.org/docs/rules/prefer-object-has-own
|
|
213
|
+
"prefer-object-has-own": "error",
|
|
214
|
+
|
|
215
|
+
// https://eslint.org/docs/rules/prefer-regex-literals
|
|
216
|
+
"prefer-regex-literals": [
|
|
217
|
+
"error",
|
|
218
|
+
{
|
|
219
|
+
disallowRedundantWrapping: true,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
|
|
223
|
+
// require use of the second argument for parseInt()
|
|
224
|
+
// https://eslint.org/docs/rules/radix
|
|
225
|
+
radix: "error",
|
|
226
|
+
|
|
227
|
+
// require or disallow Yoda conditions
|
|
228
|
+
// https://eslint.org/docs/rules/yoda
|
|
229
|
+
yoda: "error",
|
|
230
|
+
|
|
231
|
+
// Disallow await inside of loops
|
|
232
|
+
// https://eslint.org/docs/rules/no-await-in-loop
|
|
233
|
+
"no-await-in-loop": "error",
|
|
234
|
+
|
|
235
|
+
// disallow use of console
|
|
236
|
+
"no-console": "warn",
|
|
237
|
+
|
|
238
|
+
// disallow function or variable declarations in nested blocks
|
|
239
|
+
"no-inner-declarations": "error",
|
|
240
|
+
|
|
241
|
+
// Disallow returning values from Promise executor functions
|
|
242
|
+
// https://eslint.org/docs/rules/no-promise-executor-return
|
|
243
|
+
"no-promise-executor-return": "error",
|
|
244
|
+
|
|
245
|
+
// Disallow template literal placeholder syntax in regular strings
|
|
246
|
+
// https://eslint.org/docs/rules/no-template-curly-in-string
|
|
247
|
+
"no-template-curly-in-string": "error",
|
|
248
|
+
|
|
249
|
+
// Disallow loops with a body that allows only one iteration
|
|
250
|
+
// https://eslint.org/docs/rules/no-unreachable-loop
|
|
251
|
+
"no-unreachable-loop": [
|
|
252
|
+
"error",
|
|
253
|
+
{
|
|
254
|
+
ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
|
|
258
|
+
// disallow use of optional chaining in contexts where the undefined value is not allowed
|
|
259
|
+
// https://eslint.org/docs/rules/no-unsafe-optional-chaining
|
|
260
|
+
"no-unsafe-optional-chaining": ["error", { disallowArithmeticOperators: true }],
|
|
261
|
+
|
|
262
|
+
// ensure that the results of typeof are compared against a valid string
|
|
263
|
+
// https://eslint.org/docs/rules/valid-typeof
|
|
264
|
+
"valid-typeof": ["error", { requireStringLiterals: true }],
|
|
265
|
+
|
|
266
|
+
// Disallow specified names in exports
|
|
267
|
+
// https://eslint.org/docs/rules/no-restricted-exports
|
|
268
|
+
"no-restricted-exports": [
|
|
269
|
+
"error",
|
|
270
|
+
{
|
|
271
|
+
restrictedNamedExports: [
|
|
272
|
+
"default", // use `export default` to provide a default export
|
|
273
|
+
"then", // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
|
|
278
|
+
// disallow specific imports
|
|
279
|
+
// https://eslint.org/docs/rules/no-restricted-imports
|
|
280
|
+
"no-restricted-imports": [
|
|
281
|
+
"off",
|
|
282
|
+
{
|
|
283
|
+
paths: [],
|
|
284
|
+
patterns: [],
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
|
|
288
|
+
// disallow useless computed property keys
|
|
289
|
+
// https://eslint.org/docs/rules/no-useless-computed-key
|
|
290
|
+
"no-useless-computed-key": "error",
|
|
291
|
+
|
|
292
|
+
// disallow unnecessary constructor
|
|
293
|
+
// https://eslint.org/docs/rules/no-useless-constructor
|
|
294
|
+
"no-useless-constructor": "error",
|
|
295
|
+
|
|
296
|
+
// disallow renaming import, export, and destructured assignments to the same name
|
|
297
|
+
// https://eslint.org/docs/rules/no-useless-rename
|
|
298
|
+
"no-useless-rename": [
|
|
299
|
+
"error",
|
|
300
|
+
{
|
|
301
|
+
ignoreDestructuring: false,
|
|
302
|
+
ignoreImport: false,
|
|
303
|
+
ignoreExport: false,
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
|
|
307
|
+
// require let or const instead of var
|
|
308
|
+
"no-var": "error",
|
|
309
|
+
|
|
310
|
+
// require method and property shorthand syntax for object literals
|
|
311
|
+
// https://eslint.org/docs/rules/object-shorthand
|
|
312
|
+
"object-shorthand": [
|
|
313
|
+
"error",
|
|
314
|
+
"always",
|
|
315
|
+
{
|
|
316
|
+
ignoreConstructors: false,
|
|
317
|
+
avoidQuotes: true,
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
|
|
321
|
+
// suggest using of const declaration for variables that are never modified after declared
|
|
322
|
+
"prefer-const": [
|
|
323
|
+
"error",
|
|
324
|
+
{
|
|
325
|
+
destructuring: "any",
|
|
326
|
+
ignoreReadBeforeAssign: true,
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
|
|
330
|
+
// disallow parseInt() in favor of binary, octal, and hexadecimal literals
|
|
331
|
+
// https://eslint.org/docs/rules/prefer-numeric-literals
|
|
332
|
+
"prefer-numeric-literals": "error",
|
|
333
|
+
|
|
334
|
+
// use rest parameters instead of arguments
|
|
335
|
+
// https://eslint.org/docs/rules/prefer-rest-params
|
|
336
|
+
"prefer-rest-params": "error",
|
|
337
|
+
|
|
338
|
+
// suggest using the spread syntax instead of .apply()
|
|
339
|
+
// https://eslint.org/docs/rules/prefer-spread
|
|
340
|
+
"prefer-spread": "error",
|
|
341
|
+
|
|
342
|
+
// suggest using template literals instead of string concatenation
|
|
343
|
+
// https://eslint.org/docs/rules/prefer-template
|
|
344
|
+
"prefer-template": "error",
|
|
345
|
+
|
|
346
|
+
// require a Symbol description
|
|
347
|
+
// https://eslint.org/docs/rules/symbol-description
|
|
348
|
+
"symbol-description": "error",
|
|
349
|
+
|
|
350
|
+
// disallow specific globals
|
|
351
|
+
// https://eslint.org/docs/latest/rules/no-restricted-globals
|
|
352
|
+
"no-restricted-globals": [
|
|
353
|
+
"error",
|
|
354
|
+
{
|
|
355
|
+
name: "isFinite",
|
|
356
|
+
message: "Use Number.isFinite instead",
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
name: "isNaN",
|
|
360
|
+
message: "Use Number.isNaN instead",
|
|
361
|
+
},
|
|
362
|
+
...confusingBrowserGlobals.map((g) => ({
|
|
363
|
+
name: g,
|
|
364
|
+
message: `Use window.${g} instead`,
|
|
365
|
+
})),
|
|
366
|
+
],
|
|
367
|
+
|
|
368
|
+
// disallow declaration of variables already declared in the outer scope
|
|
369
|
+
// https://eslint.org/docs/latest/rules/no-shadow
|
|
370
|
+
"no-shadow": "error",
|
|
371
|
+
|
|
372
|
+
// disallow use of undefined when initializing variables
|
|
373
|
+
// https://eslint.org/docs/latest/rules/no-undef-init
|
|
374
|
+
"no-undef-init": "error",
|
|
375
|
+
|
|
376
|
+
// require camel case names
|
|
377
|
+
// https://eslint.org/docs/latest/rules/camelcase
|
|
378
|
+
camelcase: ["error", { properties: "never", ignoreDestructuring: false }],
|
|
379
|
+
|
|
380
|
+
// require function expressions to have a name
|
|
381
|
+
// https://eslint.org/docs/rules/func-names
|
|
382
|
+
"func-names": "warn",
|
|
383
|
+
|
|
384
|
+
// require a capital letter for constructors
|
|
385
|
+
// https://eslint.org/docs/rules/new-cap
|
|
386
|
+
"new-cap": [
|
|
387
|
+
"error",
|
|
388
|
+
{
|
|
389
|
+
newIsCap: true,
|
|
390
|
+
newIsCapExceptions: [],
|
|
391
|
+
capIsNew: false,
|
|
392
|
+
capIsNewExceptions: ["Immutable.Map", "Immutable.Set", "Immutable.List"],
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
|
|
396
|
+
// disallow use of the Array constructor
|
|
397
|
+
"no-array-constructor": "error",
|
|
398
|
+
|
|
399
|
+
// disallow if as the only statement in an else block
|
|
400
|
+
// https://eslint.org/docs/rules/no-lonely-if
|
|
401
|
+
"no-lonely-if": "error",
|
|
402
|
+
|
|
403
|
+
// disallow use of chained assignment expressions
|
|
404
|
+
// https://eslint.org/docs/rules/no-multi-assign
|
|
405
|
+
"no-multi-assign": ["error"],
|
|
406
|
+
|
|
407
|
+
// disallow nested ternary expressions
|
|
408
|
+
"no-nested-ternary": "error",
|
|
409
|
+
|
|
410
|
+
// disallow certain syntax forms
|
|
411
|
+
// https://eslint.org/docs/rules/no-restricted-syntax
|
|
412
|
+
"no-restricted-syntax": [
|
|
413
|
+
"error",
|
|
414
|
+
// {
|
|
415
|
+
// selector: "ForInStatement",
|
|
416
|
+
// message:
|
|
417
|
+
// "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use for..of or Object.{keys,values,entries}, and iterate over the resulting array.",
|
|
418
|
+
// },
|
|
419
|
+
{
|
|
420
|
+
selector: "LabeledStatement",
|
|
421
|
+
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
selector: "WithStatement",
|
|
425
|
+
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
|
|
429
|
+
// disallow the use of Boolean literals in conditional expressions
|
|
430
|
+
// also, prefer `a || b` over `a ? a : b`
|
|
431
|
+
// https://eslint.org/docs/rules/no-unneeded-ternary
|
|
432
|
+
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
|
|
433
|
+
|
|
434
|
+
// allow just one var statement per function
|
|
435
|
+
// https://eslint.org/docs/rules/one-var
|
|
436
|
+
"one-var": ["error", "never"],
|
|
437
|
+
|
|
438
|
+
// require assignment operator shorthand where possible or prohibit it entirely
|
|
439
|
+
// https://eslint.org/docs/rules/operator-assignment
|
|
440
|
+
"operator-assignment": ["error", "always"],
|
|
441
|
+
|
|
442
|
+
// Disallow the use of Math.pow in favor of the ** operator
|
|
443
|
+
// https://eslint.org/docs/rules/prefer-exponentiation-operator
|
|
444
|
+
"prefer-exponentiation-operator": "error",
|
|
445
|
+
|
|
446
|
+
// Prefer use of an object spread over Object.assign
|
|
447
|
+
// https://eslint.org/docs/rules/prefer-object-spread
|
|
448
|
+
"prefer-object-spread": "error",
|
|
449
|
+
|
|
450
|
+
// require or disallow the Unicode Byte Order Mark
|
|
451
|
+
// https://eslint.org/docs/rules/unicode-bom
|
|
452
|
+
"unicode-bom": ["error", "never"],
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export default rules;
|