flatlint 1.23.0 → 1.24.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.05, v1.24.0
2
+
3
+ feature:
4
+ - b6252d0 flatlint: path: getPrev -> getAllPrev
5
+
1
6
  2025.01.05, v1.23.0
2
7
 
3
8
  feature:
package/lib/flatlint.js CHANGED
@@ -2,6 +2,9 @@ import {loadPlugins} from '@putout/engine-loader';
2
2
  import {parse} from '#parser';
3
3
  import {run} from '#runner';
4
4
 
5
+ const getValue = (token) => token.value;
6
+ const print = (tokens) => tokens.map(getValue).join('');
7
+
5
8
  export function lint(source, overrides = {}) {
6
9
  const {fix = true, plugins: pluginNames = []} = overrides;
7
10
  const plugins = loadPlugins({
@@ -23,9 +26,3 @@ export function lint(source, overrides = {}) {
23
26
  places,
24
27
  ];
25
28
  }
26
-
27
- function print(tokens) {
28
- return tokens
29
- .map((token) => token.value)
30
- .join('');
31
- }
@@ -13,11 +13,10 @@ export const replace = () => ({
13
13
  });
14
14
 
15
15
  function check(vars, path) {
16
- let last;
17
-
18
- for (const token of path.getNext()) {
19
- last = token;
16
+ for (const token of path.getAllNext()) {
17
+ if (isPunctuator(token))
18
+ return false;
20
19
  }
21
20
 
22
- return !isPunctuator(last, ';');
21
+ return true;
23
22
  }
@@ -4,7 +4,7 @@ export const report = () => 'Remove useless coma';
4
4
 
5
5
  export const match = () => ({
6
6
  '__a(__args) {},': (vars, path) => {
7
- for (const token of path.getPrev()) {
7
+ for (const token of path.getAllPrev()) {
8
8
  if (isIdentifier(token, 'class'))
9
9
  return true;
10
10
  }
@@ -4,7 +4,7 @@ export const report = () => 'Remove useless semicolon';
4
4
 
5
5
  export const match = () => ({
6
6
  '__a: __expr;': (vars, path) => {
7
- for (const token of path.getPrev()) {
7
+ for (const token of path.getAllPrev()) {
8
8
  if (isIdentifier(token, 'interface'))
9
9
  return false;
10
10
  }
@@ -1,33 +1,59 @@
1
- import {isNewLine} from '#types';
1
+ import {isNewLine, isPunctuator} from '#types';
2
2
 
3
- export const createPath = ({tokens, start}) => ({
4
- getPrev: createGetPrev({
3
+ export const createPath = ({tokens, start, end}) => ({
4
+ getAllPrev: createGetAllPrev({
5
5
  tokens,
6
6
  start,
7
7
  }),
8
- getNext: createGetNext({
8
+ getAllNext: createGetAllNext({
9
9
  tokens,
10
- start,
10
+ end,
11
+ }),
12
+ isNextPunctuator: createIsNextPunctuator({
13
+ tokens,
14
+ end,
15
+ }),
16
+ isEndsWithPunctuator: createIsEndsWithPunctuator({
17
+ tokens,
18
+ end,
19
+ }),
20
+ isNext: createIsNext({
21
+ tokens,
22
+ end,
11
23
  }),
12
24
  });
13
25
 
14
- function createGetPrev({tokens, start}) {
15
- return function*() {
16
- for (let i = start; i >= 0; --i) {
17
- yield tokens[i];
18
- }
19
- };
20
- }
26
+ const createIsNextPunctuator = ({tokens, end}) => (punctuator) => {
27
+ const current = tokens[end];
28
+
29
+ if (!current)
30
+ return false;
31
+
32
+ return isPunctuator(current, punctuator);
33
+ };
34
+
35
+ const createIsEndsWithPunctuator = ({tokens, end}) => (punctuator) => {
36
+ const current = tokens[end - 1];
37
+ return isPunctuator(current, punctuator);
38
+ };
39
+
40
+ const createIsNext = ({tokens, end}) => () => {
41
+ return Boolean(tokens[end]);
42
+ };
43
+
44
+ const createGetAllPrev = ({tokens, start}) => function*() {
45
+ for (let i = start; i >= 0; --i) {
46
+ yield tokens[i];
47
+ }
48
+ };
21
49
 
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
- }
50
+ const createGetAllNext = ({tokens, end}) => function*() {
51
+ for (let i = end; i < tokens.length; ++i) {
52
+ const current = tokens[i];
53
+
54
+ if (isNewLine(current))
55
+ continue;
56
+
57
+ yield current;
58
+ }
59
+ };
@@ -136,6 +136,6 @@ function getCurrentValues({from, start, end, tokens}) {
136
136
  const current = tokens.slice(start, end);
137
137
 
138
138
  const waysFrom = findVarsWays(prepare(from));
139
+
139
140
  return getValues(current, waysFrom);
140
141
  }
141
-
@@ -15,11 +15,16 @@ 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 = (token, value) => {
18
+ export const isPunctuator = (token, punctuator) => {
19
19
  if (token.type !== 'Punctuator')
20
20
  return false;
21
21
 
22
- return !value || token.value === value;
22
+ if (!punctuator)
23
+ return true;
24
+
25
+ const punctuatorValue = punctuator.value || punctuator;
26
+
27
+ return token.value === punctuatorValue;
23
28
  };
24
29
 
25
30
  export const StringLiteral = (value) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",