flatlint 1.1.0 → 1.2.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
+ 2024.12.29, v1.2.1
2
+
3
+ feature:
4
+ - 9dbfad1 flatlint: plugins: add add-missing-round-braces, convert-comma-to-semicolon
5
+
6
+ 2024.12.28, v1.2.0
7
+
8
+ feature:
9
+ - 93b1535 flatlint: add-missing-round-braces: add
10
+
1
11
  2024.12.28, v1.1.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -28,6 +28,17 @@ npm i flatlint
28
28
 
29
29
  </details>
30
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
+
31
42
  ## API
32
43
 
33
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
+ }
@@ -7,4 +7,3 @@ export function replace() {
7
7
  'const __a = __b,': 'const __a = __b;',
8
8
  };
9
9
  }
10
-
package/lib/plugins.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import * as wrapAssignmentInParens from './plugins/wrap-assignment-in-parens/index.js';
2
+ import * as addMissingRoundBraces from './plugins/add-missing-round-braces/index.js';
3
+ import * as convertCommaToSemicolon from './plugins/convert-comma-to-semicolon/index.js';
2
4
 
3
5
  export const plugins = [
4
6
  ['wrap-assignment-in-parens', wrapAssignmentInParens],
7
+ ['add-missing-round-braces', addMissingRoundBraces],
8
+ ['convert-comma-to-semicolon', convertCommaToSemicolon],
5
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.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",
@@ -61,33 +61,20 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@putout/engine-loader": "^15.0.1",
64
- "@putout/formatter-dump": "^5.0.0",
65
- "all-object-keys": "^2.0.0",
66
- "enquirer": "^2.3.6",
67
- "find-up": "^7.0.0",
68
- "jessy": "^3.0.0",
69
64
  "js-tokens": "^9.0.1",
70
- "mapsome": "^1.0.0",
71
- "montag": "^1.0.0",
72
- "once": "^1.4.0",
73
- "putout": "^37.0.0",
74
- "try-catch": "^3.0.0",
75
- "try-to-catch": "^3.0.0",
76
- "yargs-parser": "^21.0.0"
65
+ "putout": "^37.0.0"
77
66
  },
78
67
  "devDependencies": {
68
+ "montag": "^1.0.0",
79
69
  "@putout/eslint-flat": "^2.0.0",
80
70
  "@putout/formatter-json": "^2.0.0",
81
71
  "@putout/test": "^11.1.0",
82
72
  "c8": "^10.1.2",
83
- "escover": "^4.0.0",
84
73
  "eslint": "^9.7.0",
85
74
  "eslint-plugin-putout": "^23.1.0",
86
75
  "madrun": "^10.2.2",
87
- "mock-import": "^4.0.2",
88
76
  "mock-require": "^3.0.3",
89
77
  "nodemon": "^3.0.1",
90
- "runsome": "^1.0.0",
91
78
  "supertape": "^10.0.0"
92
79
  },
93
80
  "publishConfig": {