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,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"',
|
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
|
+
};
|