flatlint 3.10.2 → 3.12.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 +10 -0
- package/README.md +21 -0
- package/lib/compare/compare.js +4 -4
- package/lib/plugins/add-missing-if/index.js +5 -0
- 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-arrow/index.js +1 -1
- package/lib/plugins/remove-useless-assign/index.js +7 -0
- package/lib/plugins.js +6 -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
|
|
@@ -339,6 +348,18 @@ const a = class {
|
|
|
339
348
|
|
|
340
349
|
</details>
|
|
341
350
|
|
|
351
|
+
<details><summary>add missing <code>if</code></summary>
|
|
352
|
+
|
|
353
|
+
```diff
|
|
354
|
+
if (a < 0)
|
|
355
|
+
console.log('hello');
|
|
356
|
+
- else (a > 3)
|
|
357
|
+
+ else if (a > 3)
|
|
358
|
+
console.log('world');
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
</details>
|
|
362
|
+
|
|
342
363
|
## Template literals
|
|
343
364
|
|
|
344
365
|
**FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
|
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 '='`;
|
|
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
|
@@ -6,6 +6,7 @@ import * as addMissingSquireBrace from './plugins/add-missing-square-brace/index
|
|
|
6
6
|
import * as addMissingQuote from './plugins/add-missing-quote/index.js';
|
|
7
7
|
import * as addMissingSemicolon from './plugins/add-missing-semicolon/index.js';
|
|
8
8
|
import * as addMissingComma from './plugins/add-missing-comma/index.js';
|
|
9
|
+
import * as addMissingIf from './plugins/add-missing-if/index.js';
|
|
9
10
|
import * as addConstToExport from './plugins/add-const-to-export/index.js';
|
|
10
11
|
import * as applyImportOrder from './plugins/apply-import-order/index.js';
|
|
11
12
|
import * as applyImportFrom from './plugins/apply-import-from/index.js';
|
|
@@ -13,6 +14,8 @@ import * as convertAssertToWith from './plugins/convert-assert-to-with/index.js'
|
|
|
13
14
|
import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/index.js';
|
|
14
15
|
import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
|
|
15
16
|
import * as removeUselessComma from './plugins/remove-useless-comma/index.js';
|
|
17
|
+
import * as removeUselessArrow from './plugins/remove-useless-arrow/index.js';
|
|
18
|
+
import * as removeUselessAssign from './plugins/remove-useless-assign/index.js';
|
|
16
19
|
import * as removeUselessDot from './plugins/remove-useless-dot/index.js';
|
|
17
20
|
import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
|
|
18
21
|
import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
|
|
@@ -24,6 +27,7 @@ import * as wrapAssignmentInParens from './plugins/wrap-assignment-in-parens/ind
|
|
|
24
27
|
|
|
25
28
|
export const plugins = [
|
|
26
29
|
['add-missing-comma', addMissingComma],
|
|
30
|
+
['add-missing-if', addMissingIf],
|
|
27
31
|
['add-missing-quote', addMissingQuote],
|
|
28
32
|
['add-const-to-export', addConstToExport],
|
|
29
33
|
['add-missing-semicolon', addMissingSemicolon],
|
|
@@ -43,6 +47,8 @@ export const plugins = [
|
|
|
43
47
|
['convert-from-to-require', convertFromToRequire],
|
|
44
48
|
['remove-useless-comma', removeUselessComma],
|
|
45
49
|
['remove-useless-round-brace', removeUselessRoundBrace],
|
|
50
|
+
['remove-useless-arrow', removeUselessArrow],
|
|
51
|
+
['remove-useless-assign', removeUselessAssign],
|
|
46
52
|
['remove-useless-dot', removeUselessDot],
|
|
47
53
|
['remove-invalid-character', removeInvalidCharacter],
|
|
48
54
|
['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
|
});
|