flatlint 1.37.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,13 @@
1
+ 2025.01.12, v1.39.0
2
+
3
+ feature:
4
+ - 8fad253 flatlint: add-missing-comma: add
5
+
6
+ 2025.01.11, v1.38.0
7
+
8
+ feature:
9
+ - 911478f flatlint: remove-invalid-character: add
10
+
1
11
  2025.01.10, v1.37.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -19,7 +19,7 @@ npm i flatlint
19
19
 
20
20
  </details>
21
21
 
22
- <details><summary>Convert <code>,</code> to <code>;</code> at the end of statement</summary>
22
+ <details><summary>convert <code>,</code> to <code>;</code> at the end of statement</summary>
23
23
 
24
24
  ```diff
25
25
  -const a = 5,
@@ -36,7 +36,7 @@ function x() {
36
36
 
37
37
  </details>
38
38
 
39
- <details><summary>Convert <code>from</code> to <code>require</code></summary>
39
+ <details><summary>convert <code>from</code> to <code>require</code></summary>
40
40
 
41
41
  ```diff
42
42
  -const a = from 'a';
@@ -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
@@ -125,6 +137,23 @@ function x() {
125
137
 
126
138
  </details>
127
139
 
140
+ <details><summary>remove invalid character</summary>
141
+
142
+ ```diff
143
+ -const {¬
144
+ - is,¬
145
+ - isArgsStr,¬
146
+ - isTypeParamsStr,¬
147
+ -} = require('./is');¬
148
+ +const {
149
+ + is,
150
+ + isArgsStr,
151
+ + isTypeParamsStr,
152
+ +} = require('./is');
153
+ ```
154
+
155
+ </details>
156
+
128
157
  <details><summary>add missing quote</summary>
129
158
 
130
159
  ```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
+
@@ -0,0 +1,6 @@
1
+ export const report = () => 'Remove invalid character';
2
+
3
+ export const replace = () => ({
4
+ '¬': '',
5
+ ';¬': ';',
6
+ });
package/lib/plugins.js CHANGED
@@ -7,6 +7,7 @@ import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/i
7
7
  import * as convertFromToRequire from './plugins/convert-from-to-require/index.js';
8
8
  import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
9
9
  import * as removeUselessComma from './plugins/remove-useless-comma/index.js';
10
+ import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
10
11
  import * as addConstToExport from './plugins/add-const-to-export/index.js';
11
12
 
12
13
  export const plugins = [
@@ -20,4 +21,5 @@ export const plugins = [
20
21
  ['convert-from-to-require', convertFromToRequire],
21
22
  ['remove-useless-round-brace', removeUselessRoundBrace],
22
23
  ['remove-useless-comma', removeUselessComma],
24
+ ['remove-invalid-character', removeInvalidCharacter],
23
25
  ];
@@ -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.37.0",
3
+ "version": "1.39.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",