flatlint 1.17.0 → 1.19.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.19.0
2
+
3
+ feature:
4
+ - f98b1e2 flatint: remove-useless-coma: add
5
+
6
+ 2025.01.02, v1.18.0
7
+
8
+ feature:
9
+ - 99d6dbf flatlint: remove-useless-arrow: add
10
+
1
11
  2025.01.02, v1.17.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -110,6 +110,28 @@ const a = {
110
110
 
111
111
  </details>
112
112
 
113
+ <details><summary>Remove useless arrow</summary>
114
+
115
+ ```diff
116
+ -function parse(source) => {
117
+ +function parse(source) {
118
+ return source;
119
+ }
120
+ ```
121
+
122
+ </details>
123
+
124
+ <details><summary>Remove useless coma</summary>
125
+
126
+ ```diff
127
+ const a = class {
128
+ - b() {},
129
+ + b() {}
130
+ }
131
+ ```
132
+
133
+ </details>
134
+
113
135
  ## Template literals
114
136
 
115
137
  **FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
@@ -1,4 +1,7 @@
1
- import {Punctuator} from '#types';
1
+ import {
2
+ CloseRoundBrace,
3
+ Punctuator,
4
+ } from '#types';
2
5
  import {equal} from './equal.js';
3
6
 
4
7
  export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Punctuator(';')}) => {
@@ -9,6 +12,9 @@ export const collectArray = ({currentTokenIndex, tokens, nextTemplateToken = Pun
9
12
  for (; index < n; index++) {
10
13
  const token = tokens[index];
11
14
 
15
+ if (equal(token, CloseRoundBrace))
16
+ break;
17
+
12
18
  if (equal(token, nextTemplateToken))
13
19
  break;
14
20
 
@@ -1,9 +1,16 @@
1
- export function report() {
2
- return 'Use semicolon instead of trailing comma';
3
- }
1
+ import {isIdentifier} from '#types';
4
2
 
5
- export function replace() {
6
- return {
7
- 'const __a = __b,': 'const __a = __b;',
8
- };
9
- }
3
+ export const report = () => 'Use semicolon instead of trailing comma';
4
+ export const match = () => ({
5
+ '__a: __expr;': (vars, path) => {
6
+ for (const token of path.getPrev()) {
7
+ if (isIdentifier(token, 'interface'))
8
+ return false;
9
+ }
10
+
11
+ return true;
12
+ },
13
+ });
14
+ export const replace = () => ({
15
+ 'const __a = __b,': 'const __a = __b;',
16
+ });
@@ -0,0 +1,5 @@
1
+ export const report = () => 'Remove useless arrow';
2
+
3
+ export const replace = () => ({
4
+ 'function __a(__array) => {': 'function __a(__array) {',
5
+ });
@@ -0,0 +1,18 @@
1
+ import {isIdentifier} from '#types';
2
+
3
+ export const report = () => 'Remove useless coma';
4
+
5
+ export const match = () => ({
6
+ '__a() {},': (vars, path) => {
7
+ for (const token of path.getPrev()) {
8
+ if (isIdentifier(token, 'class'))
9
+ return true;
10
+ }
11
+
12
+ return false;
13
+ },
14
+ });
15
+
16
+ export const replace = () => ({
17
+ '__a() {},': '__a() {}',
18
+ });
@@ -1,7 +1,16 @@
1
1
  const isString = (a) => typeof a === 'string';
2
2
 
3
3
  export const isWhiteSpace = ({type}) => type === 'WhiteSpace';
4
- export const isIdentifier = ({type}) => type === 'IdentifierName';
4
+ export const isIdentifier = (token, value = token.value) => {
5
+ const {type} = token;
6
+ const is = type === 'IdentifierName';
7
+
8
+ if (!is)
9
+ return false;
10
+
11
+ return value === token.value;
12
+ };
13
+
5
14
  export const isStringLiteral = ({type}) => type === 'StringLiteral';
6
15
  export const isNumericLiteral = ({type}) => type === 'NumericLiteral';
7
16
  export const isNewLine = ({type}) => type === 'LineTerminatorSequence';
@@ -53,3 +62,6 @@ export const isTemplateArray = (a) => a === ARRAY;
53
62
  export const isTemplateExpression = (a) => a === EXPR;
54
63
  export const isTemplateArrayToken = (a) => isIdentifier(a) && isTemplateArray(a.value);
55
64
  export const isTemplateExpressionToken = (a) => isIdentifier(a) && isTemplateExpression(a.value);
65
+
66
+ export const OpenRoundBrace = Punctuator('(');
67
+ export const CloseRoundBrace = Punctuator(')');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.17.0",
3
+ "version": "1.19.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",