flatlint 4.4.1 → 4.5.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,11 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
closeSquareBrace,
|
|
3
|
+
isPunctuator,
|
|
4
|
+
isSquireBracesBalanced,
|
|
5
|
+
openSquireBrace,
|
|
6
|
+
} from '#types';
|
|
7
|
+
|
|
1
8
|
export const report = () => 'Add missing square brace';
|
|
2
9
|
|
|
3
10
|
export const match = () => ({
|
|
4
11
|
'["__a"': (vars, path) => !path.isNext(),
|
|
12
|
+
')': (vars, path) => isSquireBracesBalanced(path),
|
|
5
13
|
});
|
|
6
14
|
export const replace = () => ({
|
|
7
15
|
'[__array;': '[__array];',
|
|
8
16
|
'["__a"': '["__a"];',
|
|
9
17
|
'[;': '[];',
|
|
10
|
-
'
|
|
18
|
+
')': '])',
|
|
11
19
|
});
|
|
20
|
+
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
hasRoundBraces,
|
|
4
4
|
isBalancedRoundBraces,
|
|
5
5
|
isPunctuator,
|
|
6
|
+
isRoundBracesBalanced,
|
|
6
7
|
openRoundBrace,
|
|
7
8
|
} from '#types';
|
|
8
9
|
|
|
@@ -24,8 +25,8 @@ export const match = () => ({
|
|
|
24
25
|
|
|
25
26
|
return true;
|
|
26
27
|
},
|
|
27
|
-
'})': (vars, path) =>
|
|
28
|
-
')]': (vars, path) =>
|
|
28
|
+
'})': (vars, path) => !isRoundBracesBalanced(path),
|
|
29
|
+
')]': (vars, path) => isRoundBracesBalanced(path) < 0,
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
export const replace = () => ({
|
|
@@ -37,16 +38,3 @@ export const replace = () => ({
|
|
|
37
38
|
'for (__a __b of __c))': 'for (__a __b of __c)',
|
|
38
39
|
});
|
|
39
40
|
|
|
40
|
-
function isBracesBalanced(path) {
|
|
41
|
-
let balance = 0;
|
|
42
|
-
|
|
43
|
-
for (const current of path.getAllPrev()) {
|
|
44
|
-
if (isPunctuator(current, openRoundBrace))
|
|
45
|
-
++balance;
|
|
46
|
-
|
|
47
|
-
if (isPunctuator(current, closeRoundBrace))
|
|
48
|
-
--balance;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return !balance;
|
|
52
|
-
}
|
package/lib/types/types.js
CHANGED
|
@@ -238,3 +238,27 @@ export const getPrev = ({tokens, start}) => {
|
|
|
238
238
|
return token;
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
|
+
|
|
242
|
+
const createIsSquireBracesBalanced = ({open, close}) => (path) => {
|
|
243
|
+
let balance = 0;
|
|
244
|
+
|
|
245
|
+
for (const current of path.getAllPrev()) {
|
|
246
|
+
if (isPunctuator(current, open))
|
|
247
|
+
++balance;
|
|
248
|
+
|
|
249
|
+
if (isPunctuator(current, close))
|
|
250
|
+
--balance;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return balance;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export const isSquireBracesBalanced = createIsSquireBracesBalanced({
|
|
257
|
+
open: openSquireBrace,
|
|
258
|
+
close: closeSquareBrace,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
export const isRoundBracesBalanced = createIsSquireBracesBalanced({
|
|
262
|
+
open: openRoundBrace,
|
|
263
|
+
close: closeRoundBrace,
|
|
264
|
+
});
|