flatlint 4.4.0 → 4.4.2

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
+ 2026.01.29, v4.4.2
2
+
3
+ feature:
4
+ - f83e19f flatlint: remove-useless-round-brace: ]): false positive
5
+
6
+ 2026.01.29, v4.4.1
7
+
8
+ feature:
9
+ - 8f021bd flatlint: parser: improve support of Templates
10
+
1
11
  2026.01.29, v4.4.0
2
12
 
3
13
  feature:
@@ -5,6 +5,7 @@ import {
5
5
  isNoSubstitutionTemplate,
6
6
  isStringLiteral,
7
7
  isWhiteSpace,
8
+ isTemplate,
8
9
  } from '#types';
9
10
  import {parseStringLiteral} from './string-literal.js';
10
11
 
@@ -62,14 +63,10 @@ function getTokensWithLocation(tokens) {
62
63
  const result = [];
63
64
 
64
65
  for (const token of tokens) {
65
- if (isNewLine(token))
66
- ++line;
67
-
68
- if (isMultilineComment(token))
69
- line += token.value.split('\n').length - 1;
70
-
71
- if (isNoSubstitutionTemplate(token))
72
- line += token.value.split('\n').length - 1;
66
+ line = maybeIncreateLine({
67
+ token,
68
+ line,
69
+ });
73
70
 
74
71
  result.push({
75
72
  ...token,
@@ -85,3 +82,21 @@ function getTokensWithLocation(tokens) {
85
82
 
86
83
  return result;
87
84
  }
85
+
86
+ function maybeIncreateLine({line, token}) {
87
+ if (isNewLine(token))
88
+ ++line;
89
+
90
+ if (isMultilineComment(token))
91
+ line += getNewlinesCount(token);
92
+
93
+ if (isNoSubstitutionTemplate(token))
94
+ line += getNewlinesCount(token);
95
+
96
+ if (isTemplate(token))
97
+ line += getNewlinesCount(token);
98
+
99
+ return line;
100
+ }
101
+
102
+ const getNewlinesCount = ({value}) => value.split('\n').length - 1;
@@ -24,8 +24,11 @@ export const match = () => ({
24
24
 
25
25
  return true;
26
26
  },
27
- '})': (vars, path) => isBracesBalanced(path),
28
- ')]': (vars, path) => !isBracesBalanced(path),
27
+ '})': (vars, path) => !isBracesBalanced(path),
28
+ ')]': (vars, path) => {
29
+ const a = isBracesBalanced(path);
30
+ return a < 0;
31
+ },
29
32
  });
30
33
 
31
34
  export const replace = () => ({
@@ -48,5 +51,5 @@ function isBracesBalanced(path) {
48
51
  --balance;
49
52
  }
50
53
 
51
- return !balance;
54
+ return balance;
52
55
  }
@@ -22,6 +22,7 @@ export const isTemplateMiddle = (a) => a?.type === 'TemplateMiddle';
22
22
  export const isNoSubstitutionTemplate = (a) => a?.type === 'NoSubstitutionTemplate';
23
23
  export const isTemplateHead = (a) => a?.type === 'TemplateHead';
24
24
  export const isTemplateTail = (a) => a?.type === 'TemplateTail';
25
+ export const isTemplate = (a) => isTemplateHead(a) || isTemplateTail(a);
25
26
  export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
26
27
  export const isIdentifier = (token, newToken) => {
27
28
  if (!token)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "4.4.0",
3
+ "version": "4.4.2",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",
@@ -9,33 +9,15 @@
9
9
  "./with-plugins": "./lib/with-plugins.js"
10
10
  },
11
11
  "imports": {
12
- "#test": {
13
- "default": "./lib/test/test.js"
14
- },
15
- "#types": {
16
- "default": "./lib/types/types.js"
17
- },
18
- "#parser": {
19
- "default": "./lib/parser/parser.js"
20
- },
21
- "#printer": {
22
- "default": "./lib/printer/printer.js"
23
- },
24
- "#traverser": {
25
- "default": "./lib/traverser/traverser.js"
26
- },
27
- "#compare": {
28
- "default": "./lib/compare/compare.js"
29
- },
30
- "#compare/values": {
31
- "default": "./lib/compare/values.js"
32
- },
33
- "#runner": {
34
- "default": "./lib/runner/runner.js"
35
- },
36
- "#flatlint": {
37
- "default": "./lib/flatlint.js"
38
- }
12
+ "#test": "./lib/test/test.js",
13
+ "#types": "./lib/types/types.js",
14
+ "#parser": "./lib/parser/parser.js",
15
+ "#printer": "./lib/printer/printer.js",
16
+ "#traverser": "./lib/traverser/traverser.js",
17
+ "#compare": "./lib/compare/compare.js",
18
+ "#compare/values": "./lib/compare/values.js",
19
+ "#runner": "./lib/runner/runner.js",
20
+ "#flatlint": "./lib/flatlint.js"
39
21
  },
40
22
  "scripts": {
41
23
  "lint": "madrun lint",