flatlint 1.31.0 → 1.33.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 +10 -0
- package/lib/compare/collect-expression.js +8 -0
- package/lib/plugins/add-missing-semicolon/index.js +1 -15
- package/lib/plugins/convert-comma-to-semicolon/index.js +15 -0
- package/lib/plugins/remove-useless-comma/index.js +0 -4
- package/lib/plugins/remove-useless-round-brace/index.js +0 -9
- package/lib/runner/path.js +16 -5
- package/lib/types/types.js +15 -6
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
closeCurlyBrace,
|
|
3
3
|
closeRoundBrace,
|
|
4
4
|
comma,
|
|
5
|
+
openRoundBrace,
|
|
5
6
|
semicolon,
|
|
6
7
|
} from '#types';
|
|
7
8
|
import {equal} from './equal.js';
|
|
@@ -9,6 +10,7 @@ import {equal} from './equal.js';
|
|
|
9
10
|
export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken = semicolon}) => {
|
|
10
11
|
const n = tokens.length;
|
|
11
12
|
let index = currentTokenIndex;
|
|
13
|
+
let roundBracesBalance = 0;
|
|
12
14
|
|
|
13
15
|
for (; index < n; index++) {
|
|
14
16
|
const token = tokens[index];
|
|
@@ -25,7 +27,13 @@ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken
|
|
|
25
27
|
if (equal(token, closeCurlyBrace))
|
|
26
28
|
break;
|
|
27
29
|
|
|
30
|
+
if (equal(token, openRoundBrace))
|
|
31
|
+
++roundBracesBalance;
|
|
32
|
+
|
|
28
33
|
if (equal(token, closeRoundBrace))
|
|
34
|
+
--roundBracesBalance;
|
|
35
|
+
|
|
36
|
+
if (roundBracesBalance < 0)
|
|
29
37
|
break;
|
|
30
38
|
}
|
|
31
39
|
|
|
@@ -19,9 +19,6 @@ export const match = () => ({
|
|
|
19
19
|
if (path.isNextPunctuator(openCurlyBrace))
|
|
20
20
|
return false;
|
|
21
21
|
|
|
22
|
-
if (path.isPrevIdentifier('function'))
|
|
23
|
-
return false;
|
|
24
|
-
|
|
25
22
|
for (const token of path.getAllNext()) {
|
|
26
23
|
if (isPunctuator(token, semicolon))
|
|
27
24
|
return false;
|
|
@@ -42,15 +39,7 @@ export const match = () => ({
|
|
|
42
39
|
if (path.isNextPunctuator(openCurlyBrace))
|
|
43
40
|
return false;
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
|
|
48
|
-
for (const token of path.getAllNext()) {
|
|
49
|
-
if (isPunctuator(token, semicolon))
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return true;
|
|
42
|
+
return !path.isPrevIdentifier('function');
|
|
54
43
|
},
|
|
55
44
|
'})': (vars, path) => {
|
|
56
45
|
if (path.isNextPunctuator(arrow))
|
|
@@ -59,9 +48,6 @@ export const match = () => ({
|
|
|
59
48
|
if (path.isNextPunctuator(comma))
|
|
60
49
|
return false;
|
|
61
50
|
|
|
62
|
-
if (path.isCurrentPunctuator(comma))
|
|
63
|
-
return false;
|
|
64
|
-
|
|
65
51
|
return !path.isNextPunctuator(semicolon);
|
|
66
52
|
},
|
|
67
53
|
});
|
|
@@ -10,10 +10,25 @@ export const match = () => ({
|
|
|
10
10
|
|
|
11
11
|
return true;
|
|
12
12
|
},
|
|
13
|
+
'let __a = __b,': check,
|
|
14
|
+
'var __a = __b': check,
|
|
15
|
+
'let __a,': check,
|
|
16
|
+
'var __a,': check,
|
|
13
17
|
});
|
|
14
18
|
|
|
15
19
|
export const replace = () => ({
|
|
20
|
+
'var __a,': 'var __a;',
|
|
21
|
+
'let __a,': 'let __a;',
|
|
22
|
+
'var __a = __b,': 'var __a = __b;',
|
|
23
|
+
'let __a = __b,': 'let __a = __b;',
|
|
16
24
|
'const __a = __b,': 'const __a = __b;',
|
|
17
25
|
'__a(__args),': '__a(__args);',
|
|
18
26
|
'return __expr,': 'return __expr;',
|
|
19
27
|
});
|
|
28
|
+
|
|
29
|
+
const check = (vars, path) => {
|
|
30
|
+
if (!path.isNext())
|
|
31
|
+
return true;
|
|
32
|
+
|
|
33
|
+
return path.isNextOperator();
|
|
34
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
closeCurlyBrace,
|
|
3
|
-
closeRoundBrace,
|
|
4
3
|
isIdentifier,
|
|
5
4
|
isPunctuator,
|
|
6
5
|
openSquireBrace,
|
|
@@ -26,9 +25,6 @@ export const match = () => ({
|
|
|
26
25
|
if (!path.isNext())
|
|
27
26
|
return true;
|
|
28
27
|
|
|
29
|
-
if (path.isNextPunctuator(closeRoundBrace))
|
|
30
|
-
return true;
|
|
31
|
-
|
|
32
28
|
if (path.isNextPunctuator(closeCurlyBrace))
|
|
33
29
|
return false;
|
|
34
30
|
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import {isPunctuator, openRoundBrace} from '#types';
|
|
2
|
-
|
|
3
1
|
export const report = () => 'Remove useless round brace';
|
|
4
2
|
|
|
5
|
-
export const match = () => ({
|
|
6
|
-
'const __a = __expr);': ({__expr}) => {
|
|
7
|
-
const [, brace] = __expr;
|
|
8
|
-
return !isPunctuator(brace, openRoundBrace);
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
|
|
12
3
|
export const replace = () => ({
|
|
13
4
|
'const __a = __expr);': 'const __a = __expr;',
|
|
14
5
|
'from "__b")': 'from "__b"',
|
package/lib/runner/path.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isIdentifier,
|
|
3
3
|
isNewLine,
|
|
4
|
+
isOperator,
|
|
4
5
|
isPunctuator,
|
|
5
6
|
isWhiteSpace,
|
|
6
7
|
} from '#types';
|
|
@@ -21,6 +22,10 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
21
22
|
tokens,
|
|
22
23
|
end,
|
|
23
24
|
}),
|
|
25
|
+
isNextOperator: createIsNextOperator({
|
|
26
|
+
tokens,
|
|
27
|
+
end,
|
|
28
|
+
}),
|
|
24
29
|
isNextPunctuator: createIsNextPunctuator({
|
|
25
30
|
tokens,
|
|
26
31
|
end,
|
|
@@ -59,10 +64,10 @@ const next = ({tokens, end}) => {
|
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
const createIsNext = ({tokens, end}) => () => {
|
|
62
|
-
return next({
|
|
67
|
+
return Boolean(next({
|
|
63
68
|
tokens,
|
|
64
69
|
end,
|
|
65
|
-
});
|
|
70
|
+
}));
|
|
66
71
|
};
|
|
67
72
|
|
|
68
73
|
const createIsNextIdentifier = ({tokens, end}) => (value) => {
|
|
@@ -71,12 +76,18 @@ const createIsNextIdentifier = ({tokens, end}) => (value) => {
|
|
|
71
76
|
end,
|
|
72
77
|
});
|
|
73
78
|
|
|
74
|
-
if (!current)
|
|
75
|
-
return false;
|
|
76
|
-
|
|
77
79
|
return isIdentifier(current, value);
|
|
78
80
|
};
|
|
79
81
|
|
|
82
|
+
const createIsNextOperator = ({tokens, end}) => () => {
|
|
83
|
+
const current = next({
|
|
84
|
+
tokens,
|
|
85
|
+
end,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return isOperator(current);
|
|
89
|
+
};
|
|
90
|
+
|
|
80
91
|
const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
81
92
|
const current = next({
|
|
82
93
|
tokens,
|
package/lib/types/types.js
CHANGED
|
@@ -2,9 +2,6 @@ const isString = (a) => typeof a === 'string';
|
|
|
2
2
|
|
|
3
3
|
export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
|
|
4
4
|
export const isIdentifier = (token, value = token.value) => {
|
|
5
|
-
if (!token)
|
|
6
|
-
return false;
|
|
7
|
-
|
|
8
5
|
const {type} = token;
|
|
9
6
|
const is = type === 'IdentifierName';
|
|
10
7
|
|
|
@@ -18,10 +15,22 @@ export const isStringLiteral = ({type}) => type === 'StringLiteral';
|
|
|
18
15
|
export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
|
|
19
16
|
export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
|
|
20
17
|
export const notWhiteSpace = (a) => !isWhiteSpace(a);
|
|
21
|
-
export const
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export const isOperator = (token) => {
|
|
19
|
+
const operators = [
|
|
20
|
+
'var',
|
|
21
|
+
'let',
|
|
22
|
+
'const',
|
|
23
|
+
'export',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for (const operator of operators) {
|
|
27
|
+
if (isIdentifier(token, operator))
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
24
30
|
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
export const isPunctuator = (token, punctuator) => {
|
|
25
34
|
if (token.type !== 'Punctuator')
|
|
26
35
|
return false;
|
|
27
36
|
|