flatlint 1.66.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/runner/path.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
isWhiteSpace,
|
|
7
7
|
isTemplateTail,
|
|
8
8
|
isTemplateMiddle,
|
|
9
|
+
isNoSubstitutionTemplate,
|
|
9
10
|
} from '#types';
|
|
10
11
|
|
|
11
12
|
export const createPath = ({tokens, start, end}) => ({
|
|
@@ -90,6 +91,9 @@ const createIsInsideTemplate = ({tokens, end}) => () => {
|
|
|
90
91
|
if (isTemplateTail(current))
|
|
91
92
|
return true;
|
|
92
93
|
|
|
94
|
+
if (isNoSubstitutionTemplate(current))
|
|
95
|
+
return true;
|
|
96
|
+
|
|
93
97
|
return isTemplateMiddle(current);
|
|
94
98
|
};
|
|
95
99
|
|
package/lib/types/types.js
CHANGED
|
@@ -3,6 +3,7 @@ const maybeArray = (a) => isArray(a) ? a : [a];
|
|
|
3
3
|
const isString = (a) => typeof a === 'string';
|
|
4
4
|
|
|
5
5
|
export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';
|
|
6
|
+
export const isNoSubstitutionTemplate = (a) => a?.type === 'NoSubstitutionTemplate';
|
|
6
7
|
export const isTemplateTail = (a) => a?.type === 'TemplateTail';
|
|
7
8
|
export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
|
|
8
9
|
export const isIdentifier = (token, newToken) => {
|
|
@@ -169,3 +170,28 @@ export const isOnlyWhitespaces = (tokens) => {
|
|
|
169
170
|
|
|
170
171
|
return true;
|
|
171
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
|
+
};
|