flatlint 1.20.0 → 1.21.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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2025.01.03, v1.21.0
2
+
3
+ feature:
4
+ - d13da41 flatlint: add-missing-squire-brace: empty array
5
+
1
6
  2025.01.03, v1.20.0
2
7
 
3
8
  feature:
@@ -1,33 +1,34 @@
1
1
  import {
2
- CloseRoundBrace,
2
+ closeRoundBrace,
3
+ closeSquareBrace,
4
+ NOT_OK,
5
+ OK,
3
6
  OpenRoundBrace,
4
- Punctuator,
5
7
  } from '#types';
6
8
  import {equal} from './equal.js';
7
9
 
8
- export const collectArgs = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(')')}) => {
10
+ export const collectArgs = ({currentTokenIndex, tokens, nextTemplateToken = closeRoundBrace}) => {
9
11
  const n = tokens.length;
10
- const brace = Punctuator(']');
11
12
  let index = currentTokenIndex;
12
13
 
13
- if (equal(tokens[index - 1], OpenRoundBrace) && equal(tokens[index], CloseRoundBrace))
14
- return [false];
14
+ if (equal(tokens[index - 1], OpenRoundBrace) && equal(tokens[index], closeRoundBrace))
15
+ return [NOT_OK];
15
16
 
16
17
  for (; index < n; index++) {
17
18
  const token = tokens[index];
18
19
 
19
- if (equal(token, CloseRoundBrace))
20
+ if (equal(token, closeRoundBrace))
20
21
  break;
21
22
 
22
23
  if (equal(token, nextTemplateToken))
23
24
  break;
24
25
 
25
- if (equal(token, brace))
26
+ if (equal(token, closeSquareBrace))
26
27
  break;
27
28
  }
28
29
 
29
30
  return [
30
- true,
31
+ OK,
31
32
  --index,
32
33
  ];
33
34
  };
@@ -1,26 +1,34 @@
1
1
  import {
2
- CloseRoundBrace,
3
- Punctuator,
2
+ closeRoundBrace,
3
+ closeSquareBrace,
4
+ semicolon,
5
+ OK,
6
+ NOT_OK,
4
7
  } from '#types';
5
8
  import {equal} from './equal.js';
6
9
 
7
- export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
10
+ export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = semicolon}) => {
8
11
  const n = tokens.length;
9
- const brace = Punctuator(']');
10
12
  let index = currentTokenIndex;
11
13
 
14
+ if (equal(tokens[index], closeSquareBrace))
15
+ return [NOT_OK];
16
+
12
17
  for (; index < n; index++) {
13
18
  const token = tokens[index];
14
19
 
15
- if (equal(token, CloseRoundBrace))
20
+ if (equal(token, closeRoundBrace))
16
21
  break;
17
22
 
18
23
  if (equal(token, nextTemplateToken))
19
24
  break;
20
25
 
21
- if (equal(token, brace))
26
+ if (equal(token, closeSquareBrace))
22
27
  break;
23
28
  }
24
29
 
25
- return --index;
30
+ return [
31
+ OK,
32
+ --index,
33
+ ];
26
34
  };
@@ -64,15 +64,19 @@ export const compare = (source, template) => {
64
64
  delta = indexOfExpressionEnd - currentTokenIndex;
65
65
  index = indexOfExpressionEnd - templateIndex;
66
66
  } else if (isTemplateArrayToken(templateToken)) {
67
- const indexOfArrayEnd = collectArray({
67
+ const [ok, indexOfArrayEnd] = collectArray({
68
68
  currentTokenIndex,
69
69
  tokens,
70
70
  templateToken,
71
71
  nextTemplateToken: templateTokens[templateIndex + 1],
72
72
  });
73
73
 
74
- delta = indexOfArrayEnd - currentTokenIndex;
75
- index = indexOfArrayEnd - templateIndex;
74
+ if (!ok) {
75
+ ++skip;
76
+ } else {
77
+ delta = indexOfArrayEnd - currentTokenIndex;
78
+ index = indexOfArrayEnd - templateIndex;
79
+ }
76
80
  } else if (!compareAll(currentToken, templateToken)) {
77
81
  isEqual = false;
78
82
  break;
@@ -113,29 +113,27 @@ function getValues(tokens, waysFrom) {
113
113
 
114
114
  for (const [name, index] of entries(waysFrom)) {
115
115
  let end = index;
116
+ let ok = true;
116
117
 
117
- if (isTemplateArray(name)) {
118
- end = collectArray({
118
+ if (isTemplateArray(name))
119
+ [ok, end] = collectArray({
119
120
  currentTokenIndex: index,
120
121
  tokens,
121
122
  });
122
- } else if (isTemplateExpression(name)) {
123
+ else if (isTemplateExpression(name))
123
124
  end = collectExpression({
124
125
  currentTokenIndex: index,
125
126
  tokens,
126
127
  });
127
- } else if (isTemplateArgs(name)) {
128
- let ok = false;
129
-
128
+ else if (isTemplateArgs(name))
130
129
  [ok, end] = collectArgs({
131
130
  currentTokenIndex: index,
132
131
  tokens,
133
132
  });
134
-
135
- if (!ok) {
136
- values[name] = [];
137
- continue;
138
- }
133
+
134
+ if (!ok) {
135
+ values[name] = [];
136
+ continue;
139
137
  }
140
138
 
141
139
  values[name] = tokens.slice(index, end + 1);
@@ -149,3 +147,4 @@ function setValues({to, waysTo, values}) {
149
147
  to.splice(index, 1, ...values[name]);
150
148
  }
151
149
  }
150
+
@@ -68,4 +68,9 @@ export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExp
68
68
  export const isTemplateArgsToken = (a) => isIdentifier(a) && isTemplateArgs(a.value);
69
69
 
70
70
  export const OpenRoundBrace = Punctuator('(');
71
- export const CloseRoundBrace = Punctuator(')');
71
+ export const closeRoundBrace = Punctuator(')');
72
+ export const closeSquareBrace = Punctuator(']');
73
+ export const semicolon = Punctuator(';');
74
+
75
+ export const OK = true;
76
+ export const NOT_OK = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",