flatlint 2.1.6 → 2.1.7

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.03.01, v2.1.7
2
+
3
+ feature:
4
+ - 180fc5e flatlint: add-missing-comma: type
5
+
1
6
  2025.03.01, v2.1.6
2
7
 
3
8
  feature:
@@ -9,13 +9,7 @@ import {
9
9
  import {collectArray} from './collect-array.js';
10
10
  import {collectExpression} from './collect-expression.js';
11
11
  import {collectArgs} from './collect-args.js';
12
- import {
13
- equal,
14
- equalAny,
15
- equalId,
16
- equalQuote,
17
- equalStr,
18
- } from './equal.js';
12
+ import {equalTemplate} from './equal.js';
19
13
 
20
14
  export const compare = (source, template, {index = 0} = {}) => {
21
15
  const templateTokens = prepare(template);
@@ -92,7 +86,7 @@ export const compare = (source, template, {index = 0} = {}) => {
92
86
  delta = indexOfArrayEnd - currentTokenIndex;
93
87
  index = indexOfArrayEnd - templateIndex;
94
88
  }
95
- } else if (!compareAll(currentToken, templateToken)) {
89
+ } else if (!equalTemplate(currentToken, templateToken)) {
96
90
  isEqual = false;
97
91
  break;
98
92
  }
@@ -113,23 +107,6 @@ export const compare = (source, template, {index = 0} = {}) => {
113
107
  return [NOT_OK];
114
108
  };
115
109
 
116
- const comparators = [
117
- equal,
118
- equalId,
119
- equalStr,
120
- equalAny,
121
- equalQuote,
122
- ];
123
-
124
- function compareAll(a, b) {
125
- for (const currentCompare of comparators) {
126
- if (currentCompare(a, b))
127
- return true;
128
- }
129
-
130
- return false;
131
- }
132
-
133
110
  function checkIndexes(index, indexCheck) {
134
111
  /* c8 ignore start */
135
112
  if (indexCheck > index + 1)
@@ -7,6 +7,23 @@ import {
7
7
  isStringLiteral,
8
8
  } from '#types';
9
9
 
10
+ const comparators = [
11
+ equal,
12
+ equalId,
13
+ equalStr,
14
+ equalAny,
15
+ equalQuote,
16
+ ];
17
+
18
+ export function equalTemplate(a, b) {
19
+ for (const currentCompare of comparators) {
20
+ if (currentCompare(a, b))
21
+ return true;
22
+ }
23
+
24
+ return false;
25
+ }
26
+
10
27
  export function equal(a, b) {
11
28
  return a.type === b.type && a.value === b.value;
12
29
  }
@@ -3,6 +3,7 @@ import {
3
3
  isMultilineComment,
4
4
  isNewLine,
5
5
  isStringLiteral,
6
+ isWhiteSpace,
6
7
  } from '#types';
7
8
  import {parseStringLiteral} from './string-literal.js';
8
9
 
@@ -21,7 +22,7 @@ const preprocess = (tokens) => {
21
22
  }
22
23
  };
23
24
 
24
- export const prepare = (a) => {
25
+ export const prepare = (a, {cutWhiteSpaces = false} = {}) => {
25
26
  if (!isString(a))
26
27
  return a;
27
28
 
@@ -31,9 +32,25 @@ export const prepare = (a) => {
31
32
 
32
33
  preprocess(array);
33
34
 
35
+ if (cutWhiteSpaces)
36
+ return runCutWhiteSpaces(array);
37
+
34
38
  return array;
35
39
  };
36
40
 
41
+ function runCutWhiteSpaces(array) {
42
+ const result = [];
43
+
44
+ for (const current of array) {
45
+ if (isWhiteSpace(current))
46
+ continue;
47
+
48
+ result.push(current);
49
+ }
50
+
51
+ return result;
52
+ }
53
+
37
54
  export const parse = (source) => {
38
55
  return getTokensWithLocation(prepare(source));
39
56
  };
@@ -18,7 +18,12 @@ export const match = () => ({
18
18
  return path.isNextIdentifier();
19
19
  },
20
20
  '__a': ({__a}, path) => {
21
- if (isKeyword(__a))
21
+ const isType = isKeyword(__a, 'type');
22
+
23
+ if (isType && path.isNextCompare('__a ='))
24
+ return false;
25
+
26
+ if (!isType && isKeyword(__a))
22
27
  return false;
23
28
 
24
29
  if (path.isNextKeyword())
@@ -12,7 +12,7 @@ import {
12
12
  isNewLine,
13
13
  isWhiteSpace,
14
14
  } from '#types';
15
- import {equal} from '../compare/equal.js';
15
+ import {equalTemplate} from '../compare/equal.js';
16
16
 
17
17
  export const createPath = ({tokens, start, end}) => ({
18
18
  tokens,
@@ -217,8 +217,6 @@ const createGetAllNext = ({tokens, end}) => function*() {
217
217
 
218
218
  yield tokens[i];
219
219
  }
220
- /* c8 ignore start */
221
- /* c8 ignore end */
222
220
  };
223
221
 
224
222
  const createIsNextCompare = ({tokens, end}) => (template) => {
@@ -227,15 +225,19 @@ const createIsNextCompare = ({tokens, end}) => (template) => {
227
225
  end,
228
226
  });
229
227
 
230
- const n = template.length;
231
- const templateTokens = prepare(template);
228
+ const templateTokens = prepare(template, {
229
+ cutWhiteSpaces: true,
230
+ });
231
+
232
+ const n = templateTokens.length;
233
+
232
234
  let i = 0;
233
235
 
234
236
  for (const token of getAllNext()) {
235
237
  if (i === n)
236
238
  break;
237
239
 
238
- if (!equal(token, templateTokens[i]))
240
+ if (!equalTemplate(token, templateTokens[i]))
239
241
  return false;
240
242
 
241
243
  ++i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",