flatlint 1.14.0 → 1.15.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.02, v1.15.0
2
+
3
+ feature:
4
+ - e018137 flatlint: replacer: simplify
5
+
1
6
  2025.01.01, v1.14.0
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -96,8 +96,8 @@ npm i flatlint
96
96
 
97
97
  It can look similar, but has a couple differences:
98
98
 
99
- - ✅it may not be valid **JavaScript**, it can be couple tokens that can be fixed;
100
- - ✅it counts each symbol as a token;
99
+ - ✅ it may not be valid **JavaScript**, it can be couple tokens that can be fixed;
100
+ - ✅ it counts each symbol as a token;
101
101
 
102
102
  ### `__a`
103
103
 
@@ -1,7 +1,7 @@
1
1
  import {Punctuator} from '#types';
2
2
  import {equal} from './equal.js';
3
3
 
4
- export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken}) => {
4
+ export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
5
5
  const n = tokens.length;
6
6
  const brace = Punctuator(']');
7
7
  let index = currentTokenIndex;
@@ -1,7 +1,7 @@
1
1
  import {Punctuator} from '#types';
2
2
  import {equal} from './equal.js';
3
3
 
4
- export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken}) => {
4
+ export const collectExpression = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
5
5
  const n = tokens.length;
6
6
  const closeBrace = Punctuator(')');
7
7
  const openBrace = Punctuator('(');
@@ -5,12 +5,10 @@ import {
5
5
  is,
6
6
  isTemplateArray,
7
7
  isTemplateExpression,
8
- Punctuator,
9
8
  } from '#types';
10
9
  import {collectArray} from '../compare/collect-array.js';
11
10
  import {collectExpression} from '../compare/collect-expression.js';
12
11
 
13
- const {isArray} = Array;
14
12
  const {entries} = Object;
15
13
 
16
14
  export const replace = (tokens, {fix, rule, plugin}) => {
@@ -87,39 +85,20 @@ function getValues(tokens, waysFrom) {
87
85
  const values = {};
88
86
 
89
87
  for (const [name, index] of entries(waysFrom)) {
90
- if (isTemplateArray(name)) {
91
- const endOfArray = collectArray({
88
+ let end = index;
89
+
90
+ if (isTemplateArray(name))
91
+ end = collectArray({
92
92
  currentTokenIndex: index,
93
93
  tokens,
94
- nextTemplateToken: Punctuator(';'),
95
94
  });
96
-
97
- if (index === endOfArray) {
98
- values[name] = tokens[index];
99
- continue;
100
- }
101
-
102
- values[name] = tokens.slice(index, endOfArray + 1);
103
- continue;
104
- }
105
-
106
- if (isTemplateExpression(name)) {
107
- const endOfArray = collectExpression({
95
+ else if (isTemplateExpression(name))
96
+ end = collectExpression({
108
97
  currentTokenIndex: index,
109
98
  tokens,
110
- nextTemplateToken: Punctuator(';'),
111
99
  });
112
-
113
- if (index === endOfArray) {
114
- values[name] = tokens[index];
115
- continue;
116
- }
117
-
118
- values[name] = tokens.slice(index, endOfArray + 1);
119
- continue;
120
- }
121
100
 
122
- values[name] = tokens[index];
101
+ values[name] = tokens.slice(index, end + 1);
123
102
  }
124
103
 
125
104
  return values;
@@ -127,13 +106,6 @@ function getValues(tokens, waysFrom) {
127
106
 
128
107
  function setValues({to, waysTo, values}) {
129
108
  for (const [name, index] of entries(waysTo)) {
130
- const current = values[name];
131
-
132
- if (!isArray(current)) {
133
- to[index] = values[name];
134
- continue;
135
- }
136
-
137
109
  to.splice(index, 1, ...values[name]);
138
110
  }
139
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",