flatlint 1.88.0 → 1.90.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/README.md +3 -0
- package/lib/compare/collect-expression.js +3 -0
- package/lib/compare/compare.js +13 -2
- package/lib/plugins/add-missing-assign/index.js +3 -3
- package/lib/plugins/add-missing-round-brace/index.js +1 -0
- package/lib/plugins/add-missing-semicolon/index.js +3 -0
- package/lib/plugins/remove-useless-round-brace/index.js +23 -0
- package/lib/runner/replacer.js +2 -1
- package/lib/types/types.js +0 -4
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
package/lib/compare/compare.js
CHANGED
|
@@ -23,17 +23,27 @@ export const compare = (source, template, {index = 0} = {}) => {
|
|
|
23
23
|
|
|
24
24
|
const n = tokens.length - 1;
|
|
25
25
|
const templateTokensLength = templateTokens.length;
|
|
26
|
+
|
|
26
27
|
let isEqual = false;
|
|
27
28
|
let start = 0;
|
|
28
29
|
let end = 0;
|
|
29
30
|
let delta = 0;
|
|
30
31
|
|
|
31
32
|
for (; index < n; index++) {
|
|
33
|
+
const indexCheck = index;
|
|
32
34
|
let skip = 0;
|
|
33
35
|
|
|
34
|
-
for (
|
|
36
|
+
for (const [templateIndex] of templateTokens.entries()) {
|
|
35
37
|
let currentTokenIndex = index + templateIndex - skip;
|
|
36
38
|
|
|
39
|
+
/* c8 ignore start */
|
|
40
|
+
if (indexCheck > index + 1)
|
|
41
|
+
throw Error(`index should never decrease more then on one: ${index} > ${indexCheck}`);
|
|
42
|
+
|
|
43
|
+
if (index < 0)
|
|
44
|
+
throw Error(`index should never be < zero: ${index}`);
|
|
45
|
+
/* c8 ignore end */
|
|
46
|
+
|
|
37
47
|
if (currentTokenIndex > n)
|
|
38
48
|
return [NOT_OK];
|
|
39
49
|
|
|
@@ -64,10 +74,11 @@ export const compare = (source, template, {index = 0} = {}) => {
|
|
|
64
74
|
nextTemplateToken: templateTokens[templateIndex + 1],
|
|
65
75
|
});
|
|
66
76
|
|
|
67
|
-
if (indexOfExpressionEnd >= n
|
|
77
|
+
if (indexOfExpressionEnd >= n) {
|
|
68
78
|
end = indexOfExpressionEnd;
|
|
69
79
|
currentTokenIndex = end;
|
|
70
80
|
} else if (templateIndex === templateTokensLength - 1) {
|
|
81
|
+
end = indexOfExpressionEnd;
|
|
71
82
|
currentTokenIndex = end;
|
|
72
83
|
} else {
|
|
73
84
|
delta = indexOfExpressionEnd - currentTokenIndex;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assign,
|
|
3
|
+
isKeyword,
|
|
3
4
|
isOneOfKeywords,
|
|
4
5
|
isOneOfPunctuators,
|
|
5
6
|
semicolon,
|
|
@@ -9,10 +10,9 @@ export const report = () => 'Add missing assign';
|
|
|
9
10
|
|
|
10
11
|
export const match = () => ({
|
|
11
12
|
'__x __a __expr': ({__expr, __x}, path) => {
|
|
12
|
-
|
|
13
|
-
return false;
|
|
13
|
+
const [first] = __expr;
|
|
14
14
|
|
|
15
|
-
if (
|
|
15
|
+
if (isKeyword(first))
|
|
16
16
|
return false;
|
|
17
17
|
|
|
18
18
|
if (!isOneOfKeywords(__x, ['const', 'let', 'var']))
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
closeCurlyBrace,
|
|
9
9
|
isOnlyWhitespaces,
|
|
10
10
|
isKeyword,
|
|
11
|
+
openRoundBrace,
|
|
11
12
|
} from '#types';
|
|
12
13
|
|
|
13
14
|
export const report = () => 'Add missing semicolon';
|
|
@@ -25,6 +26,8 @@ export const match = () => ({
|
|
|
25
26
|
semicolon,
|
|
26
27
|
openCurlyBrace,
|
|
27
28
|
question,
|
|
29
|
+
closeRoundBrace,
|
|
30
|
+
openRoundBrace,
|
|
28
31
|
];
|
|
29
32
|
|
|
30
33
|
return !path.isNextPunctuator(punctuators);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
assign,
|
|
2
3
|
hasRoundBraces,
|
|
3
4
|
isBalancedRoundBraces,
|
|
5
|
+
isPunctuator,
|
|
6
|
+
openRoundBrace,
|
|
4
7
|
} from '#types';
|
|
5
8
|
|
|
6
9
|
export const report = () => 'Remove useless round brace';
|
|
@@ -12,9 +15,29 @@ export const match = () => ({
|
|
|
12
15
|
|
|
13
16
|
return !isBalancedRoundBraces(__expr);
|
|
14
17
|
},
|
|
18
|
+
|
|
19
|
+
'__a);': (vars, path) => {
|
|
20
|
+
let result = false;
|
|
21
|
+
|
|
22
|
+
for (const current of path.getAllPrev()) {
|
|
23
|
+
if (isPunctuator(current, openRoundBrace)) {
|
|
24
|
+
result = false;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isPunctuator(current, assign)) {
|
|
29
|
+
result = true;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
},
|
|
15
36
|
});
|
|
16
37
|
|
|
17
38
|
export const replace = () => ({
|
|
18
39
|
'const __a = __expr);': 'const __a = __expr;',
|
|
19
40
|
'from "__b")': 'from "__b"',
|
|
41
|
+
'__a);': '__a;',
|
|
20
42
|
});
|
|
43
|
+
|
package/lib/runner/replacer.js
CHANGED
|
@@ -22,6 +22,7 @@ export const replace = (tokens, {fix, rule, plugin}) => {
|
|
|
22
22
|
let index = 0;
|
|
23
23
|
|
|
24
24
|
while (index < tokens.length - 1) {
|
|
25
|
+
log(`compare: ${rule}: ${from} -> ${to}`);
|
|
25
26
|
const [ok, start, end] = compare(tokens, from, {
|
|
26
27
|
index,
|
|
27
28
|
});
|
|
@@ -52,7 +53,7 @@ export const replace = (tokens, {fix, rule, plugin}) => {
|
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
if (fix) {
|
|
55
|
-
log(
|
|
56
|
+
log(`fix: ${rule}: ${from} -> ${to}`);
|
|
56
57
|
|
|
57
58
|
const preparedTo = prepare(to);
|
|
58
59
|
const waysTo = findVarsWays(preparedTo);
|
package/lib/types/types.js
CHANGED
|
@@ -29,12 +29,8 @@ export const isIdentifier = (token, newToken) => {
|
|
|
29
29
|
export const isStringLiteral = ({type}) => type === 'StringLiteral';
|
|
30
30
|
export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
|
|
31
31
|
export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
|
|
32
|
-
export const notWhiteSpace = (a) => !isWhiteSpace(a);
|
|
33
32
|
|
|
34
33
|
export const isKeyword = (token, name) => {
|
|
35
|
-
if (!token)
|
|
36
|
-
return false;
|
|
37
|
-
|
|
38
34
|
const {value} = token;
|
|
39
35
|
|
|
40
36
|
if (!keyword.isKeyword(value))
|