flatlint 1.14.0 → 1.16.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
+ 2025.01.02, v1.16.0
2
+
3
+ feature:
4
+ - bad8496 flatlint: remove-useless-squire-brace: add
5
+
6
+ 2025.01.02, v1.15.0
7
+
8
+ feature:
9
+ - e018137 flatlint: replacer: simplify
10
+
1
11
  2025.01.01, v1.14.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -78,6 +78,15 @@ npm i flatlint
78
78
 
79
79
  </details>
80
80
 
81
+ <details><summary>remove useless square brace</summary>
82
+
83
+ ```diff
84
+ -const a = [1, 2, 3]];
85
+ +const a = [1, 2, 3];
86
+ ```
87
+
88
+ </details>
89
+
81
90
  <details><summary>add missing quote</summary>
82
91
 
83
92
  ```diff
@@ -96,8 +105,8 @@ npm i flatlint
96
105
 
97
106
  It can look similar, but has a couple differences:
98
107
 
99
- - ✅it may not be valid **JavaScript**, it can be couple tokens that can be fixed;
100
- - ✅it counts each symbol as a token;
108
+ - ✅ it may not be valid **JavaScript**, it can be couple tokens that can be fixed;
109
+ - ✅ it counts each symbol as a token;
101
110
 
102
111
  ### `__a`
103
112
 
@@ -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('(');
@@ -1,5 +1,5 @@
1
1
  export function report() {
2
- return 'Add missing squire brace';
2
+ return 'Add missing square brace';
3
3
  }
4
4
 
5
5
  export function replace() {
@@ -0,0 +1,5 @@
1
+ export const report = () => 'Remove useless square brace';
2
+
3
+ export const replace = () => ({
4
+ 'const __a = [__array]];': 'const __a = [__array];',
5
+ });
@@ -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.16.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",