flatlint 1.0.2 → 1.2.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,13 @@
1
+ 2024.12.28, v1.2.0
2
+
3
+ feature:
4
+ - 93b1535 flatlint: add-missing-round-braces: add
5
+
6
+ 2024.12.28, v1.1.0
7
+
8
+ feature:
9
+ - 8a7c88c flatlint: convert-comma-to-semicolon
10
+
1
11
  2024.12.28, v1.0.2
2
12
 
3
13
  fix:
package/README.md CHANGED
@@ -8,6 +8,37 @@ Token-based JavaScript linter that fixes Syntax Errors
8
8
  npm i flatlint
9
9
  ```
10
10
 
11
+ ## Available fixes
12
+
13
+ <details><summary>Assignment without parentheses after <code>&&</code></summary>
14
+
15
+ ```diff
16
+ -a && b = c;
17
+ +a && (b = c);
18
+ ```
19
+
20
+ </details>
21
+
22
+ <details><summary>Convert <code>,</code> to <code>;</code> at the end of statement</summary>
23
+
24
+ ```diff
25
+ -const a = 5,
26
+ +const a = 5;
27
+ ```
28
+
29
+ </details>
30
+
31
+ <details><summary>forgotten round braces in if statement</summary>¬
32
+
33
+ ```diff¬
34
+ -if a > 5 {
35
+ +if (a > 5) {
36
+ alert();
37
+ }
38
+ ```
39
+
40
+ </details>
41
+
11
42
  ## API
12
43
 
13
44
  ```js
@@ -2,9 +2,7 @@ import {prepare} from '../tokenizer/index.js';
2
2
  import {
3
3
  isId,
4
4
  isIdentifier,
5
- isNewLine,
6
5
  isPunctuator,
7
- isWhiteSpace,
8
6
  } from './types.js';
9
7
 
10
8
  export const compare = (source, template) => {
@@ -17,31 +15,11 @@ export const compare = (source, template) => {
17
15
  let end = 0;
18
16
 
19
17
  for (let index = 0; index < n; index++) {
20
- let tokenDelta = 0;
21
- let templateDelta = 0;
22
-
23
18
  for (let templateIndex = 0; templateIndex < templateTokensLength; templateIndex++) {
24
- const currentTokenIndex = index + templateIndex - tokenDelta;
25
-
26
- if (currentTokenIndex === n + 1)
27
- break;
28
-
29
- const templateToken = templateTokens[templateIndex - templateDelta];
19
+ const currentTokenIndex = index + templateIndex;
20
+ const templateToken = templateTokens[templateIndex];
30
21
  const currentToken = tokens[currentTokenIndex];
31
22
 
32
- if (isWhiteSpace(currentToken)) {
33
- ++templateDelta;
34
- continue;
35
- }
36
-
37
- if (isWhiteSpace(templateToken)) {
38
- ++tokenDelta;
39
- continue;
40
- }
41
-
42
- if (isNewLine(currentToken))
43
- continue;
44
-
45
23
  if (!compareAll(currentToken, templateToken)) {
46
24
  isEqual = false;
47
25
  break;
@@ -49,7 +27,7 @@ export const compare = (source, template) => {
49
27
 
50
28
  isEqual = true;
51
29
  start = index;
52
- end = currentTokenIndex + tokenDelta + templateDelta;
30
+ end = currentTokenIndex;
53
31
  }
54
32
 
55
33
  if (isEqual)
@@ -0,0 +1,9 @@
1
+ export function report() {
2
+ return 'Add missing round braces';
3
+ }
4
+
5
+ export function replace() {
6
+ return {
7
+ 'if __a > __b': 'if (__a > __b)',
8
+ };
9
+ }
@@ -0,0 +1,9 @@
1
+ export function report() {
2
+ return 'Use semicolon instead of trailing comma';
3
+ }
4
+
5
+ export function replace() {
6
+ return {
7
+ 'const __a = __b,': 'const __a = __b;',
8
+ };
9
+ }
@@ -1,9 +1,9 @@
1
+ export function report() {
2
+ return `Wrap the assignment in parentheses after '&&'`;
3
+ }
4
+
1
5
  export function replace() {
2
6
  return {
3
7
  '__a && __b = __c': '__a && (__b = __c)',
4
8
  };
5
9
  }
6
-
7
- export function report() {
8
- return `Wrap the assignment in parentheses after '&&'`;
9
- }
@@ -20,10 +20,8 @@ function getTokensWithLocation(tokens) {
20
20
  const result = [];
21
21
 
22
22
  for (const token of tokens) {
23
- if (isNewLine(token)) {
23
+ if (isNewLine(token))
24
24
  ++line;
25
- continue;
26
- }
27
25
 
28
26
  result.push({
29
27
  ...token,
@@ -32,6 +30,9 @@ function getTokensWithLocation(tokens) {
32
30
  });
33
31
 
34
32
  column += token.value.length;
33
+
34
+ if (isNewLine(token))
35
+ column = 1;
35
36
  }
36
37
 
37
38
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",
@@ -76,6 +76,7 @@
76
76
  "yargs-parser": "^21.0.0"
77
77
  },
78
78
  "devDependencies": {
79
+ "@putout/eslint-flat": "^2.0.0",
79
80
  "@putout/formatter-json": "^2.0.0",
80
81
  "@putout/test": "^11.1.0",
81
82
  "c8": "^10.1.2",