flatlint 1.34.0 → 1.36.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.10, v1.36.0
2
+
3
+ feature:
4
+ - bf14d47 flatlint: add-missing-semicolon: exclude chain
5
+
6
+ 2025.01.10, v1.35.0
7
+
8
+ feature:
9
+ - aeb79de flatlint: add-missing-semicolon: open round brace
10
+
1
11
  2025.01.10, v1.34.0
2
12
 
3
13
  feature:
@@ -4,19 +4,21 @@ import {
4
4
  semicolon,
5
5
  arrow,
6
6
  openCurlyBrace,
7
+ closeRoundBrace,
8
+ dot,
7
9
  } from '#types';
8
10
 
9
11
  export const report = () => 'Add missing semicolon';
10
12
 
11
13
  export const match = () => ({
12
14
  'const __a = __expr': (vars, path) => {
13
- if (path.isNextPunctuator(comma))
14
- return false;
15
-
16
- if (path.isNextPunctuator(semicolon))
17
- return false;
15
+ const punctuators = [
16
+ comma,
17
+ semicolon,
18
+ openCurlyBrace,
19
+ ];
18
20
 
19
- if (path.isNextPunctuator(openCurlyBrace))
21
+ if (path.isNextPunctuator(punctuators))
20
22
  return false;
21
23
 
22
24
  for (const token of path.getAllNext()) {
@@ -27,25 +29,24 @@ export const match = () => ({
27
29
  return true;
28
30
  },
29
31
  '__a(__args)': (vars, path) => {
30
- if (path.isNextPunctuator(comma))
31
- return false;
32
+ const punctuators = [
33
+ comma,
34
+ semicolon,
35
+ arrow,
36
+ closeRoundBrace,
37
+ openCurlyBrace,
38
+ dot,
39
+ ];
32
40
 
33
- if (path.isNextPunctuator(semicolon))
34
- return false;
35
-
36
- if (path.isNextPunctuator(arrow))
37
- return false;
38
-
39
- if (path.isNextPunctuator(openCurlyBrace))
41
+ if (path.isNextPunctuator(punctuators))
40
42
  return false;
41
43
 
42
44
  return !path.isPrevIdentifier('function');
43
45
  },
44
46
  '})': (vars, path) => {
45
- if (path.isNextPunctuator(arrow))
46
- return false;
47
+ const punctuators = [arrow, comma];
47
48
 
48
- if (path.isNextPunctuator(comma))
49
+ if (path.isNextPunctuator(punctuators))
49
50
  return false;
50
51
 
51
52
  return !path.isNextPunctuator(semicolon);
@@ -28,8 +28,5 @@ export const replace = () => ({
28
28
  });
29
29
 
30
30
  const check = (vars, path) => {
31
- if (!path.isNext())
32
- return true;
33
-
34
31
  return path.isNextOperator();
35
32
  };
@@ -6,6 +6,9 @@ import {
6
6
  isWhiteSpace,
7
7
  } from '#types';
8
8
 
9
+ const {isArray} = Array;
10
+ const maybeArray = (a) => isArray(a) ? a : [a];
11
+
9
12
  export const createPath = ({tokens, start, end}) => ({
10
13
  tokens,
11
14
  start,
@@ -38,12 +41,33 @@ export const createPath = ({tokens, start, end}) => ({
38
41
  tokens,
39
42
  start,
40
43
  }),
44
+ isPrevPunctuator: createIsPrevPunctuator({
45
+ tokens,
46
+ start,
47
+ end,
48
+ }),
41
49
  isCurrentPunctuator: createIsNextPunctuator({
42
50
  tokens,
43
51
  end: end - 1,
44
52
  }),
45
53
  });
46
54
 
55
+ const prev = ({tokens, start, end}) => {
56
+ let i = end + 1;
57
+
58
+ while (--i >= start) {
59
+ const token = tokens[i];
60
+
61
+ if (isNewLine(token))
62
+ continue;
63
+
64
+ if (isWhiteSpace(token))
65
+ continue;
66
+
67
+ return token;
68
+ }
69
+ };
70
+
47
71
  const next = ({tokens, end}) => {
48
72
  let i = end - 1;
49
73
 
@@ -88,7 +112,7 @@ const createIsNextOperator = ({tokens, end}) => () => {
88
112
  return isOperator(current);
89
113
  };
90
114
 
91
- const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
115
+ const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
92
116
  const current = next({
93
117
  tokens,
94
118
  end,
@@ -97,7 +121,30 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
97
121
  if (!current)
98
122
  return false;
99
123
 
100
- return isPunctuator(current, punctuator);
124
+ for (const punctuator of maybeArray(punctuators)) {
125
+ if (isPunctuator(current, punctuator))
126
+ return true;
127
+ }
128
+
129
+ return false;
130
+ };
131
+
132
+ const createIsPrevPunctuator = ({tokens, start, end}) => (punctuators) => {
133
+ const current = prev({
134
+ tokens,
135
+ start,
136
+ end,
137
+ });
138
+
139
+ if (!current)
140
+ return false;
141
+
142
+ for (const punctuator of maybeArray(punctuators)) {
143
+ if (isPunctuator(current, punctuator))
144
+ return true;
145
+ }
146
+
147
+ return false;
101
148
  };
102
149
 
103
150
  const createIsPrevIdentifier = ({tokens, start}) => (value) => {
@@ -96,14 +96,14 @@ export const isTemplateArgsToken = (a) => isIdentifier(a) && isTemplateArgs(a.va
96
96
  export const arrow = Punctuator('=>');
97
97
  export const closeRoundBrace = Punctuator(')');
98
98
  export const closeSquareBrace = Punctuator(']');
99
+ export const colon = Punctuator(':');
100
+ export const comma = Punctuator(',');
101
+ export const dot = Punctuator('.');
99
102
  export const openRoundBrace = Punctuator('(');
100
103
  export const semicolon = Punctuator(';');
101
- export const comma = Punctuator(',');
102
- export const colon = Punctuator(':');
103
104
  export const openCurlyBrace = Punctuator('{');
104
105
  export const closeCurlyBrace = Punctuator('}');
105
106
  export const openSquireBrace = Punctuator('[');
106
- export const closeSquireBrace = Punctuator(']');
107
107
  export const quote = Punctuator(`'`);
108
108
 
109
109
  export const OK = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.34.0",
3
+ "version": "1.36.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",