flatlint 3.10.2 → 3.11.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 +5 -0
- package/README.md +9 -0
- package/lib/compare/compare.js +4 -4
- package/lib/plugins/add-missing-square-brace/index.js +1 -0
- package/lib/plugins/convert-from-to-require/index.js +13 -0
- package/lib/plugins/remove-useless-assign/index.js +7 -0
- package/lib/plugins.js +4 -0
- package/lib/runner/replacer.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -319,6 +319,15 @@ t.equal(expected, []);
|
|
|
319
319
|
|
|
320
320
|
</details>
|
|
321
321
|
|
|
322
|
+
<details><summary>Remove useless assign</summary>
|
|
323
|
+
|
|
324
|
+
```diff
|
|
325
|
+
-import {readFile, readdir} = from 'node:fs/promises';
|
|
326
|
+
+import {readFile, readdir} from 'node:fs/promises';
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
</details>
|
|
330
|
+
|
|
322
331
|
<details><summary>Remove useless coma</summary>
|
|
323
332
|
|
|
324
333
|
```diff
|
package/lib/compare/compare.js
CHANGED
|
@@ -75,7 +75,7 @@ export const compare = (source, template, {index = 0} = {}) => {
|
|
|
75
75
|
index = indexOfExpressionEnd - templateIndex;
|
|
76
76
|
}
|
|
77
77
|
} else if (isTemplateArrayToken(templateToken)) {
|
|
78
|
-
const [ok,
|
|
78
|
+
const [ok, end] = collectArray({
|
|
79
79
|
currentTokenIndex,
|
|
80
80
|
tokens,
|
|
81
81
|
templateToken,
|
|
@@ -84,9 +84,9 @@ export const compare = (source, template, {index = 0} = {}) => {
|
|
|
84
84
|
|
|
85
85
|
if (!ok) {
|
|
86
86
|
++skip;
|
|
87
|
-
} else {
|
|
88
|
-
delta =
|
|
89
|
-
index =
|
|
87
|
+
} else if (currentTokenIndex < end) {
|
|
88
|
+
delta = end - currentTokenIndex;
|
|
89
|
+
index = end - templateIndex;
|
|
90
90
|
}
|
|
91
91
|
} else if (!equalTemplate(currentToken, templateToken)) {
|
|
92
92
|
isEqual = false;
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
import {isKeyword} from '#types';
|
|
2
|
+
|
|
1
3
|
export const report = () => `Use 'require' instead of 'from'`;
|
|
2
4
|
|
|
5
|
+
export const match = () => ({
|
|
6
|
+
'= from "__a"': (vars, path) => {
|
|
7
|
+
for (const current of path.getAllPrev()) {
|
|
8
|
+
if (isKeyword(current, 'import'))
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return true;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
3
16
|
export const replace = () => ({
|
|
4
17
|
'= from "__a"': '= require("__a")',
|
|
5
18
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const report = () => 'Remove useless assign';
|
|
2
|
+
|
|
3
|
+
export const replace = () => ({
|
|
4
|
+
'import __a = from "__b"': 'import __a from "__b"',
|
|
5
|
+
'import {__a} = from "__b"': 'import {__a} from "__b"',
|
|
6
|
+
'import {__a, __b} = from "__c"': 'import {__a, __b} from "__c"',
|
|
7
|
+
});
|
package/lib/plugins.js
CHANGED
|
@@ -13,6 +13,8 @@ import * as convertAssertToWith from './plugins/convert-assert-to-with/index.js'
|
|
|
13
13
|
import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/index.js';
|
|
14
14
|
import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
|
|
15
15
|
import * as removeUselessComma from './plugins/remove-useless-comma/index.js';
|
|
16
|
+
import * as removeUselessArrow from './plugins/remove-useless-arrow/index.js';
|
|
17
|
+
import * as removeUselessAssign from './plugins/remove-useless-assign/index.js';
|
|
16
18
|
import * as removeUselessDot from './plugins/remove-useless-dot/index.js';
|
|
17
19
|
import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
|
|
18
20
|
import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
|
|
@@ -43,6 +45,8 @@ export const plugins = [
|
|
|
43
45
|
['convert-from-to-require', convertFromToRequire],
|
|
44
46
|
['remove-useless-comma', removeUselessComma],
|
|
45
47
|
['remove-useless-round-brace', removeUselessRoundBrace],
|
|
48
|
+
['remove-useless-arrow', removeUselessArrow],
|
|
49
|
+
['remove-useless-assign', removeUselessAssign],
|
|
46
50
|
['remove-useless-dot', removeUselessDot],
|
|
47
51
|
['remove-invalid-character', removeInvalidCharacter],
|
|
48
52
|
['wrap-assignment-in-parens', wrapAssignmentInParens],
|
package/lib/runner/replacer.js
CHANGED
|
@@ -10,9 +10,11 @@ import {createPath} from './path.js';
|
|
|
10
10
|
|
|
11
11
|
const returns = (a) => () => a;
|
|
12
12
|
const {entries} = Object;
|
|
13
|
+
|
|
13
14
|
const logCompare = createDebug('flatlint:compare', {
|
|
14
15
|
useColors: true,
|
|
15
16
|
});
|
|
17
|
+
|
|
16
18
|
const logFix = createDebug('flatlint:fix', {
|
|
17
19
|
useColors: true,
|
|
18
20
|
});
|