flatlint 1.21.1 → 1.22.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 +9 -0
- package/lib/compare/collect-args.js +0 -6
- package/lib/compare/compare.js +8 -6
- package/lib/plugins/add-missing-round-braces/index.js +4 -8
- package/lib/plugins/add-missing-semicolon/index.js +19 -0
- package/lib/plugins/add-missing-square-brace/index.js +4 -8
- package/lib/plugins/convert-comma-to-semicolon/index.js +0 -12
- package/lib/plugins/remove-useless-semicolon/index.js +1 -1
- package/lib/plugins/wrap-assignment-in-parens/index.js +3 -5
- package/lib/runner/path.js +19 -0
- package/lib/runner/replacer.js +1 -0
- package/lib/types/types.js +6 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -132,6 +132,15 @@ const a = class {
|
|
|
132
132
|
|
|
133
133
|
</details>
|
|
134
134
|
|
|
135
|
+
<details><summary>add missing semicolon</summary>
|
|
136
|
+
|
|
137
|
+
```diff
|
|
138
|
+
-const a = 5
|
|
139
|
+
+const a = 5;
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
</details>
|
|
143
|
+
|
|
135
144
|
## Template literals
|
|
136
145
|
|
|
137
146
|
**FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
|
|
@@ -18,12 +18,6 @@ export const collectArgs = ({currentTokenIndex, tokens, nextTemplateToken = clos
|
|
|
18
18
|
|
|
19
19
|
if (equal(token, closeRoundBrace))
|
|
20
20
|
break;
|
|
21
|
-
|
|
22
|
-
if (equal(token, nextTemplateToken))
|
|
23
|
-
break;
|
|
24
|
-
|
|
25
|
-
if (equal(token, closeSquareBrace))
|
|
26
|
-
break;
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
return [
|
package/lib/compare/compare.js
CHANGED
|
@@ -30,12 +30,6 @@ export const compare = (source, template) => {
|
|
|
30
30
|
for (let index = 0; index < n; index++) {
|
|
31
31
|
for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
|
|
32
32
|
const currentTokenIndex = index + templateIndex - skip;
|
|
33
|
-
|
|
34
|
-
if (currentTokenIndex > n) {
|
|
35
|
-
isEqual = false;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
const templateToken = templateTokens[templateIndex];
|
|
40
34
|
const currentToken = tokens[currentTokenIndex];
|
|
41
35
|
|
|
@@ -61,6 +55,13 @@ export const compare = (source, template) => {
|
|
|
61
55
|
nextTemplateToken: templateTokens[templateIndex + 1],
|
|
62
56
|
});
|
|
63
57
|
|
|
58
|
+
debugger;
|
|
59
|
+
|
|
60
|
+
if (n === indexOfExpressionEnd) {
|
|
61
|
+
end = indexOfExpressionEnd;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
64
65
|
delta = indexOfExpressionEnd - currentTokenIndex;
|
|
65
66
|
index = indexOfExpressionEnd - templateIndex;
|
|
66
67
|
} else if (isTemplateArrayToken(templateToken)) {
|
|
@@ -110,3 +111,4 @@ function compareAll(a, b) {
|
|
|
110
111
|
|
|
111
112
|
return false;
|
|
112
113
|
}
|
|
114
|
+
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
return 'Add missing round braces';
|
|
3
|
-
}
|
|
1
|
+
export const report = () => 'Add missing round braces';
|
|
4
2
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
}
|
|
3
|
+
export const replace = () => ({
|
|
4
|
+
'if __a > __b': 'if (__a > __b)',
|
|
5
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {isNewLine, isPunctuator} from '#types';
|
|
2
|
+
|
|
3
|
+
export const report = () => 'Add missing semicolon';
|
|
4
|
+
|
|
5
|
+
export const match = () => ({
|
|
6
|
+
'const __a = __expr': (vars, path) => {
|
|
7
|
+
let last;
|
|
8
|
+
|
|
9
|
+
for (const token of path.getNext()) {
|
|
10
|
+
last = token;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return !isPunctuator(last, ';');
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const replace = () => ({
|
|
18
|
+
'const __a = __expr': 'const __a = __expr;',
|
|
19
|
+
});
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
return 'Add missing square brace';
|
|
3
|
-
}
|
|
1
|
+
export const report = () => 'Add missing square brace';
|
|
4
2
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
}
|
|
3
|
+
export const replace = () => ({
|
|
4
|
+
'[__array;': '[__array];',
|
|
5
|
+
});
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {isIdentifier} from '#types';
|
|
2
|
-
|
|
3
1
|
export const report = () => 'Use semicolon instead of trailing comma';
|
|
4
|
-
export const match = () => ({
|
|
5
|
-
'__a: __expr;': (vars, path) => {
|
|
6
|
-
for (const token of path.getPrev()) {
|
|
7
|
-
if (isIdentifier(token, 'interface'))
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return true;
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
2
|
export const replace = () => ({
|
|
15
3
|
'const __a = __b,': 'const __a = __b;',
|
|
16
4
|
});
|
|
@@ -5,7 +5,7 @@ export const report = () => 'Remove useless semicolon';
|
|
|
5
5
|
export const match = () => ({
|
|
6
6
|
'__a: __expr;': (vars, path) => {
|
|
7
7
|
for (const token of path.getPrev()) {
|
|
8
|
-
if (isIdentifier(token
|
|
8
|
+
if (isIdentifier(token, 'interface'))
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -2,8 +2,6 @@ export function report() {
|
|
|
2
2
|
return `Wrap the assignment in parentheses after '&&'`;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
}
|
|
5
|
+
export const replace = () => ({
|
|
6
|
+
'__a && __b = __c': '__a && (__b = __c)',
|
|
7
|
+
});
|
package/lib/runner/path.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import {isNewLine} from '#types';
|
|
2
|
+
|
|
1
3
|
export const createPath = ({tokens, start}) => ({
|
|
2
4
|
getPrev: createGetPrev({
|
|
3
5
|
tokens,
|
|
4
6
|
start,
|
|
5
7
|
}),
|
|
8
|
+
getNext: createGetNext({
|
|
9
|
+
tokens,
|
|
10
|
+
start,
|
|
11
|
+
}),
|
|
6
12
|
});
|
|
7
13
|
|
|
8
14
|
function createGetPrev({tokens, start}) {
|
|
@@ -12,3 +18,16 @@ function createGetPrev({tokens, start}) {
|
|
|
12
18
|
}
|
|
13
19
|
};
|
|
14
20
|
}
|
|
21
|
+
|
|
22
|
+
function createGetNext({tokens, start}) {
|
|
23
|
+
return function*() {
|
|
24
|
+
for (let i = start; i < tokens.length; ++i) {
|
|
25
|
+
const current = tokens[i];
|
|
26
|
+
|
|
27
|
+
if (isNewLine(current))
|
|
28
|
+
continue;
|
|
29
|
+
|
|
30
|
+
yield current;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
package/lib/runner/replacer.js
CHANGED
package/lib/types/types.js
CHANGED
|
@@ -15,7 +15,12 @@ export const isStringLiteral = ({type}) => type === 'StringLiteral';
|
|
|
15
15
|
export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
|
|
16
16
|
export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
|
|
17
17
|
export const notWhiteSpace = (a) => !isWhiteSpace(a);
|
|
18
|
-
export const isPunctuator = (
|
|
18
|
+
export const isPunctuator = (token, value) => {
|
|
19
|
+
if (token.type !== 'Punctuator')
|
|
20
|
+
return false;
|
|
21
|
+
|
|
22
|
+
return !value || token.value === value;
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
export const StringLiteral = (value) => ({
|
|
21
26
|
type: 'StringLiteral',
|