flatlint 1.21.2 → 1.22.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.04, v1.22.0
2
+
3
+ feature:
4
+ - 807d059 flatlint: add-missing-semicolon: add
5
+
1
6
  2025.01.03, v1.21.2
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -132,6 +132,15 @@ const a = class {
132
132
 
133
133
  </details>
134
134
 
135
+ <details><summary>add missing semicolon</summary>
136
+
137
+ ```diff
138
+ -const a = 5
139
+ +const a = 5;
140
+ ```
141
+
142
+ </details>
143
+
135
144
  ## Template literals
136
145
 
137
146
  **FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
@@ -18,12 +18,6 @@ export const collectArgs = ({currentTokenIndex, tokens, nextTemplateToken = clos
18
18
 
19
19
  if (equal(token, closeRoundBrace))
20
20
  break;
21
-
22
- if (equal(token, nextTemplateToken))
23
- break;
24
-
25
- if (equal(token, closeSquareBrace))
26
- break;
27
21
  }
28
22
 
29
23
  return [
@@ -30,12 +30,6 @@ export const compare = (source, template) => {
30
30
  for (let index = 0; index < n; index++) {
31
31
  for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
32
32
  const currentTokenIndex = index + templateIndex - skip;
33
-
34
- if (currentTokenIndex > n) {
35
- isEqual = false;
36
- break;
37
- }
38
-
39
33
  const templateToken = templateTokens[templateIndex];
40
34
  const currentToken = tokens[currentTokenIndex];
41
35
 
@@ -61,6 +55,13 @@ export const compare = (source, template) => {
61
55
  nextTemplateToken: templateTokens[templateIndex + 1],
62
56
  });
63
57
 
58
+ debugger;
59
+
60
+ if (n === indexOfExpressionEnd) {
61
+ end = indexOfExpressionEnd;
62
+ continue;
63
+ }
64
+
64
65
  delta = indexOfExpressionEnd - currentTokenIndex;
65
66
  index = indexOfExpressionEnd - templateIndex;
66
67
  } else if (isTemplateArrayToken(templateToken)) {
@@ -110,3 +111,4 @@ function compareAll(a, b) {
110
111
 
111
112
  return false;
112
113
  }
114
+
@@ -1,9 +1,5 @@
1
- export function report() {
2
- return 'Add missing round braces';
3
- }
1
+ export const report = () => 'Add missing round braces';
4
2
 
5
- export function replace() {
6
- return {
7
- 'if __a > __b': 'if (__a > __b)',
8
- };
9
- }
3
+ export const replace = () => ({
4
+ 'if __a > __b': 'if (__a > __b)',
5
+ });
@@ -0,0 +1,19 @@
1
+ import {isNewLine, isPunctuator} from '#types';
2
+
3
+ export const report = () => 'Add missing semicolon';
4
+
5
+ export const match = () => ({
6
+ 'const __a = __expr': (vars, path) => {
7
+ let last;
8
+
9
+ for (const token of path.getNext()) {
10
+ last = token;
11
+ }
12
+
13
+ return !isPunctuator(last, ';');
14
+ },
15
+ });
16
+
17
+ export const replace = () => ({
18
+ 'const __a = __expr': 'const __a = __expr;',
19
+ });
@@ -1,9 +1,5 @@
1
- export function report() {
2
- return 'Add missing square brace';
3
- }
1
+ export const report = () => 'Add missing square brace';
4
2
 
5
- export function replace() {
6
- return {
7
- '[__array;': '[__array];',
8
- };
9
- }
3
+ export const replace = () => ({
4
+ '[__array;': '[__array];',
5
+ });
@@ -5,7 +5,7 @@ export const report = () => 'Remove useless semicolon';
5
5
  export const match = () => ({
6
6
  '__a: __expr;': (vars, path) => {
7
7
  for (const token of path.getPrev()) {
8
- if (isIdentifier(token) && token.value === 'interface')
8
+ if (isIdentifier(token, 'interface'))
9
9
  return false;
10
10
  }
11
11
 
@@ -2,8 +2,6 @@ export function report() {
2
2
  return `Wrap the assignment in parentheses after '&&'`;
3
3
  }
4
4
 
5
- export function replace() {
6
- return {
7
- '__a && __b = __c': '__a && (__b = __c)',
8
- };
9
- }
5
+ export const replace = () => ({
6
+ '__a && __b = __c': '__a && (__b = __c)',
7
+ });
@@ -1,8 +1,14 @@
1
+ import {isNewLine} from '#types';
2
+
1
3
  export const createPath = ({tokens, start}) => ({
2
4
  getPrev: createGetPrev({
3
5
  tokens,
4
6
  start,
5
7
  }),
8
+ getNext: createGetNext({
9
+ tokens,
10
+ start,
11
+ }),
6
12
  });
7
13
 
8
14
  function createGetPrev({tokens, start}) {
@@ -12,3 +18,16 @@ function createGetPrev({tokens, start}) {
12
18
  }
13
19
  };
14
20
  }
21
+
22
+ function createGetNext({tokens, start}) {
23
+ return function*() {
24
+ for (let i = start; i < tokens.length; ++i) {
25
+ const current = tokens[i];
26
+
27
+ if (isNewLine(current))
28
+ continue;
29
+
30
+ yield current;
31
+ }
32
+ };
33
+ }
@@ -26,6 +26,7 @@ export const match = (tokens, {plugin}) => {
26
26
  const waysFrom = findVarsWays(prepare(from));
27
27
  const values = getValues(current, waysFrom);
28
28
 
29
+ debugger;
29
30
  result = fn(values, createPath({
30
31
  tokens,
31
32
  start,
@@ -15,7 +15,12 @@ export const isStringLiteral = ({type}) => type === 'StringLiteral';
15
15
  export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
16
16
  export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
17
17
  export const notWhiteSpace = (a) => !isWhiteSpace(a);
18
- export const isPunctuator = ({type}) => type === 'Punctuator';
18
+ export const isPunctuator = (token, value) => {
19
+ if (token.type !== 'Punctuator')
20
+ return false;
21
+
22
+ return !value || token.value === value;
23
+ };
19
24
 
20
25
  export const StringLiteral = (value) => ({
21
26
  type: 'StringLiteral',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.21.2",
3
+ "version": "1.22.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",