flatlint 1.14.0 → 1.16.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 +11 -2
- package/lib/compare/collect-array.js +1 -1
- package/lib/compare/collect-expression.js +1 -1
- package/lib/plugins/add-missing-square-brace/index.js +1 -1
- package/lib/plugins/remove-useless-square-brace/index.js +5 -0
- package/lib/runner/replacer.js +7 -35
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -78,6 +78,15 @@ npm i flatlint
|
|
|
78
78
|
|
|
79
79
|
</details>
|
|
80
80
|
|
|
81
|
+
<details><summary>remove useless square brace</summary>
|
|
82
|
+
|
|
83
|
+
```diff
|
|
84
|
+
-const a = [1, 2, 3]];
|
|
85
|
+
+const a = [1, 2, 3];
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
</details>
|
|
89
|
+
|
|
81
90
|
<details><summary>add missing quote</summary>
|
|
82
91
|
|
|
83
92
|
```diff
|
|
@@ -96,8 +105,8 @@ npm i flatlint
|
|
|
96
105
|
|
|
97
106
|
It can look similar, but has a couple differences:
|
|
98
107
|
|
|
99
|
-
- ✅it may not be valid **JavaScript**, it can be couple tokens that can be fixed;
|
|
100
|
-
- ✅it counts each symbol as a token;
|
|
108
|
+
- ✅ it may not be valid **JavaScript**, it can be couple tokens that can be fixed;
|
|
109
|
+
- ✅ it counts each symbol as a token;
|
|
101
110
|
|
|
102
111
|
### `__a`
|
|
103
112
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Punctuator} from '#types';
|
|
2
2
|
import {equal} from './equal.js';
|
|
3
3
|
|
|
4
|
-
export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken}) => {
|
|
4
|
+
export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
|
|
5
5
|
const n = tokens.length;
|
|
6
6
|
const brace = Punctuator(']');
|
|
7
7
|
let index = currentTokenIndex;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Punctuator} from '#types';
|
|
2
2
|
import {equal} from './equal.js';
|
|
3
3
|
|
|
4
|
-
export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken}) => {
|
|
4
|
+
export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
|
|
5
5
|
const n = tokens.length;
|
|
6
6
|
const closeBrace = Punctuator(')');
|
|
7
7
|
const openBrace = Punctuator('(');
|
package/lib/runner/replacer.js
CHANGED
|
@@ -5,12 +5,10 @@ import {
|
|
|
5
5
|
is,
|
|
6
6
|
isTemplateArray,
|
|
7
7
|
isTemplateExpression,
|
|
8
|
-
Punctuator,
|
|
9
8
|
} from '#types';
|
|
10
9
|
import {collectArray} from '../compare/collect-array.js';
|
|
11
10
|
import {collectExpression} from '../compare/collect-expression.js';
|
|
12
11
|
|
|
13
|
-
const {isArray} = Array;
|
|
14
12
|
const {entries} = Object;
|
|
15
13
|
|
|
16
14
|
export const replace = (tokens, {fix, rule, plugin}) => {
|
|
@@ -87,39 +85,20 @@ function getValues(tokens, waysFrom) {
|
|
|
87
85
|
const values = {};
|
|
88
86
|
|
|
89
87
|
for (const [name, index] of entries(waysFrom)) {
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
let end = index;
|
|
89
|
+
|
|
90
|
+
if (isTemplateArray(name))
|
|
91
|
+
end = collectArray({
|
|
92
92
|
currentTokenIndex: index,
|
|
93
93
|
tokens,
|
|
94
|
-
nextTemplateToken: Punctuator(';'),
|
|
95
94
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
values[name] = tokens[index];
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
values[name] = tokens.slice(index, endOfArray + 1);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (isTemplateExpression(name)) {
|
|
107
|
-
const endOfArray = collectExpression({
|
|
95
|
+
else if (isTemplateExpression(name))
|
|
96
|
+
end = collectExpression({
|
|
108
97
|
currentTokenIndex: index,
|
|
109
98
|
tokens,
|
|
110
|
-
nextTemplateToken: Punctuator(';'),
|
|
111
99
|
});
|
|
112
|
-
|
|
113
|
-
if (index === endOfArray) {
|
|
114
|
-
values[name] = tokens[index];
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
values[name] = tokens.slice(index, endOfArray + 1);
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
100
|
|
|
122
|
-
values[name] = tokens
|
|
101
|
+
values[name] = tokens.slice(index, end + 1);
|
|
123
102
|
}
|
|
124
103
|
|
|
125
104
|
return values;
|
|
@@ -127,13 +106,6 @@ function getValues(tokens, waysFrom) {
|
|
|
127
106
|
|
|
128
107
|
function setValues({to, waysTo, values}) {
|
|
129
108
|
for (const [name, index] of entries(waysTo)) {
|
|
130
|
-
const current = values[name];
|
|
131
|
-
|
|
132
|
-
if (!isArray(current)) {
|
|
133
|
-
to[index] = values[name];
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
109
|
to.splice(index, 1, ...values[name]);
|
|
138
110
|
}
|
|
139
111
|
}
|