flatlint 1.93.1 → 1.95.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,17 @@
1
+ 2025.02.01, v1.95.0
2
+
3
+ fix:
4
+ - 8697533 flatlint: add-missing-round-brace: when next keyword
5
+
6
+ feature:
7
+ - 978c283 flatlint: add-missing-round-brace: before semicolon
8
+
9
+ 2025.02.01, v1.94.0
10
+
11
+ feature:
12
+ - 22555f6 flatlint: remove-useless-comma: exclude property-array
13
+ - 04c24a4 faltlint: add-missing-semicolon: exclude template tail
14
+
1
15
  2025.02.01, v1.93.1
2
16
 
3
17
  feature:
package/README.md CHANGED
@@ -83,6 +83,9 @@ const m = {
83
83
 
84
84
  -{hello} = world;
85
85
  +({hello} = world);
86
+
87
+ -assign(oldPath, currentPath;
88
+ +assign(oldPath, currentPath);
86
89
  ```
87
90
 
88
91
  </details>
@@ -1,9 +1,20 @@
1
- import {closeRoundBrace} from '#types';
1
+ import {
2
+ closeRoundBrace,
3
+ isKeyword,
4
+ isPunctuator,
5
+ openRoundBrace,
6
+ semicolon,
7
+ } from '#types';
2
8
 
3
9
  export const report = () => 'Add missing round brace';
4
10
 
5
11
  export const match = () => ({
6
- '__a(__args': (vars, path) => {
12
+ '__a(__args': ({__args}, path) => {
13
+ const last = __args.at(-1);
14
+
15
+ if (isPunctuator(last, semicolon))
16
+ return false;
17
+
7
18
  if (path.isCurrentPunctuator(closeRoundBrace))
8
19
  return false;
9
20
 
@@ -15,6 +26,26 @@ export const match = () => ({
15
26
  '{__a} = __expr;': (vars, path) => {
16
27
  return !path.isPrevDeclarationKeyword();
17
28
  },
29
+ '{__a} = __expr': (vars, path) => {
30
+ return path.isNextKeyword();
31
+ },
32
+ '__a;': (vars, path) => {
33
+ let result = false;
34
+
35
+ for (const current of path.getAllPrev()) {
36
+ if (isPunctuator(current, openRoundBrace)) {
37
+ result = true;
38
+ break;
39
+ }
40
+
41
+ if (isKeyword(current)) {
42
+ result = false;
43
+ break;
44
+ }
45
+ }
46
+
47
+ return result;
48
+ },
18
49
  });
19
50
 
20
51
  export const replace = () => ({
@@ -24,4 +55,7 @@ export const replace = () => ({
24
55
  'if (__a(__args) {': 'if (__a(__args)) {',
25
56
  'if (__a(__args)': 'if (__a(__args))',
26
57
  '{__a} = __expr;': '({__a} = __expr);',
58
+ '{__a} = __expr': '({__a} = __expr)',
59
+ '__a;': '__a);',
27
60
  });
61
+
@@ -53,6 +53,9 @@ export const match = () => ({
53
53
  closeRoundBrace,
54
54
  ];
55
55
 
56
+ if (path.isNextTemplateTail())
57
+ return false;
58
+
56
59
  if (path.isNextPunctuator(punctuators))
57
60
  return false;
58
61
 
@@ -57,6 +57,11 @@ export const match = () => ({
57
57
  return true;
58
58
  },
59
59
  '],': (vars, path) => {
60
+ for (const token of path.getAllPrev()) {
61
+ if (isPunctuator(token, colon))
62
+ return false;
63
+ }
64
+
60
65
  let result = false;
61
66
 
62
67
  for (const token of path.getAllNext()) {
@@ -82,4 +87,3 @@ export const replace = () => ({
82
87
  '}),': '})',
83
88
  '],': '];',
84
89
  });
85
-
@@ -42,6 +42,10 @@ export const createPath = ({tokens, start, end}) => ({
42
42
  tokens,
43
43
  end,
44
44
  }),
45
+ isNextTemplateTail: createIsNextTemplateTail({
46
+ tokens,
47
+ end,
48
+ }),
45
49
  isPrevPunctuator: createIsPrevPunctuator({
46
50
  tokens,
47
51
  start,
@@ -110,12 +114,18 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
110
114
  end,
111
115
  });
112
116
 
113
- if (!current)
114
- return false;
115
-
116
117
  return isPunctuator(current, punctuators);
117
118
  };
118
119
 
120
+ const createIsNextTemplateTail = ({tokens, end}) => () => {
121
+ const current = getNext({
122
+ tokens,
123
+ end,
124
+ });
125
+
126
+ return isTemplateTail(current);
127
+ };
128
+
119
129
  const createGetPrev = ({tokens, start}) => () => {
120
130
  return getPrev({
121
131
  tokens,
@@ -70,6 +70,9 @@ export const isOneOfKeywords = (token, keywords) => {
70
70
  };
71
71
 
72
72
  export const isPunctuator = (token, punctuator) => {
73
+ if (!token)
74
+ return false;
75
+
73
76
  if (token.type !== 'Punctuator')
74
77
  return false;
75
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.93.1",
3
+ "version": "1.95.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",