flatlint 1.25.0 → 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 +6 -0
- package/README.md +5 -0
- package/lib/compare/collect-args.js +4 -0
- 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/runner/path.js +11 -6
- package/lib/runner/replacer.js +3 -0
- package/lib/traverser/traverser.js +1 -1
- package/package.json +2 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -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/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
|
});
|
package/lib/runner/path.js
CHANGED
|
@@ -13,12 +13,22 @@ export const createPath = ({tokens, start, end}) => ({
|
|
|
13
13
|
tokens,
|
|
14
14
|
end,
|
|
15
15
|
}),
|
|
16
|
-
isEndsWithPunctuator:
|
|
16
|
+
isEndsWithPunctuator: createIsCurrentPunctuator({
|
|
17
|
+
tokens,
|
|
18
|
+
end,
|
|
19
|
+
}),
|
|
20
|
+
isCurrentPunctuator: createIsCurrentPunctuator({
|
|
17
21
|
tokens,
|
|
18
22
|
end,
|
|
19
23
|
}),
|
|
20
24
|
});
|
|
21
25
|
|
|
26
|
+
const createIsCurrentPunctuator = ({tokens, end}) => (punctuator) => {
|
|
27
|
+
const current = tokens[end - 1];
|
|
28
|
+
|
|
29
|
+
return isPunctuator(current, punctuator);
|
|
30
|
+
};
|
|
31
|
+
|
|
22
32
|
const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
23
33
|
const current = tokens[end];
|
|
24
34
|
|
|
@@ -28,11 +38,6 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
|
|
|
28
38
|
return isPunctuator(current, punctuator);
|
|
29
39
|
};
|
|
30
40
|
|
|
31
|
-
const createIsEndsWithPunctuator = ({tokens, end}) => (punctuator) => {
|
|
32
|
-
const current = tokens[end - 1];
|
|
33
|
-
return isPunctuator(current, punctuator);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
41
|
const createGetAllPrev = ({tokens, start}) => function*() {
|
|
37
42
|
for (let i = start; i >= 0; --i) {
|
|
38
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/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
|
},
|