flatlint 1.30.0 → 1.31.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.01.09, v1.31.0
2
+
3
+ feature:
4
+ - cf7297d flatlint: __expr: improve
5
+
6
+ 2025.01.09, v1.30.1
7
+
8
+ feature:
9
+ - 45b14e5 flatlint: remove-useless-comma: last
10
+
1
11
  2025.01.09, v1.30.0
2
12
 
3
13
  feature:
@@ -1,7 +1,7 @@
1
1
  import {
2
+ closeCurlyBrace,
2
3
  closeRoundBrace,
3
4
  comma,
4
- openRoundBrace,
5
5
  semicolon,
6
6
  } from '#types';
7
7
  import {equal} from './equal.js';
@@ -22,7 +22,7 @@ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken
22
22
  if (equal(token, nextTemplateToken))
23
23
  break;
24
24
 
25
- if (equal(token, openRoundBrace))
25
+ if (equal(token, closeCurlyBrace))
26
26
  break;
27
27
 
28
28
  if (equal(token, closeRoundBrace))
@@ -2,34 +2,72 @@ import {
2
2
  comma,
3
3
  isPunctuator,
4
4
  semicolon,
5
+ arrow,
6
+ openCurlyBrace,
5
7
  } from '#types';
6
8
 
7
9
  export const report = () => 'Add missing semicolon';
8
10
 
9
11
  export const match = () => ({
10
- 'const __a = __expr': check,
11
- '__a(__args)': check,
12
+ 'const __a = __expr': (vars, path) => {
13
+ if (path.isNextPunctuator(comma))
14
+ return false;
15
+
16
+ if (path.isNextPunctuator(semicolon))
17
+ return false;
18
+
19
+ if (path.isNextPunctuator(openCurlyBrace))
20
+ return false;
21
+
22
+ if (path.isPrevIdentifier('function'))
23
+ return false;
24
+
25
+ for (const token of path.getAllNext()) {
26
+ if (isPunctuator(token, semicolon))
27
+ return false;
28
+ }
29
+
30
+ return true;
31
+ },
32
+ '__a(__args)': (vars, path) => {
33
+ if (path.isNextPunctuator(comma))
34
+ return false;
35
+
36
+ if (path.isNextPunctuator(semicolon))
37
+ return false;
38
+
39
+ if (path.isNextPunctuator(arrow))
40
+ return false;
41
+
42
+ if (path.isNextPunctuator(openCurlyBrace))
43
+ return false;
44
+
45
+ if (path.isPrevIdentifier('function'))
46
+ return false;
47
+
48
+ for (const token of path.getAllNext()) {
49
+ if (isPunctuator(token, semicolon))
50
+ return false;
51
+ }
52
+
53
+ return true;
54
+ },
55
+ '})': (vars, path) => {
56
+ if (path.isNextPunctuator(arrow))
57
+ return false;
58
+
59
+ if (path.isNextPunctuator(comma))
60
+ return false;
61
+
62
+ if (path.isCurrentPunctuator(comma))
63
+ return false;
64
+
65
+ return !path.isNextPunctuator(semicolon);
66
+ },
12
67
  });
13
68
 
14
69
  export const replace = () => ({
15
70
  'const __a = __expr': 'const __a = __expr;',
16
71
  '__a(__args)': '__a(__args);',
72
+ '})': '});',
17
73
  });
18
-
19
- function check(vars, path) {
20
- if (path.isNextPunctuator(comma))
21
- return false;
22
-
23
- if (path.isNextPunctuator(semicolon))
24
- return false;
25
-
26
- if (path.isPrevIdentifier('function'))
27
- return false;
28
-
29
- for (const token of path.getAllNext()) {
30
- if (isPunctuator(token, semicolon))
31
- return false;
32
- }
33
-
34
- return true;
35
- }
@@ -3,7 +3,6 @@ import {
3
3
  closeRoundBrace,
4
4
  isIdentifier,
5
5
  isPunctuator,
6
- openCurlyBrace,
7
6
  openSquireBrace,
8
7
  } from '#types';
9
8
 
@@ -24,6 +23,9 @@ export const match = () => ({
24
23
  return false;
25
24
  }
26
25
 
26
+ if (!path.isNext())
27
+ return true;
28
+
27
29
  if (path.isNextPunctuator(closeRoundBrace))
28
30
  return true;
29
31
 
@@ -1,5 +1,14 @@
1
+ import {isPunctuator, openRoundBrace} from '#types';
2
+
1
3
  export const report = () => 'Remove useless round brace';
2
4
 
5
+ export const match = () => ({
6
+ 'const __a = __expr);': ({__expr}) => {
7
+ const [, brace] = __expr;
8
+ return !isPunctuator(brace, openRoundBrace);
9
+ },
10
+ });
11
+
3
12
  export const replace = () => ({
4
13
  'const __a = __expr);': 'const __a = __expr;',
5
14
  'from "__b")': 'from "__b"',
@@ -25,6 +25,10 @@ export const createPath = ({tokens, start, end}) => ({
25
25
  tokens,
26
26
  end,
27
27
  }),
28
+ isNext: createIsNext({
29
+ tokens,
30
+ end,
31
+ }),
28
32
  isPrevIdentifier: createIsPrevIdentifier({
29
33
  tokens,
30
34
  start,
@@ -54,6 +58,13 @@ const next = ({tokens, end}) => {
54
58
  }
55
59
  };
56
60
 
61
+ const createIsNext = ({tokens, end}) => () => {
62
+ return next({
63
+ tokens,
64
+ end,
65
+ });
66
+ };
67
+
57
68
  const createIsNextIdentifier = ({tokens, end}) => (value) => {
58
69
  const current = next({
59
70
  tokens,
@@ -83,9 +83,10 @@ export const isTemplateArrayToken = (a) => isIdentifier(a) && isTemplateArray(a.
83
83
  export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExpression(a.value);
84
84
  export const isTemplateArgsToken = (a) => isIdentifier(a) && isTemplateArgs(a.value);
85
85
 
86
- export const openRoundBrace = Punctuator('(');
86
+ export const arrow = Punctuator('=>');
87
87
  export const closeRoundBrace = Punctuator(')');
88
88
  export const closeSquareBrace = Punctuator(']');
89
+ export const openRoundBrace = Punctuator('(');
89
90
  export const semicolon = Punctuator(';');
90
91
  export const comma = Punctuator(',');
91
92
  export const colon = Punctuator(':');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",