@darksheep/eslint 5.2.1 → 5.3.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/CHANGELOG.md +30 -0
- package/package.json +8 -6
- package/src/configs/eslint-base.js +103 -103
- package/src/configs/eslint-complexity.js +24 -24
- package/src/configs/eslint-ignores.js +32 -32
- package/src/configs/eslint-recommended.js +4 -4
- package/src/configs/eslint-style.js +12 -12
- package/src/custom/index.js +5 -5
- package/src/custom/instance-of-array.js +44 -44
- package/src/custom/loose-types.js +128 -128
- package/src/custom/no-useless-expression.js +19 -19
- package/src/custom/sequence-expression.js +15 -15
- package/src/index.js +39 -37
- package/src/plugins/eslint-comments.js +19 -19
- package/src/plugins/jsdoc.js +57 -57
- package/src/plugins/json.js +43 -27
- package/src/plugins/node.js +108 -108
- package/src/plugins/package-json.js +25 -25
- package/src/plugins/perfectionist.js +200 -200
- package/src/plugins/promise.js +9 -9
- package/src/plugins/react.js +111 -111
- package/src/plugins/regexp.js +6 -6
- package/src/plugins/sca.js +32 -32
- package/src/plugins/security.js +14 -14
- package/src/plugins/sonarjs.js +11 -20
- package/src/plugins/style.js +236 -236
- package/src/plugins/typescript.js +65 -65
- package/src/plugins/unicorn.js +40 -40
- package/src/plugins/unused-imports.js +25 -25
- package/src/plugins/yml.js +41 -0
- package/src/types.d.ts +80 -80
- package/src/utilities/editorconfig.js +151 -141
- package/src/utilities/eslint-files.js +20 -20
- package/src/utilities/expand-glob.js +34 -34
- package/src/utilities/filesystem.js +30 -30
- package/src/utilities/make-compat.js +6 -6
- package/src/utilities/package.js +29 -29
- package/types/src/plugins/yml.d.ts +5 -0
- package/types/src/utilities/editorconfig.d.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [5.3.1](https://github.com/DarkSheepSoftware/eslint/compare/v5.3.0...v5.3.1) (2024-08-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### 📦 Dependencies
|
|
7
|
+
|
|
8
|
+
* **pkg:** update dependency @stylistic/eslint-plugin to v2.6.2 ([#564](https://github.com/DarkSheepSoftware/eslint/issues/564)) ([6d4296b](https://github.com/DarkSheepSoftware/eslint/commit/6d4296b5f5d24468bd29e640f4651842d959e899))
|
|
9
|
+
* **pkg:** update dependency eslint-plugin-unused-imports to v4.1.2 ([#563](https://github.com/DarkSheepSoftware/eslint/issues/563)) ([464a465](https://github.com/DarkSheepSoftware/eslint/commit/464a465b6293ae94d049f55d311e0ae4d09dd8d8))
|
|
10
|
+
|
|
11
|
+
## [5.3.0](https://github.com/DarkSheepSoftware/eslint/compare/v5.2.1...v5.3.0) (2024-08-08)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### 🌟 Features
|
|
15
|
+
|
|
16
|
+
* Add basic yml support ([ad7dd61](https://github.com/DarkSheepSoftware/eslint/commit/ad7dd610d52b1c1c9c0f9daea39ad5ad185c64d1))
|
|
17
|
+
* Allow editor config to configure yml/indent ([b8655bc](https://github.com/DarkSheepSoftware/eslint/commit/b8655bc56871bebf4fc1157085d9498ebe45b324))
|
|
18
|
+
* Better json formatting ([68da6b2](https://github.com/DarkSheepSoftware/eslint/commit/68da6b266a904e4c780c13b1cc6f08511826111b))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🩹 Fixes
|
|
22
|
+
|
|
23
|
+
* Disable sonar/no-duplicate-string ([8ac453d](https://github.com/DarkSheepSoftware/eslint/commit/8ac453d0e435997283c716596bfed1135467854a))
|
|
24
|
+
* Ignore line count in json files ([cc955da](https://github.com/DarkSheepSoftware/eslint/commit/cc955da408803c5ed1cfde7fd1fceb7735ba9b43))
|
|
25
|
+
* resolve issues in yml files ([315e888](https://github.com/DarkSheepSoftware/eslint/commit/315e8885ccf6f7e010c721166ec57f6449d5a8f9))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### 📦 Dependencies
|
|
29
|
+
|
|
30
|
+
* **pkg:** pin dependencies ([#561](https://github.com/DarkSheepSoftware/eslint/issues/561)) ([e14c5e6](https://github.com/DarkSheepSoftware/eslint/commit/e14c5e609fbe8a5363f620e98a890bc53d7a5c19))
|
|
31
|
+
* **pkg:** update dependency eslint-plugin-perfectionist to v3.1.3 ([#558](https://github.com/DarkSheepSoftware/eslint/issues/558)) ([e911049](https://github.com/DarkSheepSoftware/eslint/commit/e9110492400b1a3880764ce3cccb0be5ade2e918))
|
|
32
|
+
|
|
3
33
|
## [5.2.1](https://github.com/DarkSheepSoftware/eslint/compare/v5.2.0...v5.2.1) (2024-08-07)
|
|
4
34
|
|
|
5
35
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darksheep/eslint",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/DarkSheepSoftware/eslint"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@eslint-community/eslint-plugin-eslint-comments": "4.3.0",
|
|
25
25
|
"@eslint/eslintrc": "3.1.0",
|
|
26
26
|
"@eslint/js": "9.8.0",
|
|
27
|
-
"@stylistic/eslint-plugin": "2.6.
|
|
27
|
+
"@stylistic/eslint-plugin": "2.6.2",
|
|
28
28
|
"@typescript-eslint/eslint-plugin": "8.0.1",
|
|
29
29
|
"@typescript-eslint/parser": "8.0.1",
|
|
30
30
|
"editorconfig": "2.0.0",
|
|
@@ -32,15 +32,17 @@
|
|
|
32
32
|
"eslint-plugin-jsonc": "2.16.0",
|
|
33
33
|
"eslint-plugin-n": "17.10.2",
|
|
34
34
|
"eslint-plugin-package-json": "0.15.2",
|
|
35
|
-
"eslint-plugin-perfectionist": "3.1.
|
|
35
|
+
"eslint-plugin-perfectionist": "3.1.3",
|
|
36
36
|
"eslint-plugin-promise": "7.1.0",
|
|
37
37
|
"eslint-plugin-react": "7.35.0",
|
|
38
38
|
"eslint-plugin-regexp": "2.6.0",
|
|
39
39
|
"eslint-plugin-security": "3.0.1",
|
|
40
40
|
"eslint-plugin-sonarjs": "1.0.4",
|
|
41
41
|
"eslint-plugin-unicorn": "55.0.0",
|
|
42
|
-
"eslint-plugin-unused-imports": "4.
|
|
43
|
-
"
|
|
42
|
+
"eslint-plugin-unused-imports": "4.1.2",
|
|
43
|
+
"eslint-plugin-yml": "1.14.0",
|
|
44
|
+
"jsonc-eslint-parser": "2.4.0",
|
|
45
|
+
"yaml-eslint-parser": "1.2.3"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
46
48
|
"@darksheep/eslint-formatter-github": "2.0.1",
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
"@types/estree": "~1.0.2",
|
|
51
53
|
"@types/node": "~20.14.0",
|
|
52
54
|
"eslint": "~9.8.0",
|
|
53
|
-
"type-fest": "~4.
|
|
55
|
+
"type-fest": "~4.24.0",
|
|
54
56
|
"typescript": "~5.5.0"
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
@@ -1,110 +1,110 @@
|
|
|
1
1
|
/** @type {import('eslint').Linter.RulesRecord} */
|
|
2
2
|
const rules = {
|
|
3
|
-
|
|
3
|
+
'no-else-return': 'error',
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
'radix': 'error',
|
|
6
|
+
'prefer-exponentiation-operator': 'error',
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
'class-methods-use-this': 'off',
|
|
9
|
+
'no-eval': 'error',
|
|
10
|
+
'no-extend-native': 'error',
|
|
11
|
+
'no-implicit-coercion': 'error',
|
|
12
|
+
'no-implied-eval': 'error',
|
|
13
|
+
'no-invalid-this': 'error',
|
|
14
|
+
'no-new-func': 'error',
|
|
15
|
+
'no-proto': 'error',
|
|
16
|
+
'no-script-url': 'error',
|
|
17
|
+
'no-unexpected-multiline': 'error',
|
|
18
|
+
'no-void': 'error',
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
'no-caller': 'error',
|
|
21
|
+
'no-empty': [ 'error', { allowEmptyCatch: true } ],
|
|
22
|
+
'no-empty-function': [ 'error', { allow: [ 'arrowFunctions' ] } ],
|
|
23
|
+
'no-labels': 'error',
|
|
24
|
+
'no-lone-blocks': 'error',
|
|
25
|
+
'no-loop-func': 'error',
|
|
26
|
+
'no-misleading-character-class': 'error',
|
|
27
|
+
'no-new-wrappers': 'error',
|
|
28
|
+
'no-new': 'error',
|
|
29
|
+
'no-undef': [ 'error', { typeof: true } ],
|
|
30
|
+
'no-use-before-define': 'off',
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
32
|
+
'arrow-body-style': [ 'error', 'as-needed' ],
|
|
33
|
+
'constructor-super': 'error',
|
|
34
|
+
'no-class-assign': 'error',
|
|
35
|
+
'no-const-assign': 'error',
|
|
36
|
+
'no-dupe-class-members': 'error',
|
|
37
|
+
'no-duplicate-imports': 'error',
|
|
38
|
+
'no-new-native-nonconstructor': 'error',
|
|
39
|
+
'no-restricted-imports': 'error',
|
|
40
|
+
'no-this-before-super': 'error',
|
|
41
|
+
'no-useless-computed-key': 'error',
|
|
42
|
+
'no-useless-constructor': 'error',
|
|
43
|
+
'no-useless-rename': 'error',
|
|
44
|
+
'no-var': 'error',
|
|
45
|
+
'object-shorthand': [ 'error', 'consistent-as-needed' ],
|
|
46
|
+
'prefer-arrow-callback': [
|
|
47
|
+
'error',
|
|
48
|
+
{
|
|
49
|
+
allowNamedFunctions: false,
|
|
50
|
+
allowUnboundThis: true,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
'prefer-const': 'error',
|
|
54
|
+
'prefer-destructuring': [
|
|
55
|
+
'error',
|
|
56
|
+
{ array: false, object: true },
|
|
57
|
+
{ enforceForRenamedProperties: false },
|
|
58
|
+
],
|
|
59
|
+
'prefer-numeric-literals': 'error',
|
|
60
|
+
'prefer-rest-params': 'error',
|
|
61
|
+
'prefer-spread': 'error',
|
|
62
|
+
'prefer-template': 'error',
|
|
63
|
+
'require-yield': 'error',
|
|
64
|
+
'sort-imports': 'off',
|
|
65
|
+
'symbol-description': 'error',
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
'eqeqeq': [ 'error', 'always', { null: 'ignore' } ],
|
|
68
|
+
'no-extra-bind': 'error',
|
|
69
|
+
'no-loss-of-precision': 'error',
|
|
70
|
+
'no-useless-call': 'error',
|
|
71
|
+
'no-useless-catch': 'error',
|
|
72
|
+
'no-useless-concat': 'error',
|
|
73
|
+
'no-useless-escape': 'error',
|
|
74
|
+
'no-useless-return': 'error',
|
|
75
|
+
'no-multi-str': 'error',
|
|
76
|
+
'no-octal': 'error',
|
|
77
|
+
'no-octal-escape': 'error',
|
|
78
|
+
'no-return-assign': 'error',
|
|
79
|
+
'prefer-promise-reject-errors': 'error',
|
|
80
|
+
'require-await': 'off',
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
'no-shadow-restricted-names': 'error',
|
|
83
|
+
'no-undefined': 'off',
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
'func-name-matching': [ 'error', 'never' ],
|
|
86
|
+
'func-style': [
|
|
87
|
+
'error',
|
|
88
|
+
'declaration',
|
|
89
|
+
{ allowArrowFunctions: true },
|
|
90
|
+
],
|
|
91
|
+
'consistent-this': [ 'error', 'that' ],
|
|
92
|
+
'no-array-constructor': 'error',
|
|
93
|
+
'no-lonely-if': 'error',
|
|
94
|
+
'no-negated-condition': 'error',
|
|
95
|
+
'no-object-constructor': 'error',
|
|
96
|
+
'no-nested-ternary': 'warn',
|
|
97
|
+
'no-unneeded-ternary': 'warn',
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
'one-var': [
|
|
100
|
+
'error',
|
|
101
|
+
'never',
|
|
102
|
+
],
|
|
103
|
+
'operator-assignment': [ 'error', 'always' ],
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
'yoda': 'error',
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
'prefer-object-spread': 'error',
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -112,13 +112,13 @@ const rules = {
|
|
|
112
112
|
* @returns {Promise<import('eslint').Linter.FlatConfig[]>}
|
|
113
113
|
*/
|
|
114
114
|
export async function createEslintBaseConfig() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
return [ {
|
|
116
|
+
name: 'darksheep/base',
|
|
117
|
+
linterOptions: {
|
|
118
|
+
noInlineConfig: false,
|
|
119
|
+
reportUnusedDisableDirectives: true,
|
|
120
|
+
},
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
rules: rules,
|
|
123
|
+
} ];
|
|
124
124
|
}
|
|
@@ -3,29 +3,29 @@
|
|
|
3
3
|
* @returns {import('eslint').Linter.FlatConfig[]}
|
|
4
4
|
*/
|
|
5
5
|
export function createEslintComplexityConfig() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
'max-lines-per-function': [
|
|
20
|
-
'warn',
|
|
21
|
-
{
|
|
22
|
-
max: 120,
|
|
23
|
-
skipBlankLines: true,
|
|
24
|
-
skipComments: true,
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
'max-nested-callbacks': [ 'warn', 3 ],
|
|
28
|
-
'max-params': [ 'error', 5 ],
|
|
6
|
+
return [ {
|
|
7
|
+
name: 'darksheep/complexity',
|
|
8
|
+
rules: {
|
|
9
|
+
'max-depth': [ 'error', 4 ],
|
|
10
|
+
'complexity': 'off',
|
|
11
|
+
'max-lines': [
|
|
12
|
+
'warn',
|
|
13
|
+
{
|
|
14
|
+
max: 512,
|
|
15
|
+
skipBlankLines: true,
|
|
16
|
+
skipComments: true,
|
|
29
17
|
},
|
|
30
|
-
|
|
18
|
+
],
|
|
19
|
+
'max-lines-per-function': [
|
|
20
|
+
'warn',
|
|
21
|
+
{
|
|
22
|
+
max: 120,
|
|
23
|
+
skipBlankLines: true,
|
|
24
|
+
skipComments: true,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
'max-nested-callbacks': [ 'warn', 3 ],
|
|
28
|
+
'max-params': [ 'error', 5 ],
|
|
29
|
+
},
|
|
30
|
+
} ];
|
|
31
31
|
}
|
|
@@ -9,23 +9,23 @@ import { findUp } from '../utilities/filesystem.js';
|
|
|
9
9
|
* @returns {Promise<string[]>}
|
|
10
10
|
*/
|
|
11
11
|
async function getGitignore(root) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
throw error;
|
|
12
|
+
const rootPath = fileURLToPath(root);
|
|
13
|
+
const gitPath = await findUp(rootPath, '.git');
|
|
14
|
+
const path = resolve(gitPath ?? rootPath, '..', '.gitignore');
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const raw = await fs.readFile(path, 'utf8');
|
|
18
|
+
|
|
19
|
+
return raw
|
|
20
|
+
.split(/\r?\n|\r/)
|
|
21
|
+
.filter(Boolean);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') {
|
|
24
|
+
return [];
|
|
28
25
|
}
|
|
26
|
+
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -34,20 +34,20 @@ async function getGitignore(root) {
|
|
|
34
34
|
* @returns {Promise<import('eslint').Linter.FlatConfig[]>}
|
|
35
35
|
*/
|
|
36
36
|
export async function createEslintIgnoresConfig(root) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
const ignores = await getGitignore(root);
|
|
38
|
+
|
|
39
|
+
return [ {
|
|
40
|
+
name: 'darksheep/git-ignores',
|
|
41
|
+
ignores: [
|
|
42
|
+
...ignores,
|
|
43
|
+
|
|
44
|
+
// Some things we always want to ignore
|
|
45
|
+
'.yarn/',
|
|
46
|
+
'.pnp.cjs',
|
|
47
|
+
'.pnp.loader.mjs',
|
|
48
|
+
'.git/',
|
|
49
|
+
'coverage/',
|
|
50
|
+
'node_modules/',
|
|
51
|
+
],
|
|
52
|
+
} ];
|
|
53
53
|
}
|
|
@@ -5,8 +5,8 @@ import js from '@eslint/js';
|
|
|
5
5
|
* @returns {Promise<import('eslint').Linter.FlatConfig[]>}
|
|
6
6
|
*/
|
|
7
7
|
export async function createEslintRecommendsConfig() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
return [ {
|
|
9
|
+
name: 'eslint/recomended',
|
|
10
|
+
...js.configs.recommended,
|
|
11
|
+
} ];
|
|
12
12
|
}
|
|
@@ -2,12 +2,12 @@ import { createEditorOverrides } from '../utilities/editorconfig.js';
|
|
|
2
2
|
|
|
3
3
|
/** @type {import('eslint').Linter.RulesRecord} */
|
|
4
4
|
const rules = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
'dot-notation': 'error',
|
|
6
|
+
'curly': 'error',
|
|
7
|
+
'unicode-bom': [ 'error', 'never' ],
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
'no-div-regex': 'error',
|
|
10
|
+
'no-control-regex': 'error',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -16,11 +16,11 @@ const rules = {
|
|
|
16
16
|
* @returns {Promise<import('eslint').Linter.FlatConfig[]>}
|
|
17
17
|
*/
|
|
18
18
|
export async function createStyleConfig(root) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return [
|
|
20
|
+
{
|
|
21
|
+
name: 'style/core',
|
|
22
|
+
rules: rules,
|
|
23
|
+
},
|
|
24
|
+
...await createEditorOverrides(root),
|
|
25
|
+
];
|
|
26
26
|
}
|
package/src/custom/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import noUselessExpression from './no-useless-expression.js';
|
|
|
3
3
|
import sequenceExpression from './sequence-expression.js';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
rules: {
|
|
7
|
+
'loose-types': looseTypes,
|
|
8
|
+
'no-useless-expression': noUselessExpression,
|
|
9
|
+
'sequence-expression': sequenceExpression,
|
|
10
|
+
},
|
|
11
11
|
};
|
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
* @returns {import('eslint').Rule.RuleListener}
|
|
4
4
|
*/
|
|
5
5
|
const preferInstance = (context) => ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {import('estree').CallExpression} node The AST function node
|
|
8
|
+
* @returns {void}
|
|
9
|
+
*/
|
|
10
|
+
'CallExpression[callee.object.name = "Array"][callee.property.name = "isArray"]': (node) => {
|
|
11
|
+
const message = 'Use `instanceof Array` instead of `Array.isArray()`';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (node.arguments.length !== 1) {
|
|
14
|
+
return context.report({ node, message });
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const left = context.sourceCode.getText(node.arguments[0]);
|
|
18
|
+
/** @type {import('eslint').Rule.ReportFixer} */
|
|
19
|
+
const fix = (fixer) => fixer.replaceText(node, `${left} instanceof Array`);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
context.report({ node, message, fix });
|
|
22
|
+
},
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -27,46 +27,46 @@ const preferInstance = (context) => ({
|
|
|
27
27
|
* @returns {import('eslint').Rule.RuleListener}
|
|
28
28
|
*/
|
|
29
29
|
const preferIsArray = (context) => ({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @param {import('estree').BinaryExpression} node The AST function node
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
34
|
+
'BinaryExpression[operator="instanceof"][right.type="Identifier"][right.name="Array"]': (node) => {
|
|
35
|
+
const message = 'Use `Array.isArray()` instead of `instanceof Array`';
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const argument = context.sourceCode.getText(node.left);
|
|
38
|
+
/** @type {import('eslint').Rule.ReportFixer} */
|
|
39
|
+
const fix = (fixer) => fixer.replaceText(node, `Array.isArray(${argument})`);
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
context.report({ node, message, fix });
|
|
42
|
+
},
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
/** @type {import('eslint').Rule.RuleModule} */
|
|
46
46
|
const rule = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
],
|
|
57
|
-
},
|
|
47
|
+
meta: {
|
|
48
|
+
type: 'suggestion',
|
|
49
|
+
fixable: 'code',
|
|
50
|
+
schema: [
|
|
51
|
+
{
|
|
52
|
+
type: 'string',
|
|
53
|
+
enum: [
|
|
54
|
+
'instanceof',
|
|
55
|
+
'isarray',
|
|
58
56
|
],
|
|
59
|
-
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
create: function (context) {
|
|
62
|
+
const [ option = 'instanceof' ] = context.options;
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
if (option === 'instanceof') {
|
|
65
|
+
return preferInstance(context);
|
|
66
|
+
}
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
return preferIsArray(context);
|
|
69
|
+
},
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export default rule;
|