flatlint 1.24.1 → 1.26.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 +11 -0
- package/README.md +9 -1
- package/lib/compare/collect-args.js +4 -0
- package/lib/compare/compare.js +4 -1
- package/lib/flatlint.js +3 -1
- package/lib/parser/string-literal.js +14 -4
- package/lib/plugins/add-missing-quote/index.js +5 -0
- package/lib/plugins/add-missing-round-braces/index.js +7 -0
- package/lib/runner/path.js +8 -11
- package/lib/runner/replacer.js +3 -0
- package/lib/traverser/traverser.js +1 -1
- package/lib/types/types.js +1 -1
- package/package.json +2 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2025.01.07, v1.26.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 0ba6115 flatlint: add-missing-quote: round brace before quote
|
|
5
|
+
- 0aca502 flatlint: add-missing-round-brace: improve
|
|
6
|
+
|
|
7
|
+
2025.01.06, v1.25.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 9016c56 flatlint: add-missing-round-brace: improve
|
|
11
|
+
|
|
1
12
|
2025.01.05, v1.24.1
|
|
2
13
|
|
|
3
14
|
feature:
|
package/README.md
CHANGED
|
@@ -37,13 +37,21 @@ 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');
|
|
50
|
+
|
|
51
|
+
const m = {
|
|
52
|
+
- z: z('hello'
|
|
53
|
+
+ z: z('hello')
|
|
54
|
+
}
|
|
47
55
|
```
|
|
48
56
|
|
|
49
57
|
</details>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
closeRoundBrace,
|
|
3
|
+
isNewLine,
|
|
3
4
|
NOT_OK,
|
|
4
5
|
OK,
|
|
5
6
|
} from '#types';
|
|
@@ -17,6 +18,9 @@ export const collectArgs = ({currentTokenIndex, tokens}) => {
|
|
|
17
18
|
|
|
18
19
|
if (equal(token, closeRoundBrace))
|
|
19
20
|
break;
|
|
21
|
+
|
|
22
|
+
if (isNewLine(token))
|
|
23
|
+
break;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
return [
|
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;
|
package/lib/flatlint.js
CHANGED
|
@@ -3,7 +3,9 @@ import {parse} from '#parser';
|
|
|
3
3
|
import {run} from '#runner';
|
|
4
4
|
|
|
5
5
|
const getValue = (token) => token.value;
|
|
6
|
-
const print = (tokens) => tokens
|
|
6
|
+
const print = (tokens) => tokens
|
|
7
|
+
.map(getValue)
|
|
8
|
+
.join('');
|
|
7
9
|
|
|
8
10
|
export function lint(source, overrides = {}) {
|
|
9
11
|
const {fix = true, plugins: pluginNames = []} = overrides;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
closeRoundBrace,
|
|
3
|
+
comma,
|
|
4
|
+
Punctuator,
|
|
5
|
+
semicolon,
|
|
6
|
+
StringLiteral,
|
|
7
|
+
} from '#types';
|
|
2
8
|
|
|
3
9
|
export function parseStringLiteral({i, token, tokens}) {
|
|
4
10
|
const {closed} = token;
|
|
@@ -17,15 +23,19 @@ export function parseStringLiteral({i, token, tokens}) {
|
|
|
17
23
|
let count = 0;
|
|
18
24
|
|
|
19
25
|
if (value.endsWith(';')) {
|
|
20
|
-
const semicolon = Punctuator(';');
|
|
21
|
-
|
|
22
26
|
value = value.slice(0, -1);
|
|
23
27
|
newTokens.push(semicolon);
|
|
24
28
|
++count;
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
if (value.endsWith(',')) {
|
|
32
|
+
value = value.slice(0, -1);
|
|
33
|
+
newTokens.push(comma);
|
|
34
|
+
++count;
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
if (value.endsWith(')')) {
|
|
28
|
-
const brace =
|
|
38
|
+
const brace = closeRoundBrace;
|
|
29
39
|
|
|
30
40
|
value = value.slice(0, -1);
|
|
31
41
|
const {length} = newTokens;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export const report = () => 'Add missing quote';
|
|
2
2
|
|
|
3
|
+
export const match = () => ({
|
|
4
|
+
'__a("__b': (vars, path) => !path.isNextPunctuator(vars.quote),
|
|
5
|
+
});
|
|
6
|
+
|
|
3
7
|
export const replace = () => ({
|
|
4
8
|
'const __a = "__b;': 'const __a = "__b";',
|
|
5
9
|
'__a("__b)': '__a("__b")',
|
|
10
|
+
'__a("__b': '__a("__b")',
|
|
6
11
|
});
|
|
@@ -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
|
});
|
package/lib/runner/path.js
CHANGED
|
@@ -13,16 +13,22 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
13
13
|
tokens,
|
|
14
14
|
end,
|
|
15
15
|
}),
|
|
16
|
-
isEndsWithPunctuator:
|
|
16
|
+
isEndsWithPunctuator: createIsCurrentPunctuator({
|
|
17
17
|
tokens,
|
|
18
18
|
end,
|
|
19
19
|
}),
|
|
20
|
-
|
|
20
|
+
isCurrentPunctuator: createIsCurrentPunctuator({
|
|
21
21
|
tokens,
|
|
22
22
|
end,
|
|
23
23
|
}),
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
const createIsCurrentPunctuator = ({tokens, end}) => (punctuator) => {
|
|
27
|
+
const current = tokens[end - 1];
|
|
28
|
+
|
|
29
|
+
return isPunctuator(current, punctuator);
|
|
30
|
+
};
|
|
31
|
+
|
|
26
32
|
const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
27
33
|
const current = tokens[end];
|
|
28
34
|
|
|
@@ -32,15 +38,6 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
|
32
38
|
return isPunctuator(current, punctuator);
|
|
33
39
|
};
|
|
34
40
|
|
|
35
|
-
const createIsEndsWithPunctuator = ({tokens, end}) => (punctuator) => {
|
|
36
|
-
const current = tokens[end - 1];
|
|
37
|
-
return isPunctuator(current, punctuator);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const createIsNext = ({tokens, end}) => () => {
|
|
41
|
-
return Boolean(tokens[end]);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
41
|
const createGetAllPrev = ({tokens, start}) => function*() {
|
|
45
42
|
for (let i = start; i >= 0; --i) {
|
|
46
43
|
yield tokens[i];
|
package/lib/runner/replacer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
1
2
|
import {compare} from '#compare';
|
|
2
3
|
import {prepare} from '#parser';
|
|
3
4
|
import {traverse} from '#traverser';
|
|
@@ -14,6 +15,7 @@ import {collectArgs} from '../compare/collect-args.js';
|
|
|
14
15
|
|
|
15
16
|
const returns = (a) => () => a;
|
|
16
17
|
const {entries} = Object;
|
|
18
|
+
const log = debug('flatlint');
|
|
17
19
|
|
|
18
20
|
export const replace = (tokens, {fix, rule, plugin}) => {
|
|
19
21
|
const places = [];
|
|
@@ -47,6 +49,7 @@ export const replace = (tokens, {fix, rule, plugin}) => {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
if (fix) {
|
|
52
|
+
log(`${rule}: ${from} -> ${to}`);
|
|
50
53
|
to = prepare(to);
|
|
51
54
|
const waysTo = findVarsWays(to);
|
|
52
55
|
|
package/lib/types/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatlint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "JavaScript tokens-based linter",
|
|
5
5
|
"main": "lib/flatlint.js",
|
|
6
6
|
"type": "module",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@putout/engine-loader": "^15.0.1",
|
|
79
|
+
"debug": "^4.4.0",
|
|
79
80
|
"js-tokens": "^9.0.1",
|
|
80
81
|
"putout": "^37.0.0"
|
|
81
82
|
},
|