flatlint 1.28.0 → 1.29.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
package/README.md
CHANGED
|
@@ -24,6 +24,11 @@ npm i flatlint
|
|
|
24
24
|
```diff
|
|
25
25
|
-const a = 5,
|
|
26
26
|
+const a = 5;
|
|
27
|
+
|
|
28
|
+
function x() {
|
|
29
|
+
- return m,
|
|
30
|
+
+ return m;
|
|
31
|
+
}
|
|
27
32
|
```
|
|
28
33
|
|
|
29
34
|
</details>
|
|
@@ -106,6 +111,17 @@ const a = {
|
|
|
106
111
|
|
|
107
112
|
</details>
|
|
108
113
|
|
|
114
|
+
<details><summary>remove useless comma</summary>
|
|
115
|
+
|
|
116
|
+
```diff
|
|
117
|
+
function x() {
|
|
118
|
+
return m;
|
|
119
|
+
-},
|
|
120
|
+
+}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
</details>
|
|
124
|
+
|
|
109
125
|
<details><summary>add missing quote</summary>
|
|
110
126
|
|
|
111
127
|
```diff
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isIdentifier,
|
|
3
|
+
isPunctuator,
|
|
4
|
+
openCurlyBrace,
|
|
5
|
+
openSquireBrace,
|
|
6
|
+
} from '#types';
|
|
2
7
|
|
|
3
8
|
export const report = () => 'Remove useless coma';
|
|
4
9
|
|
|
@@ -11,9 +16,21 @@ export const match = () => ({
|
|
|
11
16
|
|
|
12
17
|
return false;
|
|
13
18
|
},
|
|
19
|
+
'},': (vars, path) => {
|
|
20
|
+
for (const token of path.getAllPrev()) {
|
|
21
|
+
if (isPunctuator(token, openSquireBrace))
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (path.isNextIdentifier('const'))
|
|
26
|
+
return true;
|
|
27
|
+
|
|
28
|
+
return !path.isNextPunctuator(openCurlyBrace);
|
|
29
|
+
},
|
|
14
30
|
});
|
|
15
31
|
|
|
16
32
|
export const replace = () => ({
|
|
17
33
|
'__a(__args) {},': '__a(__args) {}',
|
|
18
34
|
'__a(),': '__a()',
|
|
35
|
+
'},': '}',
|
|
19
36
|
});
|
package/lib/runner/path.js
CHANGED
|
@@ -2,12 +2,17 @@ import {
|
|
|
2
2
|
isIdentifier,
|
|
3
3
|
isNewLine,
|
|
4
4
|
isPunctuator,
|
|
5
|
+
isWhiteSpace,
|
|
5
6
|
} from '#types';
|
|
6
7
|
|
|
7
8
|
export const createPath = ({tokens, start, end}) => ({
|
|
8
9
|
tokens,
|
|
9
10
|
start,
|
|
10
11
|
end,
|
|
12
|
+
isNextIdentifier: createIsNextIdentifier({
|
|
13
|
+
tokens,
|
|
14
|
+
end,
|
|
15
|
+
}),
|
|
11
16
|
getAllPrev: createGetAllPrev({
|
|
12
17
|
tokens,
|
|
13
18
|
start,
|
|
@@ -30,12 +35,24 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
30
35
|
}),
|
|
31
36
|
});
|
|
32
37
|
|
|
33
|
-
const
|
|
38
|
+
const createIsNextIdentifier = ({tokens, end}) => (value) => {
|
|
34
39
|
const current = tokens[end];
|
|
35
40
|
|
|
36
41
|
if (!current)
|
|
37
42
|
return false;
|
|
38
43
|
|
|
44
|
+
return isIdentifier(current, value);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
48
|
+
let current = tokens[end];
|
|
49
|
+
|
|
50
|
+
if (!current)
|
|
51
|
+
return false;
|
|
52
|
+
|
|
53
|
+
if (isWhiteSpace(current))
|
|
54
|
+
current = tokens[end + 1];
|
|
55
|
+
|
|
39
56
|
return isPunctuator(current, punctuator);
|
|
40
57
|
};
|
|
41
58
|
|
package/lib/types/types.js
CHANGED
|
@@ -83,6 +83,10 @@ export const closeSquareBrace = Punctuator(']');
|
|
|
83
83
|
export const semicolon = Punctuator(';');
|
|
84
84
|
export const comma = Punctuator(',');
|
|
85
85
|
export const colon = Punctuator(':');
|
|
86
|
+
export const openCurlyBrace = Punctuator('{');
|
|
87
|
+
export const closeCurlyBrace = Punctuator('}');
|
|
88
|
+
export const openSquireBrace = Punctuator('[');
|
|
89
|
+
export const closeSquireBrace = Punctuator(']');
|
|
86
90
|
|
|
87
91
|
export const OK = true;
|
|
88
92
|
export const NOT_OK = false;
|