flatlint 1.30.1 → 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,8 @@
1
+ 2025.01.09, v1.31.0
2
+
3
+ feature:
4
+ - cf7297d flatlint: __expr: improve
5
+
1
6
  2025.01.09, v1.30.1
2
7
 
3
8
  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
 
@@ -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"',
@@ -58,7 +58,7 @@ const next = ({tokens, end}) => {
58
58
  }
59
59
  };
60
60
 
61
- const createIsNext = ({tokens, end}) => (value) => {
61
+ const createIsNext = ({tokens, end}) => () => {
62
62
  return next({
63
63
  tokens,
64
64
  end,
@@ -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.1",
3
+ "version": "1.31.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",