flatlint 1.92.0 → 1.93.1

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,13 @@
1
+ 2025.02.01, v1.93.1
2
+
3
+ feature:
4
+ - 7ed1762 flatlint: remove-useless-comma: declaration
5
+
6
+ 2025.02.01, v1.93.0
7
+
8
+ feature:
9
+ - 1141c03 flatlint: add-missing-round-brace: exclude declaration
10
+
1
11
  2025.02.01, v1.92.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -177,6 +177,10 @@ function x() {
177
177
  return m;
178
178
  -},
179
179
  +}
180
+
181
+ -const expected = [],
182
+ +const expected = [];
183
+ t.equal(expected, []);
180
184
  ```
181
185
 
182
186
  </details>
@@ -12,6 +12,9 @@ export const match = () => ({
12
12
  'if (__a(__args)': (vars, path) => {
13
13
  return path.isNextKeyword();
14
14
  },
15
+ '{__a} = __expr;': (vars, path) => {
16
+ return !path.isPrevDeclarationKeyword();
17
+ },
15
18
  });
16
19
 
17
20
  export const replace = () => ({
@@ -1,9 +1,11 @@
1
1
  import {
2
2
  closeCurlyBrace,
3
+ closeSquareBrace,
3
4
  colon,
4
5
  isIdentifier,
5
6
  isPunctuator,
6
7
  openSquireBrace,
8
+ semicolon,
7
9
  spread,
8
10
  } from '#types';
9
11
 
@@ -54,6 +56,23 @@ export const match = () => ({
54
56
 
55
57
  return true;
56
58
  },
59
+ '],': (vars, path) => {
60
+ let result = false;
61
+
62
+ for (const token of path.getAllNext()) {
63
+ if (isPunctuator(token, closeSquareBrace)) {
64
+ result = false;
65
+ break;
66
+ }
67
+
68
+ if (isPunctuator(token, semicolon)) {
69
+ result = true;
70
+ break;
71
+ }
72
+ }
73
+
74
+ return result;
75
+ },
57
76
  });
58
77
 
59
78
  export const replace = () => ({
@@ -61,4 +80,6 @@ export const replace = () => ({
61
80
  '__a(__args),': '__a(__args)',
62
81
  '},': '}',
63
82
  '}),': '})',
83
+ '],': '];',
64
84
  });
85
+
@@ -7,6 +7,7 @@ import {
7
7
  isNoSubstitutionTemplate,
8
8
  getNext,
9
9
  getPrev,
10
+ isDeclarationKeyword,
10
11
  } from '#types';
11
12
 
12
13
  export const createPath = ({tokens, start, end}) => ({
@@ -21,10 +22,18 @@ export const createPath = ({tokens, start, end}) => ({
21
22
  tokens,
22
23
  start,
23
24
  }),
25
+ getAllNext: createGetAllNext({
26
+ tokens,
27
+ end,
28
+ }),
24
29
  getPrev: createGetPrev({
25
30
  tokens,
26
31
  start,
27
32
  }),
33
+ isPrevDeclarationKeyword: createIsPrevDeclarationKeyword({
34
+ tokens,
35
+ start,
36
+ }),
28
37
  isNextKeyword: createIsNextKeyword({
29
38
  tokens,
30
39
  end,
@@ -114,6 +123,15 @@ const createGetPrev = ({tokens, start}) => () => {
114
123
  });
115
124
  };
116
125
 
126
+ const createIsPrevDeclarationKeyword = ({tokens, start}) => () => {
127
+ const prev = getPrev({
128
+ tokens,
129
+ start,
130
+ });
131
+
132
+ return isDeclarationKeyword(prev);
133
+ };
134
+
117
135
  const createIsPrevPunctuator = ({tokens, start}) => (punctuators) => {
118
136
  const current = getPrev({
119
137
  tokens,
@@ -142,3 +160,10 @@ const createGetAllPrev = ({tokens, start}) => function*() {
142
160
  yield tokens[i];
143
161
  }
144
162
  };
163
+
164
+ const createGetAllNext = ({tokens, end}) => function*() {
165
+ for (let i = end; i < tokens.length; ++i)
166
+ yield tokens[i];
167
+ /* c8 ignore start */
168
+ /* c8 ignore end */
169
+ };
@@ -40,6 +40,9 @@ export const isKeyword = (token, name) => {
40
40
  };
41
41
 
42
42
  export const isDeclarationKeyword = (token, name) => {
43
+ if (!token)
44
+ return false;
45
+
43
46
  const {value} = token;
44
47
 
45
48
  if (!keyword.isDeclarationKeyword(value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.92.0",
3
+ "version": "1.93.1",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",