flatlint 2.11.0 → 2.13.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,13 @@
1
+ 2025.03.18, v2.13.0
2
+
3
+ feature:
4
+ - c407722 flatlint: add-missing-comma: exclude tagged template litera
5
+
6
+ 2025.03.18, v2.12.0
7
+
8
+ feature:
9
+ - ee6cdc9 flatlint: convert-semicolon-to-comma: exclude call
10
+
1
11
  2025.03.15, v2.11.0
2
12
 
3
13
  feature:
@@ -8,19 +8,10 @@ import {
8
8
  export const report = () => 'Add missing comma';
9
9
 
10
10
  export const match = () => ({
11
- '"__a"': (vars, path) => {
12
- if (path.isNextPunctuator(quote))
13
- return true;
14
-
15
- if (path.isNextKeyword())
16
- return false;
17
-
18
- if (path.isPrevPunctuator(assign))
11
+ '__a': ({__a}, path) => {
12
+ if (path.isNextTemplateHead())
19
13
  return false;
20
14
 
21
- return path.isNextIdentifier();
22
- },
23
- '__a': ({__a}, path) => {
24
15
  const isType = isKeyword(__a, 'type');
25
16
 
26
17
  if (isType && path.isNextCompare('__a ='))
@@ -46,6 +37,18 @@ export const match = () => ({
46
37
 
47
38
  return !path.isNextPunctuator();
48
39
  },
40
+ '"__a"': (vars, path) => {
41
+ if (path.isNextPunctuator(quote))
42
+ return true;
43
+
44
+ if (path.isNextKeyword())
45
+ return false;
46
+
47
+ if (path.isPrevPunctuator(assign))
48
+ return false;
49
+
50
+ return path.isNextIdentifier();
51
+ },
49
52
  });
50
53
 
51
54
  export const replace = () => ({
@@ -1,9 +1,13 @@
1
1
  import {
2
2
  closeSquareBrace,
3
3
  colon,
4
+ dot,
4
5
  isKeyword,
5
6
  isOneOfKeywords,
6
7
  isPunctuator,
8
+ semicolon,
9
+ assign,
10
+ bitwiseAnd,
7
11
  } from '#types';
8
12
 
9
13
  const keywords = [
@@ -27,6 +31,9 @@ export const match = () => ({
27
31
  return false;
28
32
 
29
33
  for (const token of path.getAllPrev()) {
34
+ if (isPunctuator(token, semicolon))
35
+ return false;
36
+
30
37
  if (isOneOfKeywords(token, keywords))
31
38
  return false;
32
39
  }
@@ -55,13 +62,21 @@ export const match = () => ({
55
62
  if (path.isNextKeyword())
56
63
  return false;
57
64
 
65
+ const isNextCall = path.isNextCompare('__a.__b(');
66
+
58
67
  for (const token of path.getAllPrev()) {
59
68
  if (isOneOfKeywords(token, keywords))
60
69
  return false;
61
- }
62
-
63
- for (const token of path.getAllPrev()) {
64
- if (isPunctuator(token, colon))
70
+
71
+ if (isPunctuator(token, [
72
+ assign,
73
+ bitwiseAnd,
74
+ dot,
75
+ semicolon,
76
+ ]))
77
+ return false;
78
+
79
+ if (isPunctuator(token, colon) && !isNextCall)
65
80
  return true;
66
81
  }
67
82
 
@@ -11,6 +11,7 @@ import {
11
11
  isDeclarationKeyword,
12
12
  isNewLine,
13
13
  isWhiteSpace,
14
+ isTemplateHead,
14
15
  } from '#types';
15
16
  import {equalTemplate} from '../compare/equal.js';
16
17
 
@@ -58,6 +59,10 @@ export const createPath = ({tokens, start, end}) => ({
58
59
  tokens,
59
60
  end,
60
61
  }),
62
+ isNextTemplateHead: createIsNextTemplateHead({
63
+ tokens,
64
+ end,
65
+ }),
61
66
  isNextTemplateTail: createIsNextTemplateTail({
62
67
  tokens,
63
68
  end,
@@ -152,12 +157,21 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
152
157
  };
153
158
 
154
159
  const createIsNextTemplateTail = ({tokens, end}) => () => {
155
- const current = getNext({
160
+ const next = getNext({
161
+ tokens,
162
+ end,
163
+ });
164
+
165
+ return isTemplateTail(next);
166
+ };
167
+
168
+ const createIsNextTemplateHead = ({tokens, end}) => () => {
169
+ const next = getNext({
156
170
  tokens,
157
171
  end,
158
172
  });
159
173
 
160
- return isTemplateTail(current);
174
+ return isTemplateHead(next);
161
175
  };
162
176
 
163
177
  const createGetPrev = ({tokens, start}) => () => {
@@ -20,6 +20,7 @@ const isString = (a) => typeof a === 'string';
20
20
 
21
21
  export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';
22
22
  export const isNoSubstitutionTemplate = (a) => a?.type === 'NoSubstitutionTemplate';
23
+ export const isTemplateHead = (a) => a?.type === 'TemplateHead';
23
24
  export const isTemplateTail = (a) => a?.type === 'TemplateTail';
24
25
  export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
25
26
  export const isIdentifier = (token, newToken) => {
@@ -146,6 +147,7 @@ export const isTemplateArrayToken = (a) => isIdentifier(a) && isTemplateArray(a.
146
147
  export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExpression(a.value);
147
148
  export const isTemplateArgsToken = (a) => isIdentifier(a) && isTemplateArgs(a.value);
148
149
 
150
+ export const bitwiseAnd = Punctuator('&');
149
151
  export const arrow = Punctuator('=>');
150
152
  export const closeRoundBrace = Punctuator(')');
151
153
  export const closeSquareBrace = Punctuator(']');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "2.11.0",
3
+ "version": "2.13.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",