flatlint 1.17.0 → 1.19.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 +10 -0
- package/README.md +22 -0
- package/lib/compare/collect-array.js +7 -1
- package/lib/plugins/convert-comma-to-semicolon/index.js +15 -8
- package/lib/plugins/remove-useless-arrow/index.js +5 -0
- package/lib/plugins/remove-useless-coma/index.js +18 -0
- package/lib/types/types.js +13 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -110,6 +110,28 @@ const a = {
|
|
|
110
110
|
|
|
111
111
|
</details>
|
|
112
112
|
|
|
113
|
+
<details><summary>Remove useless arrow</summary>
|
|
114
|
+
|
|
115
|
+
```diff
|
|
116
|
+
-function parse(source) => {
|
|
117
|
+
+function parse(source) {
|
|
118
|
+
return source;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
<details><summary>Remove useless coma</summary>
|
|
125
|
+
|
|
126
|
+
```diff
|
|
127
|
+
const a = class {
|
|
128
|
+
- b() {},
|
|
129
|
+
+ b() {}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
</details>
|
|
134
|
+
|
|
113
135
|
## Template literals
|
|
114
136
|
|
|
115
137
|
**FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CloseRoundBrace,
|
|
3
|
+
Punctuator,
|
|
4
|
+
} from '#types';
|
|
2
5
|
import {equal} from './equal.js';
|
|
3
6
|
|
|
4
7
|
export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
|
|
@@ -9,6 +12,9 @@ export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Pun
|
|
|
9
12
|
for (; index < n; index++) {
|
|
10
13
|
const token = tokens[index];
|
|
11
14
|
|
|
15
|
+
if (equal(token, CloseRoundBrace))
|
|
16
|
+
break;
|
|
17
|
+
|
|
12
18
|
if (equal(token, nextTemplateToken))
|
|
13
19
|
break;
|
|
14
20
|
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
return 'Use semicolon instead of trailing comma';
|
|
3
|
-
}
|
|
1
|
+
import {isIdentifier} from '#types';
|
|
4
2
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
export const report = () => 'Use semicolon instead of trailing comma';
|
|
4
|
+
export const match = () => ({
|
|
5
|
+
'__a: __expr;': (vars, path) => {
|
|
6
|
+
for (const token of path.getPrev()) {
|
|
7
|
+
if (isIdentifier(token, 'interface'))
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return true;
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
export const replace = () => ({
|
|
15
|
+
'const __a = __b,': 'const __a = __b;',
|
|
16
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {isIdentifier} from '#types';
|
|
2
|
+
|
|
3
|
+
export const report = () => 'Remove useless coma';
|
|
4
|
+
|
|
5
|
+
export const match = () => ({
|
|
6
|
+
'__a() {},': (vars, path) => {
|
|
7
|
+
for (const token of path.getPrev()) {
|
|
8
|
+
if (isIdentifier(token, 'class'))
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return false;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const replace = () => ({
|
|
17
|
+
'__a() {},': '__a() {}',
|
|
18
|
+
});
|
package/lib/types/types.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
const isString = (a) => typeof a === 'string';
|
|
2
2
|
|
|
3
3
|
export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
|
|
4
|
-
export const isIdentifier = (
|
|
4
|
+
export const isIdentifier = (token, value = token.value) => {
|
|
5
|
+
const {type} = token;
|
|
6
|
+
const is = type === 'IdentifierName';
|
|
7
|
+
|
|
8
|
+
if (!is)
|
|
9
|
+
return false;
|
|
10
|
+
|
|
11
|
+
return value === token.value;
|
|
12
|
+
};
|
|
13
|
+
|
|
5
14
|
export const isStringLiteral = ({type}) => type === 'StringLiteral';
|
|
6
15
|
export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
|
|
7
16
|
export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
|
|
@@ -53,3 +62,6 @@ export const isTemplateArray = (a) => a === ARRAY;
|
|
|
53
62
|
export const isTemplateExpression = (a) => a === EXPR;
|
|
54
63
|
export const isTemplateArrayToken = (a) => isIdentifier(a) && isTemplateArray(a.value);
|
|
55
64
|
export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExpression(a.value);
|
|
65
|
+
|
|
66
|
+
export const OpenRoundBrace = Punctuator('(');
|
|
67
|
+
export const CloseRoundBrace = Punctuator(')');
|