flatlint 1.54.1 → 1.56.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.17, v1.56.0
2
+
3
+ feature:
4
+ - 8683716 flatlint: convert-comma-to-semicolon: improve
5
+
6
+ 2025.01.17, v1.55.0
7
+
8
+ feature:
9
+ - 8d3ee0b flatlint: remove-useless-semicolon -> convert-semicolon-to-comma
10
+
1
11
  2025.01.17, v1.54.1
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -137,7 +137,7 @@ import {
137
137
 
138
138
  </details>
139
139
 
140
- <details><summary>remove useless semicolon</summary>
140
+ <details><summary>convert semicolon to comma</summary>
141
141
 
142
142
  ```diff
143
143
  const a = {
@@ -1,8 +1,11 @@
1
1
  import {
2
+ closeCurlyBrace,
2
3
  closeRoundBrace,
3
4
  isNewLine,
4
5
  NOT_OK,
5
6
  OK,
7
+ openCurlyBrace,
8
+ openRoundBrace,
6
9
  } from '#types';
7
10
  import {equal} from './equal.js';
8
11
 
@@ -13,16 +16,34 @@ export const collectArgs = ({currentTokenIndex, tokens}) => {
13
16
  if (equal(tokens[index], closeRoundBrace))
14
17
  return [NOT_OK];
15
18
 
19
+ let curlyBracesBalance = 0;
20
+ let roundBracesBalance = 0;
21
+
16
22
  for (; index < n; index++) {
17
23
  const token = tokens[index];
18
24
 
25
+ if (equal(token, openRoundBrace))
26
+ ++roundBracesBalance;
27
+
19
28
  if (equal(token, closeRoundBrace))
29
+ --roundBracesBalance;
30
+
31
+ if (equal(token, openCurlyBrace))
32
+ ++curlyBracesBalance;
33
+
34
+ if (equal(token, closeCurlyBrace))
35
+ --curlyBracesBalance;
36
+
37
+ if (curlyBracesBalance < 0)
20
38
  break;
21
39
 
22
- if (isNewLine(token))
40
+ if (roundBracesBalance < 0)
23
41
  break;
24
42
  }
25
43
 
44
+ if (isNewLine(tokens[index - 1]))
45
+ --index;
46
+
26
47
  return [
27
48
  OK,
28
49
  --index,
@@ -1,37 +1,27 @@
1
1
  import {
2
2
  arrow,
3
+ closeCurlyBrace,
3
4
  closeRoundBrace,
4
5
  isPunctuator,
6
+ openCurlyBrace,
5
7
  openRoundBrace,
6
8
  } from '#types';
7
9
 
8
10
  export const report = () => 'Add missing round brace';
9
11
 
10
12
  export const match = () => ({
11
- '(__args) {': ({__args}) => {
12
- if (isPunctuator(arrow, __args))
13
- return false;
14
-
15
- if (!isPunctuator(openRoundBrace, __args))
16
- return false;
17
-
18
- return !isPunctuator(closeRoundBrace, __args);
19
- },
20
- '__a(__args': (vars, path) => {
13
+ '__a(__args': ({__args}, path) => {
21
14
  if (path.isCurrentPunctuator(closeRoundBrace))
22
15
  return false;
23
16
 
24
- for (const token of path.getAllNext()) {
25
- if (isPunctuator(token, closeRoundBrace))
26
- return false;
27
- }
28
-
29
- return true;
17
+ return !path.isNextPunctuator(closeRoundBrace);
30
18
  },
31
19
  });
32
20
 
33
21
  export const replace = () => ({
34
22
  'if __a > __b': 'if (__a > __b)',
35
23
  '__a(__args': '__a(__args)',
36
- '(__args) {': '(__args)) {',
24
+ 'if (__a.__b(__args) {': 'if (__a.__b(__args)) {',
25
+ 'if (__a(__args) {': 'if (__a(__args)) {',
37
26
  });
27
+
@@ -13,7 +13,7 @@ import {
13
13
  export const report = () => 'Add missing semicolon';
14
14
 
15
15
  export const match = () => ({
16
- 'const __a = __expr': (vars, path) => {
16
+ 'const __a = __expr': ({__expr}, path) => {
17
17
  const punctuators = [
18
18
  comma,
19
19
  semicolon,
@@ -21,6 +21,9 @@ export const match = () => ({
21
21
  question,
22
22
  ];
23
23
 
24
+ if (isPunctuator(openCurlyBrace, __expr))
25
+ return false;
26
+
24
27
  if (path.isNextPunctuator(punctuators))
25
28
  return false;
26
29
 
@@ -12,6 +12,9 @@ import {
12
12
  export const report = () => 'Use semicolon instead of trailing comma';
13
13
  export const match = () => ({
14
14
  '__a(__args),': (vars, path) => {
15
+ if (path.isNextKeyword())
16
+ return true;
17
+
15
18
  for (const token of path.getAllPrev()) {
16
19
  if (isPunctuator(token, colon))
17
20
  return false;
@@ -1,6 +1,6 @@
1
1
  import {isIdentifier} from '#types';
2
2
 
3
- export const report = () => 'Remove useless semicolon';
3
+ export const report = () => `Use ',' instead of ';'`;
4
4
 
5
5
  export const match = () => ({
6
6
  '__a: __expr;': (vars, path) => {
@@ -15,5 +15,4 @@ export const match = () => ({
15
15
 
16
16
  export const replace = () => ({
17
17
  '__a: __expr;': '__a: __expr,',
18
- 'export;': 'export',
19
18
  });
package/lib/plugins.js CHANGED
@@ -11,7 +11,7 @@ import * as convertFromToRequire from './plugins/convert-from-to-require/index.j
11
11
  import * as removeUselessComma from './plugins/remove-useless-comma/index.js';
12
12
  import * as removeInvalidCharacter from './plugins/remove-invalid-character/index.js';
13
13
  import * as removeUselessRoundBrace from './plugins/remove-useless-round-brace/index.js';
14
- import * as removeUselessSemicolon from './plugins/remove-useless-semicolon/index.js';
14
+ import * as convertSemicolonToComma from './plugins/convert-semicolon-to-comma/index.js';
15
15
  import * as wrapAssignmentInParens from './plugins/wrap-assignment-in-parens/index.js';
16
16
 
17
17
  export const plugins = [
@@ -24,9 +24,9 @@ export const plugins = [
24
24
  ['add-missing-quote', addMissingQuote],
25
25
  ['add-const-to-export', addConstToExport],
26
26
  ['convert-comma-to-semicolon', convertCommaToSemicolon],
27
+ ['convert-semicolon-to-comma', convertSemicolonToComma],
27
28
  ['convert-from-to-require', convertFromToRequire],
28
29
  ['remove-useless-round-brace', removeUselessRoundBrace],
29
- ['remove-useless-semicolon', removeUselessSemicolon],
30
30
  ['remove-useless-comma', removeUselessComma],
31
31
  ['remove-invalid-character', removeInvalidCharacter],
32
32
  ['wrap-assignment-in-parens', wrapAssignmentInParens],
@@ -8,9 +8,6 @@ import {
8
8
  isTemplateMiddle,
9
9
  } from '#types';
10
10
 
11
- const {isArray} = Array;
12
- const maybeArray = (a) => isArray(a) ? a : [a];
13
-
14
11
  export const createPath = ({tokens, start, end}) => ({
15
12
  tokens,
16
13
  start,
@@ -47,33 +44,12 @@ export const createPath = ({tokens, start, end}) => ({
47
44
  tokens,
48
45
  start,
49
46
  }),
50
- isPrevPunctuator: createIsPrevPunctuator({
51
- tokens,
52
- start,
53
- end,
54
- }),
55
47
  isCurrentPunctuator: createIsNextPunctuator({
56
48
  tokens,
57
49
  end: end - 1,
58
50
  }),
59
51
  });
60
52
 
61
- const prev = ({tokens, start, end}) => {
62
- let i = end + 1;
63
-
64
- while (--i >= start) {
65
- const token = tokens[i];
66
-
67
- if (isNewLine(token))
68
- continue;
69
-
70
- if (isWhiteSpace(token))
71
- continue;
72
-
73
- return token;
74
- }
75
- };
76
-
77
53
  const next = ({tokens, end}) => {
78
54
  let i = end - 1;
79
55
 
@@ -145,24 +121,6 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
145
121
  return isPunctuator(current, punctuators);
146
122
  };
147
123
 
148
- const createIsPrevPunctuator = ({tokens, start, end}) => (punctuators) => {
149
- const current = prev({
150
- tokens,
151
- start,
152
- end,
153
- });
154
-
155
- if (!current)
156
- return false;
157
-
158
- for (const punctuator of maybeArray(punctuators)) {
159
- if (isPunctuator(current, punctuator))
160
- return true;
161
- }
162
-
163
- return false;
164
- };
165
-
166
124
  const createIsPrevIdentifier = ({tokens, start}) => (value) => {
167
125
  const SPACE = 1;
168
126
  const FUNCTION = 1;
@@ -28,9 +28,10 @@ export const isKeyword = (token) => {
28
28
  const keywords = [
29
29
  'as',
30
30
  'await',
31
+ 'const',
32
+ 'continue',
31
33
  'var',
32
34
  'let',
33
- 'const',
34
35
  'export',
35
36
  'from',
36
37
  'import',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.54.1",
3
+ "version": "1.56.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",