flatlint 5.0.0 → 5.2.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 +11 -0
- package/lib/compare/compare.js +0 -1
- package/lib/compare/matchers/array.js +4 -0
- package/lib/plugins/add-missing-round-brace/index.js +4 -1
- package/lib/plugins/add-missing-square-brace/index.js +1 -0
- package/lib/plugins/remove-useless-comma/index.js +1 -1
- package/lib/plugins.js +1 -1
- package/lib/runner/path.js +14 -0
- package/lib/types/types.js +13 -4
- package/package.json +4 -3
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2026.03.11, v5.2.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 282978f flatlint: add-missing-round-brace: remove-useless-assign: improve support
|
|
5
|
+
- 111269b flatlint: superc8 v12.3.1
|
|
6
|
+
|
|
7
|
+
2026.02.18, v5.1.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 5262747 flatlint: add-missing-square-brace: inner
|
|
11
|
+
|
|
1
12
|
2026.02.17, v5.0.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/lib/compare/compare.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
OK,
|
|
6
6
|
NOT_OK,
|
|
7
7
|
isTemplateArray,
|
|
8
|
+
closeCurlyBrace,
|
|
8
9
|
} from '#types';
|
|
9
10
|
import {equal} from '../equal.js';
|
|
10
11
|
|
|
@@ -26,6 +27,9 @@ export const collect = ({currentTokenIndex, tokens, nextTemplateToken = semicolo
|
|
|
26
27
|
if (equal(token, nextTemplateToken))
|
|
27
28
|
break;
|
|
28
29
|
|
|
30
|
+
if (equal(token, closeCurlyBrace))
|
|
31
|
+
break;
|
|
32
|
+
|
|
29
33
|
if (equal(token, closeSquareBrace))
|
|
30
34
|
break;
|
|
31
35
|
}
|
|
@@ -22,7 +22,9 @@ export const match = () => ({
|
|
|
22
22
|
'if (__a(__args)': (vars, path) => {
|
|
23
23
|
return path.isNextKeyword();
|
|
24
24
|
},
|
|
25
|
-
'{__a} = __expr;': (vars, path) =>
|
|
25
|
+
'{__a} = __expr;': (vars, path) => {
|
|
26
|
+
return !path.isPrevAnyDeclarationKeyword();
|
|
27
|
+
},
|
|
26
28
|
'{__a} = __expr': (vars, path) => {
|
|
27
29
|
return path.isNextKeyword();
|
|
28
30
|
},
|
|
@@ -107,3 +109,4 @@ export const replace = () => ({
|
|
|
107
109
|
'__a(__b(__c);': '__a(__b(__c));',
|
|
108
110
|
'__a([__b, __c]) =>': '__a(([__b, __c]) =>',
|
|
109
111
|
});
|
|
112
|
+
|
|
@@ -13,7 +13,7 @@ export const report = () => `Remove useless ','`;
|
|
|
13
13
|
export const match = () => ({
|
|
14
14
|
'__a(__args) {},': (vars, path) => {
|
|
15
15
|
for (const token of path.getAllPrev()) {
|
|
16
|
-
if (isIdentifier(token, 'class'))
|
|
16
|
+
if (isIdentifier(token, {name: 'class'}))
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
|
package/lib/plugins.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/i
|
|
|
15
15
|
import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
|
|
16
16
|
import * as removeUselessComma from './plugins/remove-useless-comma/index.js';
|
|
17
17
|
import * as removeUselessArrow from './plugins/remove-useless-arrow/index.js';
|
|
18
|
-
import * as removeUselessAssign from '
|
|
18
|
+
import * as removeUselessAssign from '#plugin-remove-useless-assign';
|
|
19
19
|
import * as removeUselessDot from './plugins/remove-useless-dot/index.js';
|
|
20
20
|
import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
|
|
21
21
|
import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
|
package/lib/runner/path.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
isNewLine,
|
|
13
13
|
isWhiteSpace,
|
|
14
14
|
isTemplateHead,
|
|
15
|
+
isAnyDeclarationKeyword,
|
|
15
16
|
} from '#types';
|
|
16
17
|
import {equalTemplate} from '../compare/equal.js';
|
|
17
18
|
|
|
@@ -39,6 +40,10 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
39
40
|
tokens,
|
|
40
41
|
start,
|
|
41
42
|
}),
|
|
43
|
+
isPrevAnyDeclarationKeyword: createIsPrevAnyDeclarationKeyword({
|
|
44
|
+
tokens,
|
|
45
|
+
start,
|
|
46
|
+
}),
|
|
42
47
|
isPrevKeyword: createIsPrevKeyword({
|
|
43
48
|
tokens,
|
|
44
49
|
start,
|
|
@@ -185,6 +190,15 @@ const createGetPrev = ({tokens, start}) => () => {
|
|
|
185
190
|
});
|
|
186
191
|
};
|
|
187
192
|
|
|
193
|
+
const createIsPrevAnyDeclarationKeyword = ({tokens, start}) => () => {
|
|
194
|
+
const prev = getPrev({
|
|
195
|
+
tokens,
|
|
196
|
+
start,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return isAnyDeclarationKeyword(prev);
|
|
200
|
+
};
|
|
201
|
+
|
|
188
202
|
const createIsPrevDeclarationKeyword = ({tokens, start}) => () => {
|
|
189
203
|
const prev = getPrev({
|
|
190
204
|
tokens,
|
package/lib/types/types.js
CHANGED
|
@@ -37,7 +37,7 @@ export const isIdentifier = (token, newToken) => {
|
|
|
37
37
|
if (!newToken)
|
|
38
38
|
return true;
|
|
39
39
|
|
|
40
|
-
const newValue = newToken.value || newToken;
|
|
40
|
+
const newValue = newToken.name || newToken.value || newToken;
|
|
41
41
|
|
|
42
42
|
return newValue === token.value;
|
|
43
43
|
};
|
|
@@ -68,9 +68,6 @@ export const isKeyword = (token, names) => {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
export const isDeclarationKeyword = (token, name) => {
|
|
71
|
-
if (!token)
|
|
72
|
-
return false;
|
|
73
|
-
|
|
74
71
|
const {value} = token;
|
|
75
72
|
|
|
76
73
|
if (!keyword.isDeclarationKeyword(value))
|
|
@@ -79,6 +76,18 @@ export const isDeclarationKeyword = (token, name) => {
|
|
|
79
76
|
return isIdentifier(token, name);
|
|
80
77
|
};
|
|
81
78
|
|
|
79
|
+
export const isAnyDeclarationKeyword = (token, name) => {
|
|
80
|
+
if (!token)
|
|
81
|
+
return false;
|
|
82
|
+
|
|
83
|
+
const {value} = token;
|
|
84
|
+
|
|
85
|
+
if (keyword.isDeclarationKeyword(value))
|
|
86
|
+
return true;
|
|
87
|
+
|
|
88
|
+
return keyword.isModuleDeclarationKeyword(value);
|
|
89
|
+
};
|
|
90
|
+
|
|
82
91
|
export const isOneOfIdentifiers = (token, keywords) => {
|
|
83
92
|
for (const keyword of keywords) {
|
|
84
93
|
if (isIdentifier(token, keyword))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatlint",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "JavaScript tokens-based linter",
|
|
5
5
|
"main": "lib/flatlint.js",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"#compare": "./lib/compare/compare.js",
|
|
18
18
|
"#compare/values": "./lib/compare/values.js",
|
|
19
19
|
"#runner": "./lib/runner/runner.js",
|
|
20
|
-
"#flatlint": "./lib/flatlint.js"
|
|
20
|
+
"#flatlint": "./lib/flatlint.js",
|
|
21
|
+
"#plugin-remove-useless-assign": "./lib/plugins/remove-useless-assign/index.js"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
24
|
"lint": "madrun lint",
|
|
@@ -66,7 +67,6 @@
|
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@putout/test": "^15.0.0",
|
|
69
|
-
"c8": "^10.1.2",
|
|
70
70
|
"eslint": "^10.0.0",
|
|
71
71
|
"eslint-plugin-putout": "^31.0.0",
|
|
72
72
|
"madrun": "^13.0.0",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"montag": "^1.0.0",
|
|
75
75
|
"nodemon": "^3.0.1",
|
|
76
76
|
"putout": "^42.0.3",
|
|
77
|
+
"superc8": "^12.3.1",
|
|
77
78
|
"supertape": "^12.0.0"
|
|
78
79
|
},
|
|
79
80
|
"engines": {
|