flatlint 1.38.0 → 1.39.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.12, v1.39.0
2
+
3
+ feature:
4
+ - 8fad253 flatlint: add-missing-comma: add
5
+
1
6
  2025.01.11, v1.38.0
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -64,6 +64,18 @@ const m = {
64
64
 
65
65
  </details>
66
66
 
67
+ <details><summary>add missing comma</summary>
68
+
69
+ ```diff
70
+ import {
71
+ - a
72
+ + a,
73
+ b,
74
+ } from 'c';
75
+ ```
76
+
77
+ </details>
78
+
67
79
  <details><summary>add <code>const</code> to <code>export</code></summary>
68
80
 
69
81
  ```diff
@@ -10,6 +10,9 @@ import {collectArray} from './collect-array.js';
10
10
  import {collectExpression} from './collect-expression.js';
11
11
  import {collectArgs} from './collect-args.js';
12
12
 
13
+ const {isArray} = Array;
14
+ const maybeArray = (a) => isArray(a) ? a : [a];
15
+
13
16
  const {entries} = Object;
14
17
 
15
18
  export function findVarsWays(tokens) {
@@ -36,21 +39,25 @@ export function getValues(tokens, waysFrom) {
36
39
  let end = index;
37
40
  let ok = true;
38
41
 
39
- if (isTemplateArray(name))
42
+ if (isTemplateArray(name)) {
40
43
  [ok, end] = collectArray({
41
44
  currentTokenIndex: index,
42
45
  tokens,
43
46
  });
44
- else if (isTemplateExpression(name))
47
+ } else if (isTemplateExpression(name)) {
45
48
  end = collectExpression({
46
49
  currentTokenIndex: index,
47
50
  tokens,
48
51
  });
49
- else if (isTemplateArgs(name))
52
+ } else if (isTemplateArgs(name)) {
50
53
  [ok, end] = collectArgs({
51
54
  currentTokenIndex: index,
52
55
  tokens,
53
56
  });
57
+ } else {
58
+ values[name] = tokens[index];
59
+ continue;
60
+ }
54
61
 
55
62
  if (!ok) {
56
63
  values[name] = [];
@@ -65,7 +72,8 @@ export function getValues(tokens, waysFrom) {
65
72
 
66
73
  export function setValues({to, waysTo, values}) {
67
74
  for (const [name, index] of entries(waysTo)) {
68
- to.splice(index, 1, ...values[name]);
75
+ const current = maybeArray(values[name]);
76
+ to.splice(index, 1, ...current);
69
77
  }
70
78
  }
71
79
 
@@ -75,3 +83,4 @@ export function getCurrentValues({from, start, end, tokens}) {
75
83
 
76
84
  return getValues(current, waysFrom);
77
85
  }
86
+
@@ -0,0 +1,31 @@
1
+ import {
2
+ comma,
3
+ isPunctuator,
4
+ semicolon,
5
+ arrow,
6
+ openCurlyBrace,
7
+ closeRoundBrace,
8
+ dot,
9
+ isIdentifier,
10
+ isOperator,
11
+ } from '#types';
12
+
13
+ export const report = () => 'Add missing comma';
14
+
15
+ export const match = () => ({
16
+ __a: ({__a}, path) => {
17
+ if (!isIdentifier(__a))
18
+ return false;
19
+
20
+ if (isOperator(__a))
21
+ return false;
22
+
23
+ return !path.isNextPunctuator(comma);
24
+ },
25
+ });
26
+
27
+ export const replace = () => ({
28
+ __a: '__a,',
29
+ });
30
+
31
+
@@ -22,6 +22,7 @@ export const isOperator = (token) => {
22
22
  'const',
23
23
  'export',
24
24
  'from',
25
+ 'import',
25
26
  ];
26
27
 
27
28
  for (const operator of operators) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.38.0",
3
+ "version": "1.39.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",