flatlint 1.28.0 → 1.29.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,9 @@
1
+ 2025.01.09, v1.29.0
2
+
3
+ feature:
4
+ - 8d308ac flatlint: remove-useless-comma: curly
5
+ - f070e0c flatlint: convert-coma-to-semicolon: return
6
+
1
7
  2025.01.08, v1.28.0
2
8
 
3
9
  feature:
package/README.md CHANGED
@@ -24,6 +24,11 @@ npm i flatlint
24
24
  ```diff
25
25
  -const a = 5,
26
26
  +const a = 5;
27
+
28
+ function x() {
29
+ - return m,
30
+ + return m;
31
+ }
27
32
  ```
28
33
 
29
34
  </details>
@@ -106,6 +111,17 @@ const a = {
106
111
 
107
112
  </details>
108
113
 
114
+ <details><summary>remove useless comma</summary>
115
+
116
+ ```diff
117
+ function x() {
118
+ return m;
119
+ -},
120
+ +}
121
+ ```
122
+
123
+ </details>
124
+
109
125
  <details><summary>add missing quote</summary>
110
126
 
111
127
  ```diff
@@ -15,4 +15,5 @@ export const match = () => ({
15
15
  export const replace = () => ({
16
16
  'const __a = __b,': 'const __a = __b;',
17
17
  '__a(__args),': '__a(__args);',
18
+ 'return __expr,': 'return __expr;',
18
19
  });
@@ -1,4 +1,9 @@
1
- import {isIdentifier} from '#types';
1
+ import {
2
+ isIdentifier,
3
+ isPunctuator,
4
+ openCurlyBrace,
5
+ openSquireBrace,
6
+ } from '#types';
2
7
 
3
8
  export const report = () => 'Remove useless coma';
4
9
 
@@ -11,9 +16,21 @@ export const match = () => ({
11
16
 
12
17
  return false;
13
18
  },
19
+ '},': (vars, path) => {
20
+ for (const token of path.getAllPrev()) {
21
+ if (isPunctuator(token, openSquireBrace))
22
+ return false;
23
+ }
24
+
25
+ if (path.isNextIdentifier('const'))
26
+ return true;
27
+
28
+ return !path.isNextPunctuator(openCurlyBrace);
29
+ },
14
30
  });
15
31
 
16
32
  export const replace = () => ({
17
33
  '__a(__args) {},': '__a(__args) {}',
18
34
  '__a(),': '__a()',
35
+ '},': '}',
19
36
  });
@@ -2,12 +2,17 @@ import {
2
2
  isIdentifier,
3
3
  isNewLine,
4
4
  isPunctuator,
5
+ isWhiteSpace,
5
6
  } from '#types';
6
7
 
7
8
  export const createPath = ({tokens, start, end}) => ({
8
9
  tokens,
9
10
  start,
10
11
  end,
12
+ isNextIdentifier: createIsNextIdentifier({
13
+ tokens,
14
+ end,
15
+ }),
11
16
  getAllPrev: createGetAllPrev({
12
17
  tokens,
13
18
  start,
@@ -30,12 +35,24 @@ export const createPath = ({tokens, start, end}) => ({
30
35
  }),
31
36
  });
32
37
 
33
- const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
38
+ const createIsNextIdentifier = ({tokens, end}) => (value) => {
34
39
  const current = tokens[end];
35
40
 
36
41
  if (!current)
37
42
  return false;
38
43
 
44
+ return isIdentifier(current, value);
45
+ };
46
+
47
+ const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
48
+ let current = tokens[end];
49
+
50
+ if (!current)
51
+ return false;
52
+
53
+ if (isWhiteSpace(current))
54
+ current = tokens[end + 1];
55
+
39
56
  return isPunctuator(current, punctuator);
40
57
  };
41
58
 
@@ -83,6 +83,10 @@ export const closeSquareBrace = Punctuator(']');
83
83
  export const semicolon = Punctuator(';');
84
84
  export const comma = Punctuator(',');
85
85
  export const colon = Punctuator(':');
86
+ export const openCurlyBrace = Punctuator('{');
87
+ export const closeCurlyBrace = Punctuator('}');
88
+ export const openSquireBrace = Punctuator('[');
89
+ export const closeSquireBrace = Punctuator(']');
86
90
 
87
91
  export const OK = true;
88
92
  export const NOT_OK = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.28.0",
3
+ "version": "1.29.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",