flatlint 1.39.2 → 1.40.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,15 @@
1
+ 2025.01.13, v1.40.0
2
+
3
+ feature:
4
+ - 5a1f09b flatlint: convert-comma-to-semicolon: use __x for keyword
5
+ - e85093b flatlint: types: isOperator -> isKeywrod
6
+ - 7c4afc1 flatlint: add-missing-comma: exclude await
7
+
8
+ 2025.01.12, v1.39.3
9
+
10
+ feature:
11
+ - 159980f flatlint: equal: __a: Identifier, NumericLiteral
12
+
1
13
  2025.01.12, v1.39.2
2
14
 
3
15
  fix:
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  isId,
3
3
  isIdentifier,
4
+ isNumericLiteral,
4
5
  isPunctuator,
5
6
  isQuote,
6
7
  isStringLiteral,
@@ -38,7 +39,7 @@ export function equalId(a, b) {
38
39
  if (!isIdentifier(b))
39
40
  return false;
40
41
 
41
- if (isPunctuator(a))
42
+ if (!isIdentifier(a) && !isNumericLiteral(a))
42
43
  return false;
43
44
 
44
45
  return isId(b.value);
@@ -1,13 +1,10 @@
1
- import {isIdentifier, isOperator} from '#types';
1
+ import {isKeyword} from '#types';
2
2
 
3
3
  export const report = () => 'Add missing comma';
4
4
 
5
5
  export const match = () => ({
6
6
  __a: ({__a}, path) => {
7
- if (!isIdentifier(__a))
8
- return false;
9
-
10
- if (isOperator(__a))
7
+ if (isKeyword(__a))
11
8
  return false;
12
9
 
13
10
  return !path.isNextPunctuator();
@@ -17,3 +14,4 @@ export const match = () => ({
17
14
  export const replace = () => ({
18
15
  __a: '__a,',
19
16
  });
17
+
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  colon,
3
+ isKeyword,
4
+ isOneOfKeywords,
3
5
  isPunctuator,
4
6
  quote,
5
7
  } from '#types';
@@ -14,24 +16,25 @@ export const match = () => ({
14
16
 
15
17
  return true;
16
18
  },
17
- 'let __a = __b,': check,
18
- 'var __a = __b': check,
19
- 'let __a,': check,
20
- 'var __a,': check,
19
+ '__x __a = __b,': check,
20
+ '__x __a,': check,
21
21
  'return __expr,': ({}, path) => !path.isNextPunctuator(quote),
22
22
  });
23
23
 
24
24
  export const replace = () => ({
25
25
  'from "__a",': 'from "__a";',
26
- 'var __a,': 'var __a;',
27
- 'let __a,': 'let __a;',
28
- 'var __a = __b,': 'var __a = __b;',
29
- 'let __a = __b,': 'let __a = __b;',
30
- 'const __a = __b,': 'const __a = __b;',
26
+ '__x __a,': '__x __a;',
27
+ '__x __a = __b,': '__x __a = __b;',
31
28
  '__a(__args),': '__a(__args);',
32
29
  'return __expr,': 'return __expr;',
33
30
  });
34
31
 
35
- const check = (vars, path) => {
36
- return path.isNextOperator();
32
+ const check = ({__x}, path) => {
33
+ if (!isOneOfKeywords(__x, ['var', 'let', 'const']))
34
+ return false;
35
+
36
+ if (!path.isNext())
37
+ return true;
38
+
39
+ return path.isNextKeyword();
37
40
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isIdentifier,
3
3
  isNewLine,
4
- isOperator,
4
+ isKeyword,
5
5
  isPunctuator,
6
6
  isWhiteSpace,
7
7
  } from '#types';
@@ -25,7 +25,7 @@ export const createPath = ({tokens, start, end}) => ({
25
25
  tokens,
26
26
  end,
27
27
  }),
28
- isNextOperator: createIsNextOperator({
28
+ isNextKeyword: createIsNextKeyword({
29
29
  tokens,
30
30
  end,
31
31
  }),
@@ -103,13 +103,16 @@ const createIsNextIdentifier = ({tokens, end}) => (value) => {
103
103
  return isIdentifier(current, value);
104
104
  };
105
105
 
106
- const createIsNextOperator = ({tokens, end}) => () => {
106
+ const createIsNextKeyword = ({tokens, end}) => () => {
107
107
  const current = next({
108
108
  tokens,
109
109
  end,
110
110
  });
111
111
 
112
- return isOperator(current);
112
+ if (!current)
113
+ return false;
114
+
115
+ return isKeyword(current);
113
116
  };
114
117
 
115
118
  const createIsNextPunctuator = ({tokens, end}) => (punctuators) => {
@@ -1,3 +1,5 @@
1
+ const {isArray} = Array;
2
+ const maybeArray = (a) => isArray(a) ? a : [a];
1
3
  const isString = (a) => typeof a === 'string';
2
4
 
3
5
  export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
@@ -15,8 +17,9 @@ export const isStringLiteral = ({type}) => type === 'StringLiteral';
15
17
  export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
16
18
  export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
17
19
  export const notWhiteSpace = (a) => !isWhiteSpace(a);
18
- export const isOperator = (token) => {
19
- const operators = [
20
+ export const isKeyword = (token) => {
21
+ const keywords = [
22
+ 'await',
20
23
  'var',
21
24
  'let',
22
25
  'const',
@@ -27,13 +30,23 @@ export const isOperator = (token) => {
27
30
  'function',
28
31
  ];
29
32
 
30
- for (const operator of operators) {
31
- if (isIdentifier(token, operator))
33
+ for (const keyword of keywords) {
34
+ if (isIdentifier(token, keyword))
32
35
  return true;
33
36
  }
34
37
 
35
38
  return false;
36
39
  };
40
+
41
+ export const isOneOfKeywords = (token, keywords) => {
42
+ for (const keyword of keywords) {
43
+ if (isIdentifier(token, keyword))
44
+ return true;
45
+ }
46
+
47
+ return false;
48
+ };
49
+
37
50
  export const isPunctuator = (token, punctuator) => {
38
51
  if (token.type !== 'Punctuator')
39
52
  return false;
@@ -113,3 +126,4 @@ export const quote = Punctuator(`'`);
113
126
 
114
127
  export const OK = true;
115
128
  export const NOT_OK = false;
129
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.39.2",
3
+ "version": "1.40.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",