flatlint 4.4.2 → 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,3 +1,8 @@
1
+ 2026.01.29, v4.5.0
2
+
3
+ feature:
4
+ - e07daf6 flatlint: add-missing-squire-brace: isSquireBracesBalanced: add
5
+
1
6
  2026.01.29, v4.4.2
2
7
 
3
8
  feature:
@@ -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
- '__a(__b, ["__c", "__d")': '__a(__b, ["__c", "__d"])',
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,11 +25,8 @@ export const match = () => ({
24
25
 
25
26
  return true;
26
27
  },
27
- '})': (vars, path) => !isBracesBalanced(path),
28
- ')]': (vars, path) => {
29
- const a = isBracesBalanced(path);
30
- return a < 0;
31
- },
28
+ '})': (vars, path) => !isRoundBracesBalanced(path),
29
+ ')]': (vars, path) => isRoundBracesBalanced(path) < 0,
32
30
  });
33
31
 
34
32
  export const replace = () => ({
@@ -40,16 +38,3 @@ export const replace = () => ({
40
38
  'for (__a __b of __c))': 'for (__a __b of __c)',
41
39
  });
42
40
 
43
- function isBracesBalanced(path) {
44
- let balance = 0;
45
-
46
- for (const current of path.getAllPrev()) {
47
- if (isPunctuator(current, openRoundBrace))
48
- ++balance;
49
-
50
- if (isPunctuator(current, closeRoundBrace))
51
- --balance;
52
- }
53
-
54
- return balance;
55
- }
@@ -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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "4.4.2",
3
+ "version": "4.5.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",