flatlint 1.30.1 → 1.32.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.10, v1.32.0
2
+
3
+ feature:
4
+ - af50927 flatlint: balance: __expr
5
+
6
+ 2025.01.09, v1.31.0
7
+
8
+ feature:
9
+ - cf7297d flatlint: __expr: improve
10
+
1
11
  2025.01.09, v1.30.1
2
12
 
3
13
  feature:
@@ -1,4 +1,5 @@
1
1
  import {
2
+ closeCurlyBrace,
2
3
  closeRoundBrace,
3
4
  comma,
4
5
  openRoundBrace,
@@ -9,6 +10,7 @@ import {equal} from './equal.js';
9
10
  export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken = semicolon}) => {
10
11
  const n = tokens.length;
11
12
  let index = currentTokenIndex;
13
+ let roundBracesBalance = 0;
12
14
 
13
15
  for (; index < n; index++) {
14
16
  const token = tokens[index];
@@ -22,10 +24,16 @@ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken
22
24
  if (equal(token, nextTemplateToken))
23
25
  break;
24
26
 
25
- if (equal(token, openRoundBrace))
27
+ if (equal(token, closeCurlyBrace))
26
28
  break;
27
29
 
30
+ if (equal(token, openRoundBrace))
31
+ ++roundBracesBalance;
32
+
28
33
  if (equal(token, closeRoundBrace))
34
+ --roundBracesBalance;
35
+
36
+ if (roundBracesBalance < 0)
29
37
  break;
30
38
  }
31
39
 
@@ -2,34 +2,58 @@ 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
+ for (const token of path.getAllNext()) {
23
+ if (isPunctuator(token, semicolon))
24
+ return false;
25
+ }
26
+
27
+ return true;
28
+ },
29
+ '__a(__args)': (vars, path) => {
30
+ if (path.isNextPunctuator(comma))
31
+ return false;
32
+
33
+ if (path.isNextPunctuator(semicolon))
34
+ return false;
35
+
36
+ if (path.isNextPunctuator(arrow))
37
+ return false;
38
+
39
+ if (path.isNextPunctuator(openCurlyBrace))
40
+ return false;
41
+
42
+ return !path.isPrevIdentifier('function');
43
+ },
44
+ '})': (vars, path) => {
45
+ if (path.isNextPunctuator(arrow))
46
+ return false;
47
+
48
+ if (path.isNextPunctuator(comma))
49
+ return false;
50
+
51
+ return !path.isNextPunctuator(semicolon);
52
+ },
12
53
  });
13
54
 
14
55
  export const replace = () => ({
15
56
  'const __a = __expr': 'const __a = __expr;',
16
57
  '__a(__args)': '__a(__args);',
58
+ '})': '});',
17
59
  });
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
- }
@@ -1,9 +1,7 @@
1
1
  import {
2
2
  closeCurlyBrace,
3
- closeRoundBrace,
4
3
  isIdentifier,
5
4
  isPunctuator,
6
- openCurlyBrace,
7
5
  openSquireBrace,
8
6
  } from '#types';
9
7
 
@@ -27,9 +25,6 @@ export const match = () => ({
27
25
  if (!path.isNext())
28
26
  return true;
29
27
 
30
- if (path.isNextPunctuator(closeRoundBrace))
31
- return true;
32
-
33
28
  if (path.isNextPunctuator(closeCurlyBrace))
34
29
  return false;
35
30
 
@@ -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,
@@ -71,9 +71,6 @@ const createIsNextIdentifier = ({tokens, end}) => (value) => {
71
71
  end,
72
72
  });
73
73
 
74
- if (!current)
75
- return false;
76
-
77
74
  return isIdentifier(current, value);
78
75
  };
79
76
 
@@ -2,9 +2,6 @@ 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
-
8
5
  const {type} = token;
9
6
  const is = type === 'IdentifierName';
10
7
 
@@ -19,9 +16,6 @@ export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
19
16
  export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
20
17
  export const notWhiteSpace = (a) => !isWhiteSpace(a);
21
18
  export const isPunctuator = (token, punctuator) => {
22
- if (!token)
23
- return false;
24
-
25
19
  if (token.type !== 'Punctuator')
26
20
  return false;
27
21
 
@@ -83,9 +77,10 @@ export const isTemplateArrayToken = (a) => isIdentifier(a) && isTemplateArray(a.
83
77
  export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExpression(a.value);
84
78
  export const isTemplateArgsToken = (a) => isIdentifier(a) && isTemplateArgs(a.value);
85
79
 
86
- export const openRoundBrace = Punctuator('(');
80
+ export const arrow = Punctuator('=>');
87
81
  export const closeRoundBrace = Punctuator(')');
88
82
  export const closeSquareBrace = Punctuator(']');
83
+ export const openRoundBrace = Punctuator('(');
89
84
  export const semicolon = Punctuator(';');
90
85
  export const comma = Punctuator(',');
91
86
  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.32.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",