flatlint 1.80.1 → 1.82.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.23, v1.82.0
2
+
3
+ feature:
4
+ - e1b595d flatlint: convert-comma-to-semicolon: exclude prev punctuator
5
+
6
+ 2025.01.22, v1.81.0
7
+
8
+ feature:
9
+ - 92d7b03 flatlint: move out keywords
10
+
1
11
  2025.01.22, v1.80.1
2
12
 
3
13
  feature:
@@ -39,7 +39,12 @@ export const match = () => ({
39
39
 
40
40
  return !path.isNextPunctuator(quote);
41
41
  },
42
- '__a.__b = __expr,': ({}, path) => !path.isNextPunctuator([quote, openCurlyBrace]),
42
+ '__a.__b = __expr,': ({__expr}, path) => {
43
+ if (path.isPrevPunctuator())
44
+ return false;
45
+
46
+ return !path.isNextPunctuator([quote, openCurlyBrace]);
47
+ },
43
48
  });
44
49
 
45
50
  export const replace = () => ({
@@ -63,3 +68,4 @@ const check = ({__x}, path) => {
63
68
 
64
69
  return path.isNextKeyword() && !path.isNextIdentifier('new');
65
70
  };
71
+
@@ -29,6 +29,10 @@ export const createPath = ({tokens, start, end}) => ({
29
29
  tokens,
30
30
  end,
31
31
  }),
32
+ isPrevPunctuator: createIsPrevPunctuator({
33
+ tokens,
34
+ start,
35
+ }),
32
36
  isInsideTemplate: createIsInsideTemplate({
33
37
  tokens,
34
38
  end,
@@ -66,6 +70,25 @@ const next = ({tokens, end}) => {
66
70
  }
67
71
  };
68
72
 
73
+ const prev = ({tokens, start}) => {
74
+ let i = start;
75
+
76
+ while (--i) {
77
+ const token = tokens[i];
78
+
79
+ if (!token)
80
+ return token;
81
+
82
+ if (isNewLine(token))
83
+ continue;
84
+
85
+ if (isWhiteSpace(token))
86
+ continue;
87
+
88
+ return token;
89
+ }
90
+ };
91
+
69
92
  const createIsNext = ({tokens, end}) => () => {
70
93
  return Boolean(next({
71
94
  tokens,
@@ -118,6 +141,18 @@ const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
118
141
  return isPunctuator(current, punctuators);
119
142
  };
120
143
 
144
+ const createIsPrevPunctuator = ({tokens, start}) => (punctuators) => {
145
+ const current = prev({
146
+ tokens,
147
+ start,
148
+ });
149
+
150
+ if (!current)
151
+ return false;
152
+
153
+ return isPunctuator(current, punctuators);
154
+ };
155
+
121
156
  const createIsPrevIdentifier = ({tokens, start}) => (value) => {
122
157
  const SPACE = 1;
123
158
  const FUNCTION = 1;
@@ -1,4 +1,4 @@
1
- import {keywords} from './keywords.js';
1
+ import * as keyword from '@putout/operator-keyword';
2
2
 
3
3
  const {isArray} = Array;
4
4
  const maybeArray = (a) => isArray(a) ? a : [a];
@@ -32,12 +32,12 @@ export const isKeyword = (token, name) => {
32
32
  if (!token)
33
33
  return false;
34
34
 
35
- for (const keyword of keywords) {
36
- if (isIdentifier(token, keyword))
37
- return true;
38
- }
35
+ const {value} = token;
39
36
 
40
- return false;
37
+ if (!keyword.isKeyword(value))
38
+ return false;
39
+
40
+ return isIdentifier(token, name);
41
41
  };
42
42
 
43
43
  export const isOneOfPunctuators = (token, punctuators) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.80.1",
3
+ "version": "1.82.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",
@@ -81,6 +81,7 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "@putout/engine-loader": "^15.1.1",
84
+ "@putout/operator-keyword": "^1.0.0",
84
85
  "debug": "^4.4.0",
85
86
  "js-tokens": "^9.0.1"
86
87
  },
@@ -1,22 +0,0 @@
1
- export const keywords = [
2
- 'as',
3
- 'await',
4
- 'const',
5
- 'continue',
6
- 'for',
7
- 'function',
8
- 'var',
9
- 'let',
10
- 'new',
11
- 'else',
12
- 'export',
13
- 'from',
14
- 'import',
15
- 'return',
16
- 'throw',
17
- 'of',
18
- 'if',
19
- 'yield',
20
- 'typeof',
21
- 'while',
22
- ];