flatlint 1.55.0 → 1.57.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.18, v1.57.0
2
+
3
+ feature:
4
+ - 93b8c50 flatlint: convert-comma-to-semicolon: module
5
+
6
+ 2025.01.17, v1.56.0
7
+
8
+ feature:
9
+ - 8683716 flatlint: convert-comma-to-semicolon: improve
10
+
1
11
  2025.01.17, v1.55.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 comma to semicolon</summary>
23
23
 
24
24
  ```diff
25
25
  -const a = 5,
@@ -32,6 +32,10 @@ function x() {
32
32
 
33
33
  -import a from 'a',
34
34
  +import a from 'a';
35
+
36
+ -const a = 3,
37
+ +const a = 3;
38
+ module.exports = 2;
35
39
  ```
36
40
 
37
41
  </details>
@@ -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,34 +1,19 @@
1
- import {
2
- arrow,
3
- closeRoundBrace,
4
- isPunctuator,
5
- openRoundBrace,
6
- } from '#types';
1
+ import {closeRoundBrace} from '#types';
7
2
 
8
3
  export const report = () => 'Add missing round brace';
9
4
 
10
5
  export const match = () => ({
11
- '(__args) {': ({__args}) => {
12
- if (!isPunctuator(openRoundBrace, __args))
13
- return false;
14
-
15
- return !isPunctuator(closeRoundBrace, __args);
16
- },
17
6
  '__a(__args': (vars, path) => {
18
7
  if (path.isCurrentPunctuator(closeRoundBrace))
19
8
  return false;
20
9
 
21
- for (const token of path.getAllNext()) {
22
- if (isPunctuator(token, closeRoundBrace))
23
- return false;
24
- }
25
-
26
- return true;
10
+ return !path.isNextPunctuator(closeRoundBrace);
27
11
  },
28
12
  });
29
13
 
30
14
  export const replace = () => ({
31
15
  'if __a > __b': 'if (__a > __b)',
32
16
  '__a(__args': '__a(__args)',
33
- '(__args) {': '(__args)) {',
17
+ 'if (__a.__b(__args) {': 'if (__a.__b(__args)) {',
18
+ 'if (__a(__args) {': 'if (__a(__args)) {',
34
19
  });
@@ -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;
@@ -47,5 +50,8 @@ const check = ({__x}, path) => {
47
50
  if (!path.isNext())
48
51
  return true;
49
52
 
53
+ if (path.isNextIdentifier('module'))
54
+ return true;
55
+
50
56
  return path.isNextKeyword();
51
57
  };
@@ -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,
@@ -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.55.0",
3
+ "version": "1.57.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",