flatlint 1.61.0 → 1.62.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.19, v1.62.0
2
+
3
+ feature:
4
+ - ca2745a flatlint: __expr: improve
5
+
1
6
  2025.01.18, v1.61.0
2
7
 
3
8
  feature:
@@ -2,6 +2,7 @@ import {
2
2
  closeCurlyBrace,
3
3
  closeRoundBrace,
4
4
  comma,
5
+ isNewLine,
5
6
  openCurlyBrace,
6
7
  openRoundBrace,
7
8
  semicolon,
@@ -17,15 +18,6 @@ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken
17
18
  for (; index < n; index++) {
18
19
  const token = tokens[index];
19
20
 
20
- if (equal(token, semicolon))
21
- break;
22
-
23
- if (equal(token, comma))
24
- break;
25
-
26
- if (equal(token, nextTemplateToken))
27
- break;
28
-
29
21
  if (equal(token, openRoundBrace))
30
22
  ++roundBracesBalance;
31
23
 
@@ -43,7 +35,21 @@ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken
43
35
 
44
36
  if (curlyBracesBalance < 0)
45
37
  break;
38
+
39
+ if (!curlyBracesBalance) {
40
+ if (equal(token, semicolon))
41
+ break;
42
+
43
+ if (equal(token, comma))
44
+ break;
45
+
46
+ if (equal(token, nextTemplateToken))
47
+ break;
48
+ }
46
49
  }
47
50
 
51
+ if (isNewLine(tokens[index - 1]))
52
+ --index;
53
+
48
54
  return --index;
49
55
  };
@@ -64,13 +64,16 @@ export const compare = (source, template, {index = 0} = {}) => {
64
64
  nextTemplateToken: templateTokens[templateIndex + 1],
65
65
  });
66
66
 
67
- if (indexOfExpressionEnd >= n - 1) {
67
+ if (indexOfExpressionEnd >= n - 1)
68
68
  end = indexOfExpressionEnd;
69
- continue;
70
- }
71
69
 
72
- delta = indexOfExpressionEnd - currentTokenIndex;
73
- index = indexOfExpressionEnd - templateIndex;
70
+ if (templateIndex === templateTokensLength - 1) {
71
+ //delta = index;
72
+ currentTokenIndex = end;
73
+ } else {
74
+ delta = indexOfExpressionEnd - currentTokenIndex;
75
+ index = indexOfExpressionEnd - templateIndex;
76
+ }
74
77
  } else if (isTemplateArrayToken(templateToken)) {
75
78
  const [ok, indexOfArrayEnd] = collectArray({
76
79
  currentTokenIndex,
@@ -5,17 +5,14 @@ import {
5
5
  arrow,
6
6
  openCurlyBrace,
7
7
  closeRoundBrace,
8
- dot,
9
8
  question,
10
- openRoundBrace,
11
- or,
12
9
  closeCurlyBrace,
13
10
  } from '#types';
14
11
 
15
12
  export const report = () => 'Add missing semicolon';
16
13
 
17
14
  export const match = () => ({
18
- 'const __a = __expr': ({__expr}, path) => {
15
+ 'const __a = __expr': (vars, path) => {
19
16
  const punctuators = [
20
17
  comma,
21
18
  semicolon,
@@ -23,8 +20,8 @@ export const match = () => ({
23
20
  question,
24
21
  ];
25
22
 
26
- if (isPunctuator(openCurlyBrace, __expr))
27
- return false;
23
+ if (!path.isNext())
24
+ return true;
28
25
 
29
26
  if (path.isNextPunctuator(punctuators))
30
27
  return false;
@@ -33,8 +30,6 @@ export const match = () => ({
33
30
  if (isPunctuator(token, semicolon))
34
31
  return false;
35
32
  }
36
-
37
- return true;
38
33
  },
39
34
  '__a(__args)': (vars, path) => {
40
35
  if (path.isNextPunctuator() && !path.isNextPunctuator(closeCurlyBrace))
@@ -58,5 +53,6 @@ export const match = () => ({
58
53
  export const replace = () => ({
59
54
  'const __a = __expr': 'const __a = __expr;',
60
55
  '__a(__args)': '__a(__args);',
56
+
61
57
  '})': '});',
62
58
  });
@@ -42,6 +42,7 @@ export const replace = () => ({
42
42
  '__a(__args),': '__a(__args);',
43
43
  'return __expr,': 'return __expr;',
44
44
  '__a.__b = __expr,': '__a.__b = __expr;',
45
+ '__a.__b.__c = __expr,': '__a.__b.__c = __expr;',
45
46
  });
46
47
 
47
48
  const check = ({__x}, path) => {
package/lib/plugins.js CHANGED
@@ -16,12 +16,13 @@ import * as convertSemicolonToComma from './plugins/convert-semicolon-to-comma/i
16
16
  import * as wrapAssignmentInParens from './plugins/wrap-assignment-in-parens/index.js';
17
17
 
18
18
  export const plugins = [
19
+ ['add-missing-semicolon', addMissingSemicolon],
20
+ ['remove-useless-comma', removeUselessComma],
19
21
  ['add-missing-arrow', addMissingArrow],
20
22
  ['add-missing-assign', addMissingAssign],
21
23
  ['add-missing-curly-brace', addMissingCurlyBrace],
22
24
  ['add-missing-round-brace', addMissingRoundBrace],
23
25
  ['add-missing-squire-brace', addMissingSquireBrace],
24
- ['add-missing-semicolon', addMissingSemicolon],
25
26
  ['add-missing-comma', addMissingComma],
26
27
  ['add-missing-quote', addMissingQuote],
27
28
  ['add-const-to-export', addConstToExport],
@@ -29,7 +30,6 @@ export const plugins = [
29
30
  ['convert-semicolon-to-comma', convertSemicolonToComma],
30
31
  ['convert-from-to-require', convertFromToRequire],
31
32
  ['remove-useless-round-brace', removeUselessRoundBrace],
32
- ['remove-useless-comma', removeUselessComma],
33
33
  ['remove-invalid-character', removeInvalidCharacter],
34
34
  ['wrap-assignment-in-parens', wrapAssignmentInParens],
35
35
  ];
@@ -103,9 +103,6 @@ const createIsNextKeyword = ({tokens, end}) => () => {
103
103
  end,
104
104
  });
105
105
 
106
- if (!current)
107
- return false;
108
-
109
106
  return isKeyword(current);
110
107
  };
111
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.61.0",
3
+ "version": "1.62.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",