flatlint 1.38.0 → 1.39.1
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 +12 -0
- package/lib/compare/values.js +12 -4
- package/lib/plugins/add-missing-comma/index.js +43 -0
- package/lib/plugins.js +3 -1
- package/lib/types/types.js +5 -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
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assign,
|
|
3
|
+
closeCurlyBrace,
|
|
4
|
+
closeRoundBrace,
|
|
5
|
+
colon,
|
|
6
|
+
comma,
|
|
7
|
+
dot,
|
|
8
|
+
isIdentifier,
|
|
9
|
+
isOperator,
|
|
10
|
+
more,
|
|
11
|
+
openRoundBrace,
|
|
12
|
+
} from '#types';
|
|
13
|
+
|
|
14
|
+
export const report = () => 'Add missing comma';
|
|
15
|
+
|
|
16
|
+
export const match = () => ({
|
|
17
|
+
__a: ({__a}, path) => {
|
|
18
|
+
const punctuators = [
|
|
19
|
+
assign,
|
|
20
|
+
comma,
|
|
21
|
+
openRoundBrace,
|
|
22
|
+
closeRoundBrace,
|
|
23
|
+
closeCurlyBrace,
|
|
24
|
+
colon,
|
|
25
|
+
dot,
|
|
26
|
+
more,
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
if (!isIdentifier(__a))
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
if (isOperator(__a))
|
|
33
|
+
return false;
|
|
34
|
+
|
|
35
|
+
return !path.isNextPunctuator(punctuators);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const replace = () => ({
|
|
40
|
+
__a: '__a,',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
package/lib/plugins.js
CHANGED
|
@@ -3,18 +3,20 @@ import * as addMissingRoundBraces from './plugins/add-missing-round-braces/index
|
|
|
3
3
|
import * as addMissingSquireBrace from './plugins/add-missing-square-brace/index.js';
|
|
4
4
|
import * as addMissingQuote from './plugins/add-missing-quote/index.js';
|
|
5
5
|
import * as addMissingSemicolon from './plugins/add-missing-semicolon/index.js';
|
|
6
|
+
import * as addMissingComma from './plugins/add-missing-comma/index.js';
|
|
7
|
+
import * as addConstToExport from './plugins/add-const-to-export/index.js';
|
|
6
8
|
import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/index.js';
|
|
7
9
|
import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
|
|
8
10
|
import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
|
|
9
11
|
import * as removeUselessComma from './plugins/remove-useless-comma/index.js';
|
|
10
12
|
import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
|
|
11
|
-
import * as addConstToExport from './plugins/add-const-to-export/index.js';
|
|
12
13
|
|
|
13
14
|
export const plugins = [
|
|
14
15
|
['wrap-assignment-in-parens', wrapAssignmentInParens],
|
|
15
16
|
['add-missing-round-braces', addMissingRoundBraces],
|
|
16
17
|
['add-missing-squire-brace', addMissingSquireBrace],
|
|
17
18
|
['add-missing-semicolon', addMissingSemicolon],
|
|
19
|
+
['add-missing-comma', addMissingComma],
|
|
18
20
|
['add-missing-quote', addMissingQuote],
|
|
19
21
|
['add-const-to-export', addConstToExport],
|
|
20
22
|
['convert-comma-to-semicolon', convertCommaToSemicolon],
|
package/lib/types/types.js
CHANGED
|
@@ -22,6 +22,9 @@ export const isOperator = (token) => {
|
|
|
22
22
|
'const',
|
|
23
23
|
'export',
|
|
24
24
|
'from',
|
|
25
|
+
'import',
|
|
26
|
+
'return',
|
|
27
|
+
'function',
|
|
25
28
|
];
|
|
26
29
|
|
|
27
30
|
for (const operator of operators) {
|
|
@@ -99,6 +102,8 @@ export const closeSquareBrace = Punctuator(']');
|
|
|
99
102
|
export const colon = Punctuator(':');
|
|
100
103
|
export const comma = Punctuator(',');
|
|
101
104
|
export const dot = Punctuator('.');
|
|
105
|
+
export const more = Punctuator('>');
|
|
106
|
+
export const assign = Punctuator('=');
|
|
102
107
|
export const openRoundBrace = Punctuator('(');
|
|
103
108
|
export const semicolon = Punctuator(';');
|
|
104
109
|
export const openCurlyBrace = Punctuator('{');
|