flatlint 1.67.0 → 1.69.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
package/README.md
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
assign,
|
|
3
|
+
isOneOfKeywords,
|
|
4
|
+
isOneOfPunctuators,
|
|
5
|
+
} from '#types';
|
|
2
6
|
|
|
3
7
|
export const report = () => 'Add missing assign';
|
|
4
8
|
|
|
5
9
|
export const match = () => ({
|
|
6
|
-
'__x __a
|
|
7
|
-
|
|
10
|
+
'__x __a __expr': ({__expr, __x}, path) => {
|
|
11
|
+
if (path.isNextPunctuator(assign))
|
|
12
|
+
return false;
|
|
13
|
+
|
|
14
|
+
if (!isOneOfKeywords(__x, ['const', 'let', 'var']))
|
|
15
|
+
return false;
|
|
16
|
+
|
|
17
|
+
return !isOneOfPunctuators(assign, __expr);
|
|
8
18
|
},
|
|
19
|
+
'__a.__b __expr': ({__expr}) => !isOneOfPunctuators(assign, __expr),
|
|
9
20
|
});
|
|
10
21
|
|
|
11
22
|
export const replace = () => ({
|
|
12
|
-
'__x __a
|
|
23
|
+
'__x __a __expr': '__x __a = __expr',
|
|
24
|
+
'__a.__b __expr': '__a.__b = __expr',
|
|
13
25
|
});
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasRoundBraces,
|
|
3
|
+
isBalancedRoundBraces,
|
|
4
|
+
} from '#types';
|
|
5
|
+
|
|
1
6
|
export const report = () => 'Remove useless round brace';
|
|
2
7
|
|
|
8
|
+
export const match = () => ({
|
|
9
|
+
'const __a = __expr);': ({__expr}) => {
|
|
10
|
+
if (!hasRoundBraces(__expr))
|
|
11
|
+
return true;
|
|
12
|
+
|
|
13
|
+
return !isBalancedRoundBraces(__expr);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
3
17
|
export const replace = () => ({
|
|
4
18
|
'const __a = __expr);': 'const __a = __expr;',
|
|
5
19
|
'from "__b")': 'from "__b"',
|
package/lib/types/types.js
CHANGED
|
@@ -170,3 +170,28 @@ export const isOnlyWhitespaces = (tokens) => {
|
|
|
170
170
|
|
|
171
171
|
return true;
|
|
172
172
|
};
|
|
173
|
+
|
|
174
|
+
export const hasRoundBraces = (tokens) => {
|
|
175
|
+
const roundBraces = [openRoundBrace, closeRoundBrace];
|
|
176
|
+
|
|
177
|
+
for (const token of tokens) {
|
|
178
|
+
if (isOneOfPunctuators(token, roundBraces))
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return false;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export const isBalancedRoundBraces = (tokens) => {
|
|
186
|
+
let roundBalance = 0;
|
|
187
|
+
|
|
188
|
+
for (const token of tokens) {
|
|
189
|
+
if (isPunctuator(token, openRoundBrace))
|
|
190
|
+
roundBalance++;
|
|
191
|
+
|
|
192
|
+
if (isPunctuator(token, closeRoundBrace))
|
|
193
|
+
roundBalance--;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return !roundBalance;
|
|
197
|
+
};
|