@msobiecki/eslint-config 8.38.2 → 8.39.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/CHANGELOG.md +31 -56
- package/README.md +73 -58
- package/eslint.config.js +209 -0
- package/jest.config.js +7 -5
- package/package.json +32 -33
- package/rules/base.js +582 -0
- package/rules/imports.js +273 -0
- package/rules/node.js +12 -0
- package/{__tests__ → tests}/base.test.js +15 -10
- package/tests/eslint.config.js +13 -0
- package/tests/test-cases/base/array-callback-return.js +2 -0
- package/tests/test-cases/base/block-scoped-var.js +40 -0
- package/tests/test-cases/base/consistent-return.js +4 -0
- package/tests/test-cases/base/curly.js +9 -0
- package/tests/test-cases/base/default-case.js +7 -0
- package/tests/test-cases/base/guard-for-in.js +4 -0
- package/tests/test-cases/base/no-alert.js +2 -0
- package/tests/test-cases/base/no-else-return.js +38 -0
- package/tests/test-cases/base/no-empty-function.js +44 -0
- package/tests/test-cases/base/no-extend-native.js +2 -0
- package/tests/test-cases/base/no-fallthrough.js +9 -0
- package/tests/test-cases/base/no-new.js +2 -0
- package/tests/test-cases/base/no-param-reassign.js +4 -0
- package/tests/test-cases/base/no-proto.js +2 -0
- package/tests/test-cases/base/no-redeclare.js +15 -0
- package/tests/test-cases/base/no-return-assign.js +4 -0
- package/tests/test-cases/base/no-script-url.js +2 -0
- package/tests/test-cases/base/no-self-compare.js +3 -0
- package/tests/test-cases/base/no-sequences.js +2 -0
- package/tests/test-cases/base/no-useless-concat.js +8 -0
- package/{__tests__ → tests}/test-cases/base/no-var.js +1 -1
- package/tests/test-cases/base/no-void.js +4 -0
- package/tests/test-cases/base/radix.js +2 -0
- package/tests/test-cases/base/yoda.js +29 -0
- package/utils/get-ts-config.js +16 -9
- package/.eslintrc.json +0 -3
- package/__tests__/.eslintrc.json +0 -3
- package/__tests__/test-cases/base/comma-dangle.js +0 -2
- package/best-practice-next.js +0 -3
- package/best-practice-react.js +0 -3
- package/best-practice.js +0 -3
- package/index.js +0 -3
- package/jest-dom.js +0 -3
- package/jest-react.js +0 -3
- package/jest.js +0 -3
- package/next.js +0 -3
- package/node.js +0 -3
- package/presets/base/base.js +0 -26
- package/presets/best-practice/best-practice-next.js +0 -12
- package/presets/best-practice/best-practice-react.js +0 -37
- package/presets/best-practice/best-practice.js +0 -38
- package/presets/jest/jest-base.js +0 -8
- package/presets/jest/jest-dom.js +0 -9
- package/presets/jest/jest-react.js +0 -8
- package/presets/next/next.js +0 -13
- package/presets/node/node.js +0 -3
- package/presets/react/react-jsx.js +0 -3
- package/presets/react/react.js +0 -35
- package/react-jsx.js +0 -3
- package/react.js +0 -3
- /package/{__tests__ → tests}/test-cases/base/camelcase.js +0 -0
- /package/{__tests__ → tests}/test-cases/base/eqeqeq.js +0 -0
- /package/{__tests__ → tests}/test-cases/base/no-console.js +0 -0
- /package/{__tests__ → tests}/test-cases/base/no-eval.js +0 -0
- /package/{__tests__ → tests}/test-cases/base/no-undef.js +0 -0
- /package/{__tests__ → tests}/test-cases/base/no-unused-vars.js +0 -0
- /package/{__tests__ → tests}/test-cases/base/prefer-const.js +0 -0
package/rules/imports.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const importRules = {
|
|
2
|
+
// Static analysis:
|
|
3
|
+
|
|
4
|
+
// ensure imports point to files/modules that can be resolved
|
|
5
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
|
|
6
|
+
"import/no-unresolved": ["error", { commonjs: true, caseSensitive: true }],
|
|
7
|
+
|
|
8
|
+
// ensure named imports coupled with named exports
|
|
9
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
|
|
10
|
+
"import/named": "error",
|
|
11
|
+
|
|
12
|
+
// ensure default import coupled with default export
|
|
13
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
|
|
14
|
+
"import/default": "off",
|
|
15
|
+
|
|
16
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/namespace.md
|
|
17
|
+
"import/namespace": "off",
|
|
18
|
+
|
|
19
|
+
// Helpful warnings:
|
|
20
|
+
|
|
21
|
+
// disallow invalid exports, e.g. multiple defaults
|
|
22
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/export.md
|
|
23
|
+
"import/export": "error",
|
|
24
|
+
|
|
25
|
+
// do not allow a default import name to match a named export
|
|
26
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
|
|
27
|
+
"import/no-named-as-default": "error",
|
|
28
|
+
|
|
29
|
+
// warn on accessing default export property names that are also named exports
|
|
30
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
|
|
31
|
+
"import/no-named-as-default-member": "error",
|
|
32
|
+
|
|
33
|
+
// disallow use of jsdoc-marked-deprecated imports
|
|
34
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
|
|
35
|
+
"import/no-deprecated": "off",
|
|
36
|
+
|
|
37
|
+
// Forbid the use of extraneous packages
|
|
38
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
|
|
39
|
+
// paths are treated both as absolute paths, and relative to process.cwd()
|
|
40
|
+
"import/no-extraneous-dependencies": [
|
|
41
|
+
"error",
|
|
42
|
+
{
|
|
43
|
+
devDependencies: [
|
|
44
|
+
"test/**", // tape, common npm pattern
|
|
45
|
+
"tests/**", // also common npm pattern
|
|
46
|
+
"spec/**", // mocha, rspec-like pattern
|
|
47
|
+
"**/__tests__/**", // jest pattern
|
|
48
|
+
"**/__mocks__/**", // jest pattern
|
|
49
|
+
"test.{js,jsx}", // repos with a single test file
|
|
50
|
+
"test-*.{js,jsx}", // repos with multiple top-level test files
|
|
51
|
+
"**/*{.,_}{test,spec}.{js,jsx}", // tests where the extension or filename suffix denotes that it is a test
|
|
52
|
+
"**/jest.config.js", // jest config
|
|
53
|
+
"**/jest.setup.js", // jest setup
|
|
54
|
+
"**/vue.config.js", // vue-cli config
|
|
55
|
+
"**/webpack.config.js", // webpack config
|
|
56
|
+
"**/webpack.config.*.js", // webpack config
|
|
57
|
+
"**/rollup.config.js", // rollup config
|
|
58
|
+
"**/rollup.config.*.js", // rollup config
|
|
59
|
+
"**/gulpfile.js", // gulp config
|
|
60
|
+
"**/gulpfile.*.js", // gulp config
|
|
61
|
+
"**/Gruntfile{,.js}", // grunt config
|
|
62
|
+
"**/protractor.conf.js", // protractor config
|
|
63
|
+
"**/protractor.conf.*.js", // protractor config
|
|
64
|
+
"**/karma.conf.js", // karma config
|
|
65
|
+
"**/.eslintrc.js", // eslint config
|
|
66
|
+
],
|
|
67
|
+
optionalDependencies: false,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
|
|
71
|
+
// Forbid mutable exports
|
|
72
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
|
|
73
|
+
"import/no-mutable-exports": "error",
|
|
74
|
+
|
|
75
|
+
// Module systems:
|
|
76
|
+
|
|
77
|
+
// disallow require()
|
|
78
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
|
|
79
|
+
"import/no-commonjs": "off",
|
|
80
|
+
|
|
81
|
+
// disallow AMD require/define
|
|
82
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-amd.md
|
|
83
|
+
"import/no-amd": "error",
|
|
84
|
+
|
|
85
|
+
// No Node.js builtin modules
|
|
86
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
|
|
87
|
+
// TODO: enable?
|
|
88
|
+
"import/no-nodejs-modules": "off",
|
|
89
|
+
|
|
90
|
+
// Style guide:
|
|
91
|
+
|
|
92
|
+
// disallow non-import statements appearing before import statements
|
|
93
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/first.md
|
|
94
|
+
"import/first": "error",
|
|
95
|
+
|
|
96
|
+
// disallow non-import statements appearing before import statements
|
|
97
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/imports-first.md
|
|
98
|
+
// deprecated: use `import/first`
|
|
99
|
+
"import/imports-first": "off",
|
|
100
|
+
|
|
101
|
+
// disallow duplicate imports
|
|
102
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
|
|
103
|
+
"import/no-duplicates": "error",
|
|
104
|
+
|
|
105
|
+
// disallow namespace imports
|
|
106
|
+
// TODO: enable?
|
|
107
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
|
|
108
|
+
"import/no-namespace": "off",
|
|
109
|
+
|
|
110
|
+
// Ensure consistent use of file extension within the import path
|
|
111
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/extensions.md
|
|
112
|
+
"import/extensions": [
|
|
113
|
+
"error",
|
|
114
|
+
"ignorePackages",
|
|
115
|
+
{
|
|
116
|
+
js: "never",
|
|
117
|
+
mjs: "never",
|
|
118
|
+
jsx: "never",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
|
|
122
|
+
// ensure absolute imports are above relative imports and that unassigned imports are ignored
|
|
123
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md
|
|
124
|
+
// TODO: enforce a stricter convention in module import order?
|
|
125
|
+
"import/order": ["error", { groups: [["builtin", "external", "internal"]] }],
|
|
126
|
+
|
|
127
|
+
// Require a newline after the last import/require in a group
|
|
128
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
|
|
129
|
+
"import/newline-after-import": "error",
|
|
130
|
+
|
|
131
|
+
// Require modules with a single export to use a default export
|
|
132
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
|
|
133
|
+
"import/prefer-default-export": "error",
|
|
134
|
+
|
|
135
|
+
// Restrict which files can be imported in a given folder
|
|
136
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
|
|
137
|
+
"import/no-restricted-paths": "off",
|
|
138
|
+
|
|
139
|
+
// Forbid modules to have too many dependencies
|
|
140
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/max-dependencies.md
|
|
141
|
+
"import/max-dependencies": ["off", { max: 10 }],
|
|
142
|
+
|
|
143
|
+
// Forbid import of modules using absolute paths
|
|
144
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
|
|
145
|
+
"import/no-absolute-path": "error",
|
|
146
|
+
|
|
147
|
+
// Forbid require() calls with expressions
|
|
148
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
|
|
149
|
+
"import/no-dynamic-require": "error",
|
|
150
|
+
|
|
151
|
+
// prevent importing the submodules of other modules
|
|
152
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md
|
|
153
|
+
"import/no-internal-modules": [
|
|
154
|
+
"off",
|
|
155
|
+
{
|
|
156
|
+
allow: [],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
|
|
160
|
+
// Warn if a module could be mistakenly parsed as a script by a consumer
|
|
161
|
+
// leveraging Unambiguous JavaScript Grammar
|
|
162
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/unambiguous.md
|
|
163
|
+
// this should not be enabled until this proposal has at least been *presented* to TC39.
|
|
164
|
+
// At the moment, it's not a thing.
|
|
165
|
+
"import/unambiguous": "off",
|
|
166
|
+
|
|
167
|
+
// Forbid Webpack loader syntax in imports
|
|
168
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
|
|
169
|
+
"import/no-webpack-loader-syntax": "error",
|
|
170
|
+
|
|
171
|
+
// Prevent unassigned imports
|
|
172
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
|
|
173
|
+
// importing for side effects is perfectly acceptable, if you need side effects.
|
|
174
|
+
"import/no-unassigned-import": "off",
|
|
175
|
+
|
|
176
|
+
// Prevent importing the default as if it were named
|
|
177
|
+
// https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
|
|
178
|
+
"import/no-named-default": "error",
|
|
179
|
+
|
|
180
|
+
// Reports if a module's default export is unnamed
|
|
181
|
+
// https://github.com/import-js/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
|
|
182
|
+
"import/no-anonymous-default-export": [
|
|
183
|
+
"off",
|
|
184
|
+
{
|
|
185
|
+
allowArray: false,
|
|
186
|
+
allowArrowFunction: false,
|
|
187
|
+
allowAnonymousClass: false,
|
|
188
|
+
allowAnonymousFunction: false,
|
|
189
|
+
allowLiteral: false,
|
|
190
|
+
allowObject: false,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
|
|
194
|
+
// This rule enforces that all exports are declared at the bottom of the file.
|
|
195
|
+
// https://github.com/import-js/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
|
|
196
|
+
// TODO: enable?
|
|
197
|
+
"import/exports-last": "off",
|
|
198
|
+
|
|
199
|
+
// Reports when named exports are not grouped together in a single export declaration
|
|
200
|
+
// or when multiple assignments to CommonJS module.exports or exports object are present
|
|
201
|
+
// in a single file.
|
|
202
|
+
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
|
|
203
|
+
"import/group-exports": "off",
|
|
204
|
+
|
|
205
|
+
// forbid default exports. this is a terrible rule, do not use it.
|
|
206
|
+
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md
|
|
207
|
+
"import/no-default-export": "off",
|
|
208
|
+
|
|
209
|
+
// Prohibit named exports. this is a terrible rule, do not use it.
|
|
210
|
+
// https://github.com/import-js/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
|
|
211
|
+
"import/no-named-export": "off",
|
|
212
|
+
|
|
213
|
+
// Forbid a module from importing itself
|
|
214
|
+
// https://github.com/import-js/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
|
|
215
|
+
"import/no-self-import": "error",
|
|
216
|
+
|
|
217
|
+
// Forbid cyclical dependencies between modules
|
|
218
|
+
// https://github.com/import-js/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
|
|
219
|
+
"import/no-cycle": ["error", { maxDepth: "∞" }],
|
|
220
|
+
|
|
221
|
+
// Ensures that there are no useless path segments
|
|
222
|
+
// https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
|
|
223
|
+
"import/no-useless-path-segments": ["error", { commonjs: true }],
|
|
224
|
+
|
|
225
|
+
// dynamic imports require a leading comment with a webpackChunkName
|
|
226
|
+
// https://github.com/import-js/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md
|
|
227
|
+
"import/dynamic-import-chunkname": [
|
|
228
|
+
"off",
|
|
229
|
+
{
|
|
230
|
+
importFunctions: [],
|
|
231
|
+
webpackChunknameFormat: "[0-9a-zA-Z-_/.]+",
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
|
|
235
|
+
// Use this rule to prevent imports to folders in relative parent paths.
|
|
236
|
+
// https://github.com/import-js/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
|
|
237
|
+
"import/no-relative-parent-imports": "off",
|
|
238
|
+
|
|
239
|
+
// Reports modules without any exports, or with unused exports
|
|
240
|
+
// https://github.com/import-js/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
|
|
241
|
+
// TODO: enable once it supports CJS
|
|
242
|
+
"import/no-unused-modules": [
|
|
243
|
+
"off",
|
|
244
|
+
{
|
|
245
|
+
ignoreExports: [],
|
|
246
|
+
missingExports: true,
|
|
247
|
+
unusedExports: true,
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
|
|
251
|
+
// Reports the use of import declarations with CommonJS exports in any module except for the main module.
|
|
252
|
+
// https://github.com/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-import-module-exports.md
|
|
253
|
+
"import/no-import-module-exports": [
|
|
254
|
+
"error",
|
|
255
|
+
{
|
|
256
|
+
exceptions: [],
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
|
|
260
|
+
// Use this rule to prevent importing packages through relative paths.
|
|
261
|
+
// https://github.com/import-js/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md
|
|
262
|
+
"import/no-relative-packages": "error",
|
|
263
|
+
|
|
264
|
+
// enforce a consistent style for type specifiers (inline or top-level)
|
|
265
|
+
// https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/consistent-type-specifier-style.md
|
|
266
|
+
// TODO, semver-major: enable (just in case)
|
|
267
|
+
"import/consistent-type-specifier-style": ["off", "prefer-inline"],
|
|
268
|
+
|
|
269
|
+
// Reports the use of empty named import blocks.
|
|
270
|
+
// https://github.com/import-js/eslint-plugin-import/blob/d5fc8b670dc8e6903dbb7b0894452f60c03089f5/docs/rules/no-empty-named-blocks.md
|
|
271
|
+
// TODO, semver-minor: enable
|
|
272
|
+
"import/no-empty-named-blocks": "off",
|
|
273
|
+
};
|
package/rules/node.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const nodeRules = {
|
|
2
|
+
// require all requires be top-level
|
|
3
|
+
"n/global-require": "error",
|
|
4
|
+
|
|
5
|
+
// disallow use of new operator with the require function
|
|
6
|
+
"n/no-new-require": "error",
|
|
7
|
+
|
|
8
|
+
// disallow string concatenation with __dirname and __filename
|
|
9
|
+
"n/no-path-concat": "error",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default nodeRules;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
5
|
import { ESLint } from "eslint";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
useEslintrc: false,
|
|
10
|
-
overrideConfigFile: path.resolve(process.cwd(), "presets/base/base.js"),
|
|
11
|
-
});
|
|
7
|
+
const filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const dirname = path.dirname(filename);
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
const configPath = path.resolve(process.cwd(), "eslint.config.js");
|
|
11
|
+
const configModule = await import(configPath);
|
|
12
|
+
|
|
13
|
+
const eslint = new ESLint({
|
|
14
|
+
overrideConfigFile: true,
|
|
15
|
+
overrideConfig: configModule.default ?? configModule,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("check base rules", () => {
|
|
19
|
+
const testDirectory = path.join(dirname, "test-cases", "base");
|
|
14
20
|
const testFiles = fs.readdirSync(testDirectory);
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
for (const file of testFiles) {
|
|
22
|
+
testFiles.forEach((file) => {
|
|
18
23
|
const ruleId = path.basename(file, ".js");
|
|
19
24
|
|
|
20
25
|
test(`${file} should trigger rule: ${ruleId}`, async () => {
|
|
@@ -23,5 +28,5 @@ describe("check base rules", () => {
|
|
|
23
28
|
const triggeredRules = messages.map((m) => m.ruleId).filter(Boolean);
|
|
24
29
|
expect(triggeredRules).toContain(ruleId);
|
|
25
30
|
});
|
|
26
|
-
}
|
|
31
|
+
});
|
|
27
32
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// ❌ Violates: block-scoped-var
|
|
2
|
+
function doIf() {
|
|
3
|
+
if (true) {
|
|
4
|
+
var build = true;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
console.log(build);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function doIfElse() {
|
|
11
|
+
if (true) {
|
|
12
|
+
var build = true;
|
|
13
|
+
} else {
|
|
14
|
+
var build = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function doTryCatch() {
|
|
19
|
+
try {
|
|
20
|
+
var build = 1;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
var f = build;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function doFor() {
|
|
27
|
+
for (var x = 1; x < 10; x++) {
|
|
28
|
+
var y = f(x);
|
|
29
|
+
}
|
|
30
|
+
console.log(y);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class C {
|
|
34
|
+
static {
|
|
35
|
+
if (something) {
|
|
36
|
+
var build = true;
|
|
37
|
+
}
|
|
38
|
+
build = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function foo1() {
|
|
2
|
+
if (x) {
|
|
3
|
+
return y;
|
|
4
|
+
} else {
|
|
5
|
+
return z;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function foo2() {
|
|
10
|
+
if (x) {
|
|
11
|
+
return y;
|
|
12
|
+
} else {
|
|
13
|
+
const t = "foo";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function foo3() {
|
|
18
|
+
if (error) {
|
|
19
|
+
return 'It failed';
|
|
20
|
+
} else {
|
|
21
|
+
if (loading) {
|
|
22
|
+
return "It's still loading";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Two warnings for nested occurrences
|
|
28
|
+
function foo4() {
|
|
29
|
+
if (x) {
|
|
30
|
+
if (y) {
|
|
31
|
+
return y;
|
|
32
|
+
} else {
|
|
33
|
+
return x;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
return z;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// ❌ Violates: no-empty-function
|
|
2
|
+
function foo() {}
|
|
3
|
+
|
|
4
|
+
const bar = function() {};
|
|
5
|
+
|
|
6
|
+
const bar1 = () => {};
|
|
7
|
+
|
|
8
|
+
function* baz() {}
|
|
9
|
+
|
|
10
|
+
const bar2 = function*() {};
|
|
11
|
+
|
|
12
|
+
const obj = {
|
|
13
|
+
foo() {},
|
|
14
|
+
|
|
15
|
+
*foo() {},
|
|
16
|
+
|
|
17
|
+
foo() {},
|
|
18
|
+
|
|
19
|
+
*foo() {},
|
|
20
|
+
|
|
21
|
+
get foo() {},
|
|
22
|
+
|
|
23
|
+
set foo(value) {}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
class A {
|
|
27
|
+
constructor() {}
|
|
28
|
+
|
|
29
|
+
foo() {}
|
|
30
|
+
|
|
31
|
+
*foo() {}
|
|
32
|
+
|
|
33
|
+
get foo() {}
|
|
34
|
+
|
|
35
|
+
set foo(value) {}
|
|
36
|
+
|
|
37
|
+
static foo() {}
|
|
38
|
+
|
|
39
|
+
static *foo() {}
|
|
40
|
+
|
|
41
|
+
static get foo() {}
|
|
42
|
+
|
|
43
|
+
static set foo(value) {}
|
|
44
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// ❌ Violates: no-var
|
|
2
|
-
var count = 5;
|
|
2
|
+
var count = 5;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// ❌ Violates: yoda
|
|
2
|
+
if ("red" === color) {
|
|
3
|
+
// ...
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (`red` === color) {
|
|
7
|
+
// ...
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (`red` === `${color}`) {
|
|
11
|
+
// ...
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (true == flag) {
|
|
15
|
+
// ...
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (5 > count) {
|
|
19
|
+
// ...
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (-1 < str.indexOf(substr)) {
|
|
23
|
+
// ...
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (0 <= x && x < 1) {
|
|
27
|
+
// ...
|
|
28
|
+
}
|
|
29
|
+
|
package/utils/get-ts-config.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Get tsconfig path if exists
|
|
6
|
+
* @returns {string|undefined} tsconfig path or undefined
|
|
7
|
+
*/
|
|
8
|
+
export default function getTsConfig() {
|
|
9
|
+
if (fs.existsSync("tsconfig.json")) {
|
|
10
|
+
return path.resolve("tsconfig.json");
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
if (fs.existsSync("../tsconfig.json")) {
|
|
14
|
+
return path.resolve("../tsconfig.json");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return;
|
|
18
|
+
}
|
package/.eslintrc.json
DELETED
package/__tests__/.eslintrc.json
DELETED