flatlint 1.0.2 → 1.2.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 +31 -0
- package/lib/compare/compare.js +3 -25
- package/lib/plugins/add-missing-round-braces/index.js +9 -0
- package/lib/plugins/convert-comma-to-semicolon/index.js +9 -0
- package/lib/plugins/wrap-assignment-in-parens/index.js +4 -4
- package/lib/tokenizer/index.js +4 -3
- package/package.json +2 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -8,6 +8,37 @@ Token-based JavaScript linter that fixes Syntax Errors
|
|
|
8
8
|
npm i flatlint
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Available fixes
|
|
12
|
+
|
|
13
|
+
<details><summary>Assignment without parentheses after <code>&&</code></summary>
|
|
14
|
+
|
|
15
|
+
```diff
|
|
16
|
+
-a && b = c;
|
|
17
|
+
+a && (b = c);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
</details>
|
|
21
|
+
|
|
22
|
+
<details><summary>Convert <code>,</code> to <code>;</code> at the end of statement</summary>
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
-const a = 5,
|
|
26
|
+
+const a = 5;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
</details>
|
|
30
|
+
|
|
31
|
+
<details><summary>forgotten round braces in if statement</summary>¬
|
|
32
|
+
|
|
33
|
+
```diff¬
|
|
34
|
+
-if a > 5 {
|
|
35
|
+
+if (a > 5) {
|
|
36
|
+
alert();
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
</details>
|
|
41
|
+
|
|
11
42
|
## API
|
|
12
43
|
|
|
13
44
|
```js
|
package/lib/compare/compare.js
CHANGED
|
@@ -2,9 +2,7 @@ import {prepare} from '../tokenizer/index.js';
|
|
|
2
2
|
import {
|
|
3
3
|
isId,
|
|
4
4
|
isIdentifier,
|
|
5
|
-
isNewLine,
|
|
6
5
|
isPunctuator,
|
|
7
|
-
isWhiteSpace,
|
|
8
6
|
} from './types.js';
|
|
9
7
|
|
|
10
8
|
export const compare = (source, template) => {
|
|
@@ -17,31 +15,11 @@ export const compare = (source, template) => {
|
|
|
17
15
|
let end = 0;
|
|
18
16
|
|
|
19
17
|
for (let index = 0; index < n; index++) {
|
|
20
|
-
let tokenDelta = 0;
|
|
21
|
-
let templateDelta = 0;
|
|
22
|
-
|
|
23
18
|
for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
|
|
24
|
-
const currentTokenIndex = index + templateIndex
|
|
25
|
-
|
|
26
|
-
if (currentTokenIndex === n + 1)
|
|
27
|
-
break;
|
|
28
|
-
|
|
29
|
-
const templateToken = templateTokens[templateIndex - templateDelta];
|
|
19
|
+
const currentTokenIndex = index + templateIndex;
|
|
20
|
+
const templateToken = templateTokens[templateIndex];
|
|
30
21
|
const currentToken = tokens[currentTokenIndex];
|
|
31
22
|
|
|
32
|
-
if (isWhiteSpace(currentToken)) {
|
|
33
|
-
++templateDelta;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (isWhiteSpace(templateToken)) {
|
|
38
|
-
++tokenDelta;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (isNewLine(currentToken))
|
|
43
|
-
continue;
|
|
44
|
-
|
|
45
23
|
if (!compareAll(currentToken, templateToken)) {
|
|
46
24
|
isEqual = false;
|
|
47
25
|
break;
|
|
@@ -49,7 +27,7 @@ export const compare = (source, template) => {
|
|
|
49
27
|
|
|
50
28
|
isEqual = true;
|
|
51
29
|
start = index;
|
|
52
|
-
end = currentTokenIndex
|
|
30
|
+
end = currentTokenIndex;
|
|
53
31
|
}
|
|
54
32
|
|
|
55
33
|
if (isEqual)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
export function report() {
|
|
2
|
+
return `Wrap the assignment in parentheses after '&&'`;
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
export function replace() {
|
|
2
6
|
return {
|
|
3
7
|
'__a && __b = __c': '__a && (__b = __c)',
|
|
4
8
|
};
|
|
5
9
|
}
|
|
6
|
-
|
|
7
|
-
export function report() {
|
|
8
|
-
return `Wrap the assignment in parentheses after '&&'`;
|
|
9
|
-
}
|
package/lib/tokenizer/index.js
CHANGED
|
@@ -20,10 +20,8 @@ function getTokensWithLocation(tokens) {
|
|
|
20
20
|
const result = [];
|
|
21
21
|
|
|
22
22
|
for (const token of tokens) {
|
|
23
|
-
if (isNewLine(token))
|
|
23
|
+
if (isNewLine(token))
|
|
24
24
|
++line;
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
25
|
|
|
28
26
|
result.push({
|
|
29
27
|
...token,
|
|
@@ -32,6 +30,9 @@ function getTokensWithLocation(tokens) {
|
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
column += token.value.length;
|
|
33
|
+
|
|
34
|
+
if (isNewLine(token))
|
|
35
|
+
column = 1;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatlint",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "JavaScript tokens-based linter",
|
|
5
5
|
"main": "lib/flatlint.js",
|
|
6
6
|
"type": "module",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"yargs-parser": "^21.0.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
+
"@putout/eslint-flat": "^2.0.0",
|
|
79
80
|
"@putout/formatter-json": "^2.0.0",
|
|
80
81
|
"@putout/test": "^11.1.0",
|
|
81
82
|
"c8": "^10.1.2",
|