flatlint 1.90.1 → 1.91.1

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.31, v1.91.1
2
+
3
+ feature:
4
+ - c79d232 flatlint: remove-useless-round-brace: improve
5
+
6
+ 2025.01.31, v1.91.0
7
+
8
+ feature:
9
+ - 9485514 flatlint: add-missing-assign: isDeclarationKeyword
10
+
1
11
  2025.01.31, v1.90.1
2
12
 
3
13
  feature:
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  assign,
3
+ isDeclarationKeyword,
3
4
  isKeyword,
4
- isOneOfKeywords,
5
5
  isOneOfPunctuators,
6
6
  semicolon,
7
7
  } from '#types';
@@ -9,13 +9,13 @@ import {
9
9
  export const report = () => 'Add missing assign';
10
10
 
11
11
  export const match = () => ({
12
- '__x __a __expr': ({__expr, __x}, path) => {
12
+ '__x __a __expr': ({__expr, __x}) => {
13
13
  const [first] = __expr;
14
14
 
15
15
  if (isKeyword(first))
16
16
  return false;
17
17
 
18
- if (!isOneOfKeywords(__x, ['const', 'let', 'var']))
18
+ if (!isDeclarationKeyword(__x))
19
19
  return false;
20
20
 
21
21
  return !isOneOfPunctuators(assign, __expr);
@@ -1,5 +1,4 @@
1
1
  import {
2
- assign,
3
2
  hasRoundBraces,
4
3
  isBalancedRoundBraces,
5
4
  isPunctuator,
@@ -17,21 +16,12 @@ export const match = () => ({
17
16
  },
18
17
 
19
18
  '__a);': (vars, path) => {
20
- let result = false;
21
-
22
19
  for (const current of path.getAllPrev()) {
23
- if (isPunctuator(current, openRoundBrace)) {
24
- result = false;
25
- break;
26
- }
27
-
28
- if (isPunctuator(current, assign)) {
29
- result = true;
30
- break;
31
- }
20
+ if (isPunctuator(current, openRoundBrace))
21
+ return false;
32
22
  }
33
23
 
34
- return result;
24
+ return true;
35
25
  },
36
26
  });
37
27
 
@@ -40,4 +30,3 @@ export const replace = () => ({
40
30
  'from "__b")': 'from "__b"',
41
31
  '__a);': '__a;',
42
32
  });
43
-
@@ -10,7 +10,8 @@ import {createPath} from './path.js';
10
10
 
11
11
  const returns = (a) => () => a;
12
12
  const {entries} = Object;
13
- const log = debug('flatlint');
13
+ const logCompare = debug('flatlint:compare');
14
+ const logFix = debug('flatlint:fix');
14
15
 
15
16
  export const replace = (tokens, {fix, rule, plugin}) => {
16
17
  const places = [];
@@ -22,7 +23,7 @@ export const replace = (tokens, {fix, rule, plugin}) => {
22
23
  let index = 0;
23
24
 
24
25
  while (index < tokens.length - 1) {
25
- log(`compare: ${rule}: ${from} -> ${to}`);
26
+ logCompare(`${rule}: ${from} -> ${to}`);
26
27
  const [ok, start, end] = compare(tokens, from, {
27
28
  index,
28
29
  });
@@ -53,7 +54,7 @@ export const replace = (tokens, {fix, rule, plugin}) => {
53
54
  }
54
55
 
55
56
  if (fix) {
56
- log(`fix: ${rule}: ${from} -> ${to}`);
57
+ logFix(`${rule}: ${from} -> ${to}`);
57
58
 
58
59
  const preparedTo = prepare(to);
59
60
  const waysTo = findVarsWays(preparedTo);
@@ -39,6 +39,15 @@ export const isKeyword = (token, name) => {
39
39
  return isIdentifier(token, name);
40
40
  };
41
41
 
42
+ export const isDeclarationKeyword = (token, name) => {
43
+ const {value} = token;
44
+
45
+ if (!keyword.isDeclarationKeyword(value))
46
+ return false;
47
+
48
+ return isIdentifier(token, name);
49
+ };
50
+
42
51
  export const isOneOfPunctuators = (token, punctuators) => {
43
52
  for (const punctuator of punctuators) {
44
53
  if (isPunctuator(token, punctuator))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.90.1",
3
+ "version": "1.91.1",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",