flatlint 1.24.1 → 1.25.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,8 @@
1
+ 2025.01.06, v1.25.0
2
+
3
+ feature:
4
+ - 9016c56 flatlint: add-missing-round-brace: improve
5
+
1
6
  2025.01.05, v1.24.1
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -37,13 +37,16 @@ npm i flatlint
37
37
 
38
38
  </details>
39
39
 
40
- <details><summary>add missing round braces in if statement</summary>
40
+ <details><summary>add missing round brace</summary>
41
41
 
42
42
  ```diff
43
43
  -if a > 5 {
44
44
  +if (a > 5) {
45
45
  alert();
46
46
  }
47
+
48
+ -a('hello'
49
+ +a('hello');
47
50
  ```
48
51
 
49
52
  </details>
@@ -29,7 +29,8 @@ export const compare = (source, template) => {
29
29
 
30
30
  for (let index = 0; index < n; index++) {
31
31
  for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
32
- const currentTokenIndex = index + templateIndex - skip;
32
+ let currentTokenIndex = index + templateIndex - skip;
33
+
33
34
  const templateToken = templateTokens[templateIndex];
34
35
  const currentToken = tokens[currentTokenIndex];
35
36
 
@@ -43,6 +44,8 @@ export const compare = (source, template) => {
43
44
 
44
45
  if (!ok) {
45
46
  ++skip;
47
+ } else if (templateIndex === templateTokensLength - 1) {
48
+ currentTokenIndex = end;
46
49
  } else {
47
50
  delta = end - currentTokenIndex;
48
51
  index = end - templateIndex;
@@ -1,5 +1,12 @@
1
+ import {closeRoundBrace} from '#types';
2
+
1
3
  export const report = () => 'Add missing round braces';
2
4
 
5
+ export const match = () => ({
6
+ '__a(__args': (vars, path) => !path.isNextPunctuator(closeRoundBrace),
7
+ });
8
+
3
9
  export const replace = () => ({
4
10
  'if __a > __b': 'if (__a > __b)',
11
+ '__a(__args': '__a(__args)',
5
12
  });
@@ -17,10 +17,6 @@ export const createPath = ({tokens, start, end}) => ({
17
17
  tokens,
18
18
  end,
19
19
  }),
20
- isNext: createIsNext({
21
- tokens,
22
- end,
23
- }),
24
20
  });
25
21
 
26
22
  const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
@@ -37,10 +33,6 @@ const createIsEndsWithPunctuator = ({tokens, end}) => (punctuator) => {
37
33
  return isPunctuator(current, punctuator);
38
34
  };
39
35
 
40
- const createIsNext = ({tokens, end}) => () => {
41
- return Boolean(tokens[end]);
42
- };
43
-
44
36
  const createGetAllPrev = ({tokens, start}) => function*() {
45
37
  for (let i = start; i >= 0; --i) {
46
38
  yield tokens[i];
@@ -22,7 +22,7 @@ export const isPunctuator = (token, punctuator) => {
22
22
  if (!punctuator)
23
23
  return true;
24
24
 
25
- const punctuatorValue = punctuator.value || punctuator;
25
+ const punctuatorValue = punctuator.value;
26
26
 
27
27
  return token.value === punctuatorValue;
28
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.24.1",
3
+ "version": "1.25.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",