flatlint 1.67.0 → 1.68.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
+ 2025.01.21, v1.68.0
2
+
3
+ feature:
4
+ - 8939969 remove-useless-round-brace: exclude call
5
+
1
6
  2025.01.21, v1.67.0
2
7
 
3
8
  feature:
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  comma,
3
- isPunctuator,
4
3
  semicolon,
5
4
  arrow,
6
5
  openCurlyBrace,
@@ -54,4 +53,3 @@ export const replace = () => ({
54
53
 
55
54
  '})': '});',
56
55
  });
57
-
@@ -1,5 +1,23 @@
1
+ import {
2
+ closeRoundBrace,
3
+ hasRoundBraces,
4
+ isBalancedRoundBraces,
5
+ isOneOfPunctuators,
6
+ isPunctuator,
7
+ openRoundBrace,
8
+ } from '#types';
9
+
1
10
  export const report = () => 'Remove useless round brace';
2
11
 
12
+ export const match = () => ({
13
+ 'const __a = __expr);': ({__expr}) => {
14
+ if (!hasRoundBraces(__expr))
15
+ return true;
16
+
17
+ return !isBalancedRoundBraces(__expr);
18
+ },
19
+ });
20
+
3
21
  export const replace = () => ({
4
22
  'const __a = __expr);': 'const __a = __expr;',
5
23
  'from "__b")': 'from "__b"',
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.67.0",
3
+ "version": "1.68.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",