flatlint 1.23.0 → 1.24.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/flatlint.js +3 -6
- package/lib/plugins/add-missing-semicolon/index.js +4 -5
- package/lib/plugins/remove-useless-coma/index.js +1 -1
- package/lib/plugins/remove-useless-semicolon/index.js +1 -1
- package/lib/runner/path.js +50 -24
- package/lib/runner/replacer.js +1 -1
- package/lib/types/types.js +7 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/flatlint.js
CHANGED
|
@@ -2,6 +2,9 @@ import {loadPlugins} from '@putout/engine-loader';
|
|
|
2
2
|
import {parse} from '#parser';
|
|
3
3
|
import {run} from '#runner';
|
|
4
4
|
|
|
5
|
+
const getValue = (token) => token.value;
|
|
6
|
+
const print = (tokens) => tokens.map(getValue).join('');
|
|
7
|
+
|
|
5
8
|
export function lint(source, overrides = {}) {
|
|
6
9
|
const {fix = true, plugins: pluginNames = []} = overrides;
|
|
7
10
|
const plugins = loadPlugins({
|
|
@@ -23,9 +26,3 @@ export function lint(source, overrides = {}) {
|
|
|
23
26
|
places,
|
|
24
27
|
];
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
function print(tokens) {
|
|
28
|
-
return tokens
|
|
29
|
-
.map((token) => token.value)
|
|
30
|
-
.join('');
|
|
31
|
-
}
|
|
@@ -13,11 +13,10 @@ export const replace = () => ({
|
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
function check(vars, path) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
last = token;
|
|
16
|
+
for (const token of path.getAllNext()) {
|
|
17
|
+
if (isPunctuator(token))
|
|
18
|
+
return false;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
return
|
|
21
|
+
return true;
|
|
23
22
|
}
|
|
@@ -4,7 +4,7 @@ export const report = () => 'Remove useless semicolon';
|
|
|
4
4
|
|
|
5
5
|
export const match = () => ({
|
|
6
6
|
'__a: __expr;': (vars, path) => {
|
|
7
|
-
for (const token of path.
|
|
7
|
+
for (const token of path.getAllPrev()) {
|
|
8
8
|
if (isIdentifier(token, 'interface'))
|
|
9
9
|
return false;
|
|
10
10
|
}
|
package/lib/runner/path.js
CHANGED
|
@@ -1,33 +1,59 @@
|
|
|
1
|
-
import {isNewLine} from '#types';
|
|
1
|
+
import {isNewLine, isPunctuator} from '#types';
|
|
2
2
|
|
|
3
|
-
export const createPath = ({tokens, start}) => ({
|
|
4
|
-
|
|
3
|
+
export const createPath = ({tokens, start, end}) => ({
|
|
4
|
+
getAllPrev: createGetAllPrev({
|
|
5
5
|
tokens,
|
|
6
6
|
start,
|
|
7
7
|
}),
|
|
8
|
-
|
|
8
|
+
getAllNext: createGetAllNext({
|
|
9
9
|
tokens,
|
|
10
|
-
|
|
10
|
+
end,
|
|
11
|
+
}),
|
|
12
|
+
isNextPunctuator: createIsNextPunctuator({
|
|
13
|
+
tokens,
|
|
14
|
+
end,
|
|
15
|
+
}),
|
|
16
|
+
isEndsWithPunctuator: createIsEndsWithPunctuator({
|
|
17
|
+
tokens,
|
|
18
|
+
end,
|
|
19
|
+
}),
|
|
20
|
+
isNext: createIsNext({
|
|
21
|
+
tokens,
|
|
22
|
+
end,
|
|
11
23
|
}),
|
|
12
24
|
});
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
27
|
+
const current = tokens[end];
|
|
28
|
+
|
|
29
|
+
if (!current)
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
return isPunctuator(current, punctuator);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const createIsEndsWithPunctuator = ({tokens, end}) => (punctuator) => {
|
|
36
|
+
const current = tokens[end - 1];
|
|
37
|
+
return isPunctuator(current, punctuator);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const createIsNext = ({tokens, end}) => () => {
|
|
41
|
+
return Boolean(tokens[end]);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const createGetAllPrev = ({tokens, start}) => function*() {
|
|
45
|
+
for (let i = start; i >= 0; --i) {
|
|
46
|
+
yield tokens[i];
|
|
47
|
+
}
|
|
48
|
+
};
|
|
21
49
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
}
|
|
50
|
+
const createGetAllNext = ({tokens, end}) => function*() {
|
|
51
|
+
for (let i = end; i < tokens.length; ++i) {
|
|
52
|
+
const current = tokens[i];
|
|
53
|
+
|
|
54
|
+
if (isNewLine(current))
|
|
55
|
+
continue;
|
|
56
|
+
|
|
57
|
+
yield current;
|
|
58
|
+
}
|
|
59
|
+
};
|
package/lib/runner/replacer.js
CHANGED
package/lib/types/types.js
CHANGED
|
@@ -15,11 +15,16 @@ 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 = (token,
|
|
18
|
+
export const isPunctuator = (token, punctuator) => {
|
|
19
19
|
if (token.type !== 'Punctuator')
|
|
20
20
|
return false;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
if (!punctuator)
|
|
23
|
+
return true;
|
|
24
|
+
|
|
25
|
+
const punctuatorValue = punctuator.value || punctuator;
|
|
26
|
+
|
|
27
|
+
return token.value === punctuatorValue;
|
|
23
28
|
};
|
|
24
29
|
|
|
25
30
|
export const StringLiteral = (value) => ({
|