flatlint 1.4.1 → 1.5.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 +3 -0
- package/lib/compare/compare.js +1 -1
- package/lib/flatlint.js +1 -1
- package/lib/{tokenizer → parser}/index.js +9 -26
- package/lib/parser/string-literal.js +47 -0
- package/lib/plugins/add-missing-quote/index.js +1 -0
- package/lib/runner/replacer.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
package/lib/compare/compare.js
CHANGED
package/lib/flatlint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {loadPlugins} from '@putout/engine-loader';
|
|
2
2
|
import {run} from './runner/runner.js';
|
|
3
|
-
import {parse} from './
|
|
3
|
+
import {parse} from './parser/index.js';
|
|
4
4
|
|
|
5
5
|
export function lint(source, overrides = {}) {
|
|
6
6
|
const {fix = true, plugins: pluginNames = []} = overrides;
|
|
@@ -2,40 +2,23 @@ import tokenize from 'js-tokens';
|
|
|
2
2
|
import {
|
|
3
3
|
isNewLine,
|
|
4
4
|
isStringLiteral,
|
|
5
|
-
Punctuator,
|
|
6
|
-
StringLiteral,
|
|
7
5
|
} from '#types';
|
|
6
|
+
import {parseStringLiteral} from './string-literal.js';
|
|
8
7
|
|
|
9
8
|
const isString = (a) => typeof a === 'string';
|
|
10
9
|
|
|
11
|
-
const
|
|
10
|
+
const preprocess = (tokens) => {
|
|
12
11
|
const n = tokens.length;
|
|
13
12
|
|
|
14
13
|
for (let i = 0; i < n; i++) {
|
|
15
14
|
const token = tokens[i];
|
|
16
15
|
|
|
17
|
-
if (isStringLiteral(token))
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (closed) {
|
|
24
|
-
const literal = StringLiteral(value.slice(1, -1));
|
|
25
|
-
newTokens.push(quote, literal, quote);
|
|
26
|
-
} else if (value.endsWith(';')) {
|
|
27
|
-
const literal = StringLiteral(value.slice(1, -1));
|
|
28
|
-
const semicolon = Punctuator(';');
|
|
29
|
-
|
|
30
|
-
newTokens.push(quote, literal, semicolon);
|
|
31
|
-
} else {
|
|
32
|
-
const literal = StringLiteral(value.slice(1));
|
|
33
|
-
newTokens.push(quote, literal);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
tokens.splice(i, 1, ...newTokens);
|
|
37
|
-
++i;
|
|
38
|
-
}
|
|
16
|
+
if (isStringLiteral(token))
|
|
17
|
+
i = parseStringLiteral({
|
|
18
|
+
token,
|
|
19
|
+
tokens,
|
|
20
|
+
i,
|
|
21
|
+
});
|
|
39
22
|
}
|
|
40
23
|
};
|
|
41
24
|
|
|
@@ -44,7 +27,7 @@ export const prepare = (a) => {
|
|
|
44
27
|
return a;
|
|
45
28
|
|
|
46
29
|
const array = Array.from(tokenize(a));
|
|
47
|
-
|
|
30
|
+
preprocess(array);
|
|
48
31
|
|
|
49
32
|
return array;
|
|
50
33
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {Punctuator, StringLiteral} from '#types';
|
|
2
|
+
|
|
3
|
+
export function parseStringLiteral({i, token, tokens}) {
|
|
4
|
+
const {closed} = token;
|
|
5
|
+
let {value} = token;
|
|
6
|
+
|
|
7
|
+
const quote = Punctuator(value.at(0));
|
|
8
|
+
const newTokens = [quote];
|
|
9
|
+
|
|
10
|
+
if (closed) {
|
|
11
|
+
const literal = StringLiteral(value.slice(1, -1));
|
|
12
|
+
newTokens.push(literal, quote);
|
|
13
|
+
tokens.splice(i, 1, ...newTokens);
|
|
14
|
+
++i;
|
|
15
|
+
} else {
|
|
16
|
+
let count = 0;
|
|
17
|
+
|
|
18
|
+
if (value.endsWith(';')) {
|
|
19
|
+
const semicolon = Punctuator(';');
|
|
20
|
+
|
|
21
|
+
value = value.slice(0, -1);
|
|
22
|
+
newTokens.push(semicolon);
|
|
23
|
+
++count;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (value.endsWith(')')) {
|
|
27
|
+
const brace = Punctuator(')');
|
|
28
|
+
|
|
29
|
+
value = value.slice(0, -1);
|
|
30
|
+
const {length} = newTokens;
|
|
31
|
+
const start = !count ? length : length - 1;
|
|
32
|
+
|
|
33
|
+
newTokens.splice(start, 0, brace);
|
|
34
|
+
++count;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
++count;
|
|
38
|
+
|
|
39
|
+
const literal = StringLiteral(value.slice(1));
|
|
40
|
+
newTokens.splice(1, 0, literal);
|
|
41
|
+
|
|
42
|
+
tokens.splice(i, 1, ...newTokens);
|
|
43
|
+
i += count;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return i;
|
|
47
|
+
}
|
package/lib/runner/replacer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {compare} from '../compare/compare.js';
|
|
2
2
|
import {traverse} from '../traverser/traverser.js';
|
|
3
3
|
import {is} from '../types/types.js';
|
|
4
|
-
import {prepare} from '../
|
|
4
|
+
import {prepare} from '../parser/index.js';
|
|
5
5
|
|
|
6
6
|
const {entries} = Object;
|
|
7
7
|
|