flatlint 1.18.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,8 @@
1
+ 2025.01.02, v1.19.0
2
+
3
+ feature:
4
+ - f98b1e2 flatint: remove-useless-coma: add
5
+
1
6
  2025.01.02, v1.18.0
2
7
 
3
8
  feature:
package/README.md CHANGED
@@ -121,6 +121,17 @@ const a = {
121
121
 
122
122
  </details>
123
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
+
124
135
  ## Template literals
125
136
 
126
137
  **FlatLint** uses language similar to 🐊[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript).
@@ -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,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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flatlint",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "JavaScript tokens-based linter",
5
5
  "main": "lib/flatlint.js",
6
6
  "type": "module",