flatlint 1.64.0 → 1.66.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,16 @@
1
+ 2025.01.20, v1.66.0
2
+
3
+ feature:
4
+ - ff4cc99 flatlint: simplify
5
+
6
+ 2025.01.20, v1.65.0
7
+
8
+ fix:
9
+ - edcfcda flatlint: replacer: column end
10
+
11
+ feature:
12
+ - 8c99182 flatlint: position
13
+
1
14
  2025.01.19, v1.64.0
2
15
 
3
16
  feature:
@@ -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;
@@ -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
+
@@ -20,10 +20,6 @@ export const createPath = ({tokens, start, end}) => ({
20
20
  tokens,
21
21
  start,
22
22
  }),
23
- getAllNext: createGetAllNext({
24
- tokens,
25
- end,
26
- }),
27
23
  isNextKeyword: createIsNextKeyword({
28
24
  tokens,
29
25
  end,
@@ -134,9 +130,3 @@ const createGetAllPrev = ({tokens, start}) => function*() {
134
130
  yield tokens[i];
135
131
  }
136
132
  };
137
-
138
- const createGetAllNext = ({tokens, end}) => function*() {
139
- for (let i = end; i < tokens.length; ++i) {
140
- yield tokens[i];
141
- }
142
- };
@@ -70,14 +70,16 @@ export const replace = (tokens, {fix, rule, plugin}) => {
70
70
  continue;
71
71
  }
72
72
 
73
- const {line, column} = tokens[start];
73
+ const {line, column} = tokens[end - 1];
74
74
  const message = plugin.report();
75
75
 
76
76
  places.push({
77
77
  rule,
78
78
  message,
79
- line,
80
- column,
79
+ position: {
80
+ line,
81
+ column,
82
+ },
81
83
  });
82
84
 
83
85
  index = end;
@@ -155,3 +155,17 @@ export const quote = Punctuator(`'`);
155
155
 
156
156
  export const OK = true;
157
157
  export const NOT_OK = false;
158
+
159
+ export const isOnlyWhitespaces = (tokens) => {
160
+ for (const token of tokens) {
161
+ if (isWhiteSpace(token))
162
+ continue;
163
+
164
+ if (isNewLine(token))
165
+ continue;
166
+
167
+ return false;
168
+ }
169
+
170
+ return true;
171
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.64.0",
3
+ "version": "1.66.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",