flatlint 4.2.0 → 4.3.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 +9 -0
- package/lib/compare/values.js +25 -9
- package/lib/plugins/split-namespace-with-specifier/index.js +5 -0
- package/lib/plugins.js +2 -0
- package/package.json +2 -2
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -371,6 +371,15 @@ const a = class {
|
|
|
371
371
|
|
|
372
372
|
</details>
|
|
373
373
|
|
|
374
|
+
<details><summary>split <code>namespace</code> with <code>specifier</code></summary>
|
|
375
|
+
|
|
376
|
+
```diff
|
|
377
|
+
-import * as plugin, {CUT} from './plugin.js'
|
|
378
|
+
+import * as plugin, {CUT} from './plugin.js'
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
</details>
|
|
382
|
+
|
|
374
383
|
## Template literals
|
|
375
384
|
|
|
376
385
|
**FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
|
package/lib/compare/values.js
CHANGED
|
@@ -15,18 +15,20 @@ const maybeArray = (a) => isArray(a) ? a : [a];
|
|
|
15
15
|
|
|
16
16
|
const {entries} = Object;
|
|
17
17
|
|
|
18
|
+
const createAddWay = (ways) => ({value, index}) => {
|
|
19
|
+
if (is(value)) {
|
|
20
|
+
ways[value] = ways[value] || [];
|
|
21
|
+
ways[value].push(index);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
18
25
|
export function findVarsWays(tokens) {
|
|
19
26
|
const ways = {};
|
|
27
|
+
const add = createAddWay(ways);
|
|
20
28
|
|
|
21
29
|
traverse(tokens, {
|
|
22
|
-
Identifier
|
|
23
|
-
|
|
24
|
-
ways[value] = index;
|
|
25
|
-
},
|
|
26
|
-
StringLiteral({value, index}) {
|
|
27
|
-
if (is(value))
|
|
28
|
-
ways[value] = index;
|
|
29
|
-
},
|
|
30
|
+
Identifier: add,
|
|
31
|
+
StringLiteral: add,
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
return ways;
|
|
@@ -71,7 +73,9 @@ export function getValues(tokens, waysFrom) {
|
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
export function setValues({to, waysTo, values}) {
|
|
74
|
-
|
|
76
|
+
const namesWithIndexes = getNamesWithIndexes(waysTo);
|
|
77
|
+
|
|
78
|
+
for (const [name, index] of namesWithIndexes) {
|
|
75
79
|
const current = maybeArray(values[name]);
|
|
76
80
|
to.splice(index, 1, ...current);
|
|
77
81
|
}
|
|
@@ -83,3 +87,15 @@ export function getCurrentValues({from, start, end, tokens}) {
|
|
|
83
87
|
|
|
84
88
|
return getValues(current, waysFrom);
|
|
85
89
|
}
|
|
90
|
+
|
|
91
|
+
function getNamesWithIndexes(waysTo) {
|
|
92
|
+
const namesWithIndexes = [];
|
|
93
|
+
|
|
94
|
+
for (const [name, ways] of entries(waysTo)) {
|
|
95
|
+
for (const index of ways) {
|
|
96
|
+
namesWithIndexes.push([name, index]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return namesWithIndexes;
|
|
101
|
+
}
|
package/lib/plugins.js
CHANGED
|
@@ -19,6 +19,7 @@ import * as removeUselessAssign from './plugins/remove-useless-assign/index.js';
|
|
|
19
19
|
import * as removeUselessDot from './plugins/remove-useless-dot/index.js';
|
|
20
20
|
import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
|
|
21
21
|
import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
|
|
22
|
+
import * as splitNamespaceWithSpecifier from './plugins/split-namespace-with-specifier/index.js';
|
|
22
23
|
import * as convertSemicolonToComma from './plugins/convert-semicolon-to-comma/index.js';
|
|
23
24
|
import * as convertColonToComma from './plugins/convert-colon-to-comma/index.js';
|
|
24
25
|
import * as convertColonToSemicolon from './plugins/convert-colon-to-semicolon/index.js';
|
|
@@ -53,5 +54,6 @@ export const plugins = [
|
|
|
53
54
|
['remove-useless-assign', removeUselessAssign],
|
|
54
55
|
['remove-useless-dot', removeUselessDot],
|
|
55
56
|
['remove-invalid-character', removeInvalidCharacter],
|
|
57
|
+
['split-namespace-with-specifier', splitNamespaceWithSpecifier],
|
|
56
58
|
['wrap-assignment-in-parens', wrapAssignmentInParens],
|
|
57
59
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatlint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "JavaScript tokens-based linter",
|
|
5
5
|
"main": "lib/flatlint.js",
|
|
6
6
|
"type": "module",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@putout/test": "^15.0.0",
|
|
87
87
|
"c8": "^10.1.2",
|
|
88
88
|
"eslint": "^9.7.0",
|
|
89
|
-
"eslint-plugin-putout": "^
|
|
89
|
+
"eslint-plugin-putout": "^30.0.1",
|
|
90
90
|
"madrun": "^12.1.0",
|
|
91
91
|
"mock-require": "^3.0.3",
|
|
92
92
|
"montag": "^1.0.0",
|