flatlint 1.31.0 → 1.32.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 +5 -0
- package/lib/compare/collect-expression.js +8 -0
- package/lib/plugins/add-missing-semicolon/index.js +1 -15
- 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 +0 -3
- package/lib/types/types.js +0 -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
|
});
|
|
@@ -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
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
|
|
|
@@ -19,9 +16,6 @@ export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
|
|
|
19
16
|
export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
|
|
20
17
|
export const notWhiteSpace = (a) => !isWhiteSpace(a);
|
|
21
18
|
export const isPunctuator = (token, punctuator) => {
|
|
22
|
-
if (!token)
|
|
23
|
-
return false;
|
|
24
|
-
|
|
25
19
|
if (token.type !== 'Punctuator')
|
|
26
20
|
return false;
|
|
27
21
|
|