flatlint 1.29.0 → 1.30.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.09, v1.30.0
2
+
3
+ feature:
4
+ - 2379871 flatlint: remoe-useless-comma: improve
5
+
1
6
  2025.01.09, v1.29.0
2
7
 
3
8
  feature:
@@ -1,7 +1,9 @@
1
+ import {quote} from '#types';
2
+
1
3
  export const report = () => 'Add missing quote';
2
4
 
3
5
  export const match = () => ({
4
- '__a("__b': (vars, path) => !path.isNextPunctuator(vars.quote),
6
+ '__a("__b': (vars, path) => !path.isNextPunctuator(quote),
5
7
  });
6
8
 
7
9
  export const replace = () => ({
@@ -1,4 +1,6 @@
1
1
  import {
2
+ closeCurlyBrace,
3
+ closeRoundBrace,
2
4
  isIdentifier,
3
5
  isPunctuator,
4
6
  openCurlyBrace,
@@ -22,10 +24,13 @@ export const match = () => ({
22
24
  return false;
23
25
  }
24
26
 
25
- if (path.isNextIdentifier('const'))
27
+ if (path.isNextPunctuator(closeRoundBrace))
26
28
  return true;
27
29
 
28
- return !path.isNextPunctuator(openCurlyBrace);
30
+ if (path.isNextPunctuator(closeCurlyBrace))
31
+ return false;
32
+
33
+ return path.isNextIdentifier('const');
29
34
  },
30
35
  });
31
36
 
@@ -33,4 +38,5 @@ export const replace = () => ({
33
38
  '__a(__args) {},': '__a(__args) {}',
34
39
  '__a(),': '__a()',
35
40
  '},': '}',
41
+ '}),': '})',
36
42
  });
@@ -35,8 +35,30 @@ export const createPath = ({tokens, start, end}) => ({
35
35
  }),
36
36
  });
37
37
 
38
+ const next = ({tokens, end}) => {
39
+ let i = end - 1;
40
+
41
+ while (++i) {
42
+ const token = tokens[i];
43
+
44
+ if (!token)
45
+ return token;
46
+
47
+ if (isNewLine(token))
48
+ continue;
49
+
50
+ if (isWhiteSpace(token))
51
+ continue;
52
+
53
+ return token;
54
+ }
55
+ };
56
+
38
57
  const createIsNextIdentifier = ({tokens, end}) => (value) => {
39
- const current = tokens[end];
58
+ const current = next({
59
+ tokens,
60
+ end,
61
+ });
40
62
 
41
63
  if (!current)
42
64
  return false;
@@ -45,14 +67,14 @@ const createIsNextIdentifier = ({tokens, end}) => (value) => {
45
67
  };
46
68
 
47
69
  const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
48
- let current = tokens[end];
70
+ const current = next({
71
+ tokens,
72
+ end,
73
+ });
49
74
 
50
75
  if (!current)
51
76
  return false;
52
77
 
53
- if (isWhiteSpace(current))
54
- current = tokens[end + 1];
55
-
56
78
  return isPunctuator(current, punctuator);
57
79
  };
58
80
 
@@ -2,6 +2,9 @@ const isString = (a) => typeof a === 'string';
2
2
 
3
3
  export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
4
4
  export const isIdentifier = (token, value = token.value) => {
5
+ if (!token)
6
+ return false;
7
+
5
8
  const {type} = token;
6
9
  const is = type === 'IdentifierName';
7
10
 
@@ -16,6 +19,9 @@ export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
16
19
  export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
17
20
  export const notWhiteSpace = (a) => !isWhiteSpace(a);
18
21
  export const isPunctuator = (token, punctuator) => {
22
+ if (!token)
23
+ return false;
24
+
19
25
  if (token.type !== 'Punctuator')
20
26
  return false;
21
27
 
@@ -87,6 +93,7 @@ export const openCurlyBrace = Punctuator('{');
87
93
  export const closeCurlyBrace = Punctuator('}');
88
94
  export const openSquireBrace = Punctuator('[');
89
95
  export const closeSquireBrace = Punctuator(']');
96
+ export const quote = Punctuator(`'`);
90
97
 
91
98
  export const OK = true;
92
99
  export const NOT_OK = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.29.0",
3
+ "version": "1.30.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",