flatlint 1.39.3 → 1.41.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
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2025.01.13, v1.41.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 677b162 flatlint: add-missing-semicolon: exclude template tail
|
|
5
|
+
|
|
6
|
+
2025.01.13, v1.40.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 5a1f09b flatlint: convert-comma-to-semicolon: use __x for keyword
|
|
10
|
+
- e85093b flatlint: types: isOperator -> isKeywrod
|
|
11
|
+
- 7c4afc1 flatlint: add-missing-comma: exclude await
|
|
12
|
+
|
|
1
13
|
2025.01.12, v1.39.3
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {isKeyword} from '#types';
|
|
2
2
|
|
|
3
3
|
export const report = () => 'Add missing comma';
|
|
4
4
|
|
|
5
5
|
export const match = () => ({
|
|
6
6
|
__a: ({__a}, path) => {
|
|
7
|
-
if (
|
|
7
|
+
if (isKeyword(__a))
|
|
8
8
|
return false;
|
|
9
9
|
|
|
10
10
|
return !path.isNextPunctuator();
|
|
@@ -14,4 +14,3 @@ export const match = () => ({
|
|
|
14
14
|
export const replace = () => ({
|
|
15
15
|
__a: '__a,',
|
|
16
16
|
});
|
|
17
|
-
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
colon,
|
|
3
|
+
isOneOfKeywords,
|
|
3
4
|
isPunctuator,
|
|
4
5
|
quote,
|
|
5
6
|
} from '#types';
|
|
@@ -14,24 +15,25 @@ export const match = () => ({
|
|
|
14
15
|
|
|
15
16
|
return true;
|
|
16
17
|
},
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'let __a,': check,
|
|
20
|
-
'var __a,': check,
|
|
18
|
+
'__x __a = __b,': check,
|
|
19
|
+
'__x __a,': check,
|
|
21
20
|
'return __expr,': ({}, path) => !path.isNextPunctuator(quote),
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
export const replace = () => ({
|
|
25
24
|
'from "__a",': 'from "__a";',
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'var __a = __b,': 'var __a = __b;',
|
|
29
|
-
'let __a = __b,': 'let __a = __b;',
|
|
30
|
-
'const __a = __b,': 'const __a = __b;',
|
|
25
|
+
'__x __a,': '__x __a;',
|
|
26
|
+
'__x __a = __b,': '__x __a = __b;',
|
|
31
27
|
'__a(__args),': '__a(__args);',
|
|
32
28
|
'return __expr,': 'return __expr;',
|
|
33
29
|
});
|
|
34
30
|
|
|
35
|
-
const check = (
|
|
36
|
-
|
|
31
|
+
const check = ({__x}, path) => {
|
|
32
|
+
if (!isOneOfKeywords(__x, ['var', 'let', 'const']))
|
|
33
|
+
return false;
|
|
34
|
+
|
|
35
|
+
if (!path.isNext())
|
|
36
|
+
return true;
|
|
37
|
+
|
|
38
|
+
return path.isNextKeyword();
|
|
37
39
|
};
|
package/lib/runner/path.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isIdentifier,
|
|
3
3
|
isNewLine,
|
|
4
|
-
|
|
4
|
+
isKeyword,
|
|
5
5
|
isPunctuator,
|
|
6
6
|
isWhiteSpace,
|
|
7
|
+
isTemplateTail,
|
|
7
8
|
} from '#types';
|
|
8
9
|
|
|
9
10
|
const {isArray} = Array;
|
|
@@ -25,7 +26,7 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
25
26
|
tokens,
|
|
26
27
|
end,
|
|
27
28
|
}),
|
|
28
|
-
|
|
29
|
+
isNextKeyword: createIsNextKeyword({
|
|
29
30
|
tokens,
|
|
30
31
|
end,
|
|
31
32
|
}),
|
|
@@ -33,6 +34,10 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
33
34
|
tokens,
|
|
34
35
|
end,
|
|
35
36
|
}),
|
|
37
|
+
isNextTemplateTail: createIsNextTemplateTail({
|
|
38
|
+
tokens,
|
|
39
|
+
end,
|
|
40
|
+
}),
|
|
36
41
|
isNext: createIsNext({
|
|
37
42
|
tokens,
|
|
38
43
|
end,
|
|
@@ -103,13 +108,25 @@ const createIsNextIdentifier = ({tokens, end}) => (value) => {
|
|
|
103
108
|
return isIdentifier(current, value);
|
|
104
109
|
};
|
|
105
110
|
|
|
106
|
-
const
|
|
111
|
+
const createIsNextTemplateTail = ({tokens, end}) => () => {
|
|
107
112
|
const current = next({
|
|
108
113
|
tokens,
|
|
109
114
|
end,
|
|
110
115
|
});
|
|
111
116
|
|
|
112
|
-
return
|
|
117
|
+
return isTemplateTail(current);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const createIsNextKeyword = ({tokens, end}) => () => {
|
|
121
|
+
const current = next({
|
|
122
|
+
tokens,
|
|
123
|
+
end,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (!current)
|
|
127
|
+
return false;
|
|
128
|
+
|
|
129
|
+
return isKeyword(current);
|
|
113
130
|
};
|
|
114
131
|
|
|
115
132
|
const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
|
package/lib/types/types.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const isString = (a) => typeof a === 'string';
|
|
2
2
|
|
|
3
|
+
export const isTemplateTail = (a) => a?.type === 'TemplateTail';
|
|
3
4
|
export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
|
|
4
5
|
export const isIdentifier = (token, value = token.value) => {
|
|
5
6
|
const {type} = token;
|
|
@@ -15,8 +16,9 @@ export const isStringLiteral = ({type}) => type === 'StringLiteral';
|
|
|
15
16
|
export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
|
|
16
17
|
export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
|
|
17
18
|
export const notWhiteSpace = (a) => !isWhiteSpace(a);
|
|
18
|
-
export const
|
|
19
|
-
const
|
|
19
|
+
export const isKeyword = (token) => {
|
|
20
|
+
const keywords = [
|
|
21
|
+
'await',
|
|
20
22
|
'var',
|
|
21
23
|
'let',
|
|
22
24
|
'const',
|
|
@@ -27,13 +29,23 @@ export const isOperator = (token) => {
|
|
|
27
29
|
'function',
|
|
28
30
|
];
|
|
29
31
|
|
|
30
|
-
for (const
|
|
31
|
-
if (isIdentifier(token,
|
|
32
|
+
for (const keyword of keywords) {
|
|
33
|
+
if (isIdentifier(token, keyword))
|
|
32
34
|
return true;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
return false;
|
|
36
38
|
};
|
|
39
|
+
|
|
40
|
+
export const isOneOfKeywords = (token, keywords) => {
|
|
41
|
+
for (const keyword of keywords) {
|
|
42
|
+
if (isIdentifier(token, keyword))
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
export const isPunctuator = (token, punctuator) => {
|
|
38
50
|
if (token.type !== 'Punctuator')
|
|
39
51
|
return false;
|