flatlint 1.24.0 → 1.25.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 +4 -1
- package/lib/compare/compare.js +4 -1
- package/lib/plugins/add-missing-round-braces/index.js +7 -0
- package/lib/plugins/add-missing-semicolon/index.js +9 -2
- package/lib/plugins.js +2 -0
- package/lib/runner/path.js +0 -8
- package/lib/types/types.js +2 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -37,13 +37,16 @@ npm i flatlint
|
|
|
37
37
|
|
|
38
38
|
</details>
|
|
39
39
|
|
|
40
|
-
<details><summary>add missing round
|
|
40
|
+
<details><summary>add missing round brace</summary>
|
|
41
41
|
|
|
42
42
|
```diff
|
|
43
43
|
-if a > 5 {
|
|
44
44
|
+if (a > 5) {
|
|
45
45
|
alert();
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
-a('hello'
|
|
49
|
+
+a('hello');
|
|
47
50
|
```
|
|
48
51
|
|
|
49
52
|
</details>
|
package/lib/compare/compare.js
CHANGED
|
@@ -29,7 +29,8 @@ export const compare = (source, template) => {
|
|
|
29
29
|
|
|
30
30
|
for (let index = 0; index < n; index++) {
|
|
31
31
|
for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
|
|
32
|
-
|
|
32
|
+
let currentTokenIndex = index + templateIndex - skip;
|
|
33
|
+
|
|
33
34
|
const templateToken = templateTokens[templateIndex];
|
|
34
35
|
const currentToken = tokens[currentTokenIndex];
|
|
35
36
|
|
|
@@ -43,6 +44,8 @@ export const compare = (source, template) => {
|
|
|
43
44
|
|
|
44
45
|
if (!ok) {
|
|
45
46
|
++skip;
|
|
47
|
+
} else if (templateIndex === templateTokensLength - 1) {
|
|
48
|
+
currentTokenIndex = end;
|
|
46
49
|
} else {
|
|
47
50
|
delta = end - currentTokenIndex;
|
|
48
51
|
index = end - templateIndex;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import {closeRoundBrace} from '#types';
|
|
2
|
+
|
|
1
3
|
export const report = () => 'Add missing round braces';
|
|
2
4
|
|
|
5
|
+
export const match = () => ({
|
|
6
|
+
'__a(__args': (vars, path) => !path.isNextPunctuator(closeRoundBrace),
|
|
7
|
+
});
|
|
8
|
+
|
|
3
9
|
export const replace = () => ({
|
|
4
10
|
'if __a > __b': 'if (__a > __b)',
|
|
11
|
+
'__a(__args': '__a(__args)',
|
|
5
12
|
});
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
comma,
|
|
3
|
+
isPunctuator,
|
|
4
|
+
semicolon,
|
|
5
|
+
} from '#types';
|
|
2
6
|
|
|
3
7
|
export const report = () => 'Add missing semicolon';
|
|
4
8
|
|
|
@@ -13,8 +17,11 @@ export const replace = () => ({
|
|
|
13
17
|
});
|
|
14
18
|
|
|
15
19
|
function check(vars, path) {
|
|
20
|
+
if (path.isEndsWithPunctuator(comma))
|
|
21
|
+
return false;
|
|
22
|
+
|
|
16
23
|
for (const token of path.getAllNext()) {
|
|
17
|
-
if (isPunctuator(token))
|
|
24
|
+
if (isPunctuator(token, semicolon))
|
|
18
25
|
return false;
|
|
19
26
|
}
|
|
20
27
|
|
package/lib/plugins.js
CHANGED
|
@@ -6,12 +6,14 @@ import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/i
|
|
|
6
6
|
import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
|
|
7
7
|
import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
|
|
8
8
|
import * as addConstToExport from './plugins/add-const-to-export/index.js';
|
|
9
|
+
import * as addMissingSemicolon from './plugins/add-missing-semicolon/index.js';
|
|
9
10
|
|
|
10
11
|
export const plugins = [
|
|
11
12
|
['wrap-assignment-in-parens', wrapAssignmentInParens],
|
|
12
13
|
['add-missing-round-braces', addMissingRoundBraces],
|
|
13
14
|
['add-missing-squire-brace', addMissingSquireBrace],
|
|
14
15
|
['add-missing-quote', addMissingQuote],
|
|
16
|
+
['add-missing-semicolon', addMissingSemicolon],
|
|
15
17
|
['add-const-to-export', addConstToExport],
|
|
16
18
|
['convert-comma-to-semicolon', convertCommaToSemicolon],
|
|
17
19
|
['convert-from-to-require', convertFromToRequire],
|
package/lib/runner/path.js
CHANGED
|
@@ -17,10 +17,6 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
17
17
|
tokens,
|
|
18
18
|
end,
|
|
19
19
|
}),
|
|
20
|
-
isNext: createIsNext({
|
|
21
|
-
tokens,
|
|
22
|
-
end,
|
|
23
|
-
}),
|
|
24
20
|
});
|
|
25
21
|
|
|
26
22
|
const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
@@ -37,10 +33,6 @@ const createIsEndsWithPunctuator = ({tokens, end}) => (punctuator) => {
|
|
|
37
33
|
return isPunctuator(current, punctuator);
|
|
38
34
|
};
|
|
39
35
|
|
|
40
|
-
const createIsNext = ({tokens, end}) => () => {
|
|
41
|
-
return Boolean(tokens[end]);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
36
|
const createGetAllPrev = ({tokens, start}) => function*() {
|
|
45
37
|
for (let i = start; i >= 0; --i) {
|
|
46
38
|
yield tokens[i];
|
package/lib/types/types.js
CHANGED
|
@@ -22,7 +22,7 @@ export const isPunctuator = (token, punctuator) => {
|
|
|
22
22
|
if (!punctuator)
|
|
23
23
|
return true;
|
|
24
24
|
|
|
25
|
-
const punctuatorValue = punctuator.value
|
|
25
|
+
const punctuatorValue = punctuator.value;
|
|
26
26
|
|
|
27
27
|
return token.value === punctuatorValue;
|
|
28
28
|
};
|
|
@@ -81,6 +81,7 @@ export const openRoundBrace = Punctuator('(');
|
|
|
81
81
|
export const closeRoundBrace = Punctuator(')');
|
|
82
82
|
export const closeSquareBrace = Punctuator(']');
|
|
83
83
|
export const semicolon = Punctuator(';');
|
|
84
|
+
export const comma = Punctuator(',');
|
|
84
85
|
|
|
85
86
|
export const OK = true;
|
|
86
87
|
export const NOT_OK = false;
|