flatlint 1.65.0 → 1.67.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.21, v1.67.0
2
+
3
+ feature:
4
+ - 3a5ea58 flatlint: add-missing-comma: template
5
+
6
+ 2025.01.20, v1.66.0
7
+
8
+ feature:
9
+ - ff4cc99 flatlint: simplify
10
+
1
11
  2025.01.20, v1.65.0
2
12
 
3
13
  fix:
@@ -11,10 +11,7 @@ import {
11
11
  } from '#types';
12
12
  import {equal} from './equal.js';
13
13
 
14
- const NOT_OK_PUNCTUATORS = [
15
- semicolon,
16
- closeRoundBrace,
17
- ];
14
+ const NOT_OK_PUNCTUATORS = [semicolon, closeRoundBrace];
18
15
 
19
16
  export const collectArgs = ({currentTokenIndex, tokens}) => {
20
17
  let index = currentTokenIndex;
@@ -64,11 +64,10 @@ 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
-
70
- if (templateIndex === templateTokensLength - 1) {
71
- //delta = index;
69
+ currentTokenIndex = end;
70
+ } else if (templateIndex === templateTokensLength - 1) {
72
71
  currentTokenIndex = end;
73
72
  } else {
74
73
  delta = indexOfExpressionEnd - currentTokenIndex;
package/lib/flatlint.js CHANGED
@@ -10,6 +10,7 @@ export function lint(source, overrides = {}) {
10
10
  });
11
11
 
12
12
  const tokens = parse(source);
13
+
13
14
  const places = run(tokens, {
14
15
  plugins,
15
16
  fix,
@@ -7,12 +7,19 @@ import {
7
7
  closeRoundBrace,
8
8
  question,
9
9
  closeCurlyBrace,
10
+ isOnlyWhitespaces,
10
11
  } from '#types';
11
12
 
12
13
  export const report = () => 'Add missing semicolon';
13
14
 
14
15
  export const match = () => ({
15
- 'const __a = __expr': (vars, path) => {
16
+ 'const __a = __expr': ({__expr}, path) => {
17
+ if (isOnlyWhitespaces(__expr))
18
+ return false;
19
+
20
+ if (!path.isNext())
21
+ return true;
22
+
16
23
  const punctuators = [
17
24
  comma,
18
25
  semicolon,
@@ -20,16 +27,7 @@ export const match = () => ({
20
27
  question,
21
28
  ];
22
29
 
23
- if (!path.isNext())
24
- return true;
25
-
26
- if (path.isNextPunctuator(punctuators))
27
- return false;
28
-
29
- for (const token of path.getAllNext()) {
30
- if (isPunctuator(token, semicolon))
31
- return false;
32
- }
30
+ return !path.isNextPunctuator(punctuators);
33
31
  },
34
32
  '__a(__args)': (vars, path) => {
35
33
  if (path.isNextPunctuator() && !path.isNextPunctuator(closeCurlyBrace))
@@ -56,3 +54,4 @@ export const replace = () => ({
56
54
 
57
55
  '})': '});',
58
56
  });
57
+
@@ -6,6 +6,7 @@ import {
6
6
  isWhiteSpace,
7
7
  isTemplateTail,
8
8
  isTemplateMiddle,
9
+ isNoSubstitutionTemplate,
9
10
  } from '#types';
10
11
 
11
12
  export const createPath = ({tokens, start, end}) => ({
@@ -20,10 +21,6 @@ export const createPath = ({tokens, start, end}) => ({
20
21
  tokens,
21
22
  start,
22
23
  }),
23
- getAllNext: createGetAllNext({
24
- tokens,
25
- end,
26
- }),
27
24
  isNextKeyword: createIsNextKeyword({
28
25
  tokens,
29
26
  end,
@@ -94,6 +91,9 @@ const createIsInsideTemplate = ({tokens, end}) => () => {
94
91
  if (isTemplateTail(current))
95
92
  return true;
96
93
 
94
+ if (isNoSubstitutionTemplate(current))
95
+ return true;
96
+
97
97
  return isTemplateMiddle(current);
98
98
  };
99
99
 
@@ -134,9 +134,3 @@ const createGetAllPrev = ({tokens, start}) => function*() {
134
134
  yield tokens[i];
135
135
  }
136
136
  };
137
-
138
- const createGetAllNext = ({tokens, end}) => function*() {
139
- for (let i = end; i < tokens.length; ++i) {
140
- yield tokens[i];
141
- }
142
- };
@@ -3,6 +3,7 @@ const maybeArray = (a) => isArray(a) ? a : [a];
3
3
  const isString = (a) => typeof a === 'string';
4
4
 
5
5
  export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';
6
+ export const isNoSubstitutionTemplate = (a) => a?.type === 'NoSubstitutionTemplate';
6
7
  export const isTemplateTail = (a) => a?.type === 'TemplateTail';
7
8
  export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
8
9
  export const isIdentifier = (token, newToken) => {
@@ -155,3 +156,17 @@ export const quote = Punctuator(`'`);
155
156
 
156
157
  export const OK = true;
157
158
  export const NOT_OK = false;
159
+
160
+ export const isOnlyWhitespaces = (tokens) => {
161
+ for (const token of tokens) {
162
+ if (isWhiteSpace(token))
163
+ continue;
164
+
165
+ if (isNewLine(token))
166
+ continue;
167
+
168
+ return false;
169
+ }
170
+
171
+ return true;
172
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.65.0",
3
+ "version": "1.67.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",