flatlint 1.38.0 → 1.39.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 +5 -0
- package/README.md +12 -0
- package/lib/compare/values.js +13 -4
- package/lib/plugins/add-missing-comma/index.js +31 -0
- package/lib/types/types.js +1 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -64,6 +64,18 @@ const m = {
|
|
|
64
64
|
|
|
65
65
|
</details>
|
|
66
66
|
|
|
67
|
+
<details><summary>add missing comma</summary>
|
|
68
|
+
|
|
69
|
+
```diff
|
|
70
|
+
import {
|
|
71
|
+
- a
|
|
72
|
+
+ a,
|
|
73
|
+
b,
|
|
74
|
+
} from 'c';
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
</details>
|
|
78
|
+
|
|
67
79
|
<details><summary>add <code>const</code> to <code>export</code></summary>
|
|
68
80
|
|
|
69
81
|
```diff
|
package/lib/compare/values.js
CHANGED
|
@@ -10,6 +10,9 @@ import {collectArray} from './collect-array.js';
|
|
|
10
10
|
import {collectExpression} from './collect-expression.js';
|
|
11
11
|
import {collectArgs} from './collect-args.js';
|
|
12
12
|
|
|
13
|
+
const {isArray} = Array;
|
|
14
|
+
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
15
|
+
|
|
13
16
|
const {entries} = Object;
|
|
14
17
|
|
|
15
18
|
export function findVarsWays(tokens) {
|
|
@@ -36,21 +39,25 @@ export function getValues(tokens, waysFrom) {
|
|
|
36
39
|
let end = index;
|
|
37
40
|
let ok = true;
|
|
38
41
|
|
|
39
|
-
if (isTemplateArray(name))
|
|
42
|
+
if (isTemplateArray(name)) {
|
|
40
43
|
[ok, end] = collectArray({
|
|
41
44
|
currentTokenIndex: index,
|
|
42
45
|
tokens,
|
|
43
46
|
});
|
|
44
|
-
else if (isTemplateExpression(name))
|
|
47
|
+
} else if (isTemplateExpression(name)) {
|
|
45
48
|
end = collectExpression({
|
|
46
49
|
currentTokenIndex: index,
|
|
47
50
|
tokens,
|
|
48
51
|
});
|
|
49
|
-
else if (isTemplateArgs(name))
|
|
52
|
+
} else if (isTemplateArgs(name)) {
|
|
50
53
|
[ok, end] = collectArgs({
|
|
51
54
|
currentTokenIndex: index,
|
|
52
55
|
tokens,
|
|
53
56
|
});
|
|
57
|
+
} else {
|
|
58
|
+
values[name] = tokens[index];
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
54
61
|
|
|
55
62
|
if (!ok) {
|
|
56
63
|
values[name] = [];
|
|
@@ -65,7 +72,8 @@ export function getValues(tokens, waysFrom) {
|
|
|
65
72
|
|
|
66
73
|
export function setValues({to, waysTo, values}) {
|
|
67
74
|
for (const [name, index] of entries(waysTo)) {
|
|
68
|
-
|
|
75
|
+
const current = maybeArray(values[name]);
|
|
76
|
+
to.splice(index, 1, ...current);
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
@@ -75,3 +83,4 @@ export function getCurrentValues({from, start, end, tokens}) {
|
|
|
75
83
|
|
|
76
84
|
return getValues(current, waysFrom);
|
|
77
85
|
}
|
|
86
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
comma,
|
|
3
|
+
isPunctuator,
|
|
4
|
+
semicolon,
|
|
5
|
+
arrow,
|
|
6
|
+
openCurlyBrace,
|
|
7
|
+
closeRoundBrace,
|
|
8
|
+
dot,
|
|
9
|
+
isIdentifier,
|
|
10
|
+
isOperator,
|
|
11
|
+
} from '#types';
|
|
12
|
+
|
|
13
|
+
export const report = () => 'Add missing comma';
|
|
14
|
+
|
|
15
|
+
export const match = () => ({
|
|
16
|
+
__a: ({__a}, path) => {
|
|
17
|
+
if (!isIdentifier(__a))
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
if (isOperator(__a))
|
|
21
|
+
return false;
|
|
22
|
+
|
|
23
|
+
return !path.isNextPunctuator(comma);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const replace = () => ({
|
|
28
|
+
__a: '__a,',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
package/lib/types/types.js
CHANGED