2.11.0 • Published 3 months ago

flatlint v2.11.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

FlatLintLicense NPM version Build Status Coverage Status

Token-based JavaScript linter that fixes Syntax Errors

Install

npm i flatlint

Available fixes

-import {readFile}, fs from 'node:fs';
+import fs, {readFile} from 'node:fs';
-a && b = c;
+a && (b = c);
-const a = 5,
+const a = 5;

function x() {
-   return m,
+   return m;
}

-import a from 'a',
+import a from 'a';

-const a = 3,
+const a = 3;
module.exports = 2;
-console.log(a, b):
+console.log(a, b);
-const a = from 'a';
+const a = require('a');
-function a({b, c) {}
-function a({b, c}) {}

-const {a = b;
+const {a} = b;
-if a > 5 {
+if (a > 5) {
    alert();
}

-if (a.b() {
+if (a.b()) {
}

-a('hello'
+a('hello');

const m = {
-    z: z('hello'
+    z: z('hello')
}

-{hello} = world;
+({hello} = world);

-assign(oldPath, currentPath;
+assign(oldPath, currentPath);
-const a 5;
+const a = 5;

-module.exports {};
+module.exports = {};
import {
-   a
+   a,
    b,
} from 'c';

t.transform('declare-imports-first', {
-   'declare-imports-first': declareImportsFirst
+   'declare-imports-first': declareImportsFirst,
    'convert-esm-to-commonjs': convertEsmToCommonJs,
});
-const a = (b, c) {};
+const a = (b, c) => {};
-export x = 5;
+export const x = 5;
-const a = ['hello', 'world';
+const a = ['hello', 'world'];
-const a = 5);
+const a = 5;

-import a from 'a');
+import a from 'a';

if (a) {
-})
+}
-const a = [1, 2, 3]];
+const a = [1, 2, 3];
const a = {
-    b: 'hello';
+    b: 'hello',
}

const b = [
    1,
-   2;
+   2,
    3,
]
function x() {
    return m;
-},
+}

-const expected = [],
+const expected = [];
t.equal(expected, []);
-fn([].);
+fn([].);
-const {¬
-····is,¬
-····sArgsStr,¬
-····isTypeParamsStr,¬
-} = require('./is');¬
+const {
+    is,
+    isArgsStr,
+    isTypeParamsStr,
+} = require('./is');
-const a = 'hello
+const a = 'hello'

-fn('hello);
+fn('hello');
-function parse(source) => {
+function parse(source) {
    return source;
}
const a = class {
-    b() {},
+    b() {}
}
-const a = 5
+const a = 5;

Template literals

FlatLint uses language similar to 🐊PutoutScript.

It can look similar, but has a couple differences:

  • ✅ it may not be valid JavaScript, it can be couple tokens that can be fixed;
  • ✅ it counts each symbol as a token;

__a

From __a to __z is usually identifiers, but can also be strings if used with quotes '__a' they can be single or double, it can be only one quote '__a - this is valid, since FlatLint is tokens based.

__array

Collects everything that looks like array elements, it can start from squire brace [__array;, but that's not important to end with it, since it used to fix error patterns.

__args

Collects arguments of function when exists.

__expr

Collects everything that looks like expression.

API

import {lint, plugins} from 'flatlint/with-plugins';

const [code] = flatlint(`a && b = c`, {
    plugins,
});

// returns
`
a && (b = c);
`;

Without fix:

import {lint, plugins} from 'flatlint/with-plugins';

const [, places] = flatlint(`a && b = c`, {
    fix: false,
    plugins,
});

// returns
[{
    column: 1,
    line: 1,
    message: `Wrap the assignment in parentheses after '&&'`,
    rule: 'wrap-assignment-in-parens',
}];

When you want to use custom plugins:

import {lint} from 'flatlint';

const [code] = lint(`a && b = c`, {
    startLine: 1,
    plugins: [
        ['wrap-assignment-in-parens', {
            report: () => `Wrap the assignment in parentheses after '&&'`,
            replace: () => ({
                '__a && __b = __c': '__a && (__b = __c)',
            }),
        }],
    ],
});

License

MIT

2.11.0

3 months ago

2.8.0

3 months ago

2.10.0

3 months ago

2.7.0

3 months ago

2.6.0

3 months ago

2.5.0

3 months ago

2.5.1

3 months ago

2.9.0

3 months ago

2.4.0

3 months ago

2.3.0

3 months ago

2.3.2

3 months ago

2.3.1

3 months ago

2.3.4

3 months ago

2.3.3

3 months ago

2.3.5

3 months ago

2.2.0

3 months ago

2.1.2

4 months ago

2.1.1

4 months ago

2.1.4

4 months ago

2.1.3

4 months ago

2.1.6

4 months ago

2.1.5

4 months ago

2.1.7

4 months ago

2.1.0

4 months ago

2.0.3

4 months ago

2.0.2

4 months ago

2.0.5

4 months ago

2.0.4

4 months ago

2.0.7

4 months ago

2.0.6

4 months ago

2.0.9

4 months ago

2.0.8

4 months ago

2.0.10

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.115.0

4 months ago

1.114.0

4 months ago

1.116.0

4 months ago

1.111.0

4 months ago

1.113.0

4 months ago

1.112.0

4 months ago

1.110.0

4 months ago

1.109.0

4 months ago

1.108.0

4 months ago

1.107.0

4 months ago

1.103.0

4 months ago

1.106.0

4 months ago

1.106.1

4 months ago

1.102.0

4 months ago

1.101.0

4 months ago

1.105.1

4 months ago

1.105.0

4 months ago

1.101.1

4 months ago

1.99.0

4 months ago

1.100.0

4 months ago

1.104.0

4 months ago

1.98.1

4 months ago

1.98.0

4 months ago

1.97.1

4 months ago

1.97.0

4 months ago

1.98.2

4 months ago

1.94.0

5 months ago

1.96.0

5 months ago

1.95.0

5 months ago

1.79.0

5 months ago

1.90.1

5 months ago

1.90.0

5 months ago

1.82.0

5 months ago

1.86.0

5 months ago

1.67.0

5 months ago

1.70.0

5 months ago

1.74.0

5 months ago

1.93.1

5 months ago

1.93.0

5 months ago

1.83.0

5 months ago

1.87.0

5 months ago

1.68.0

5 months ago

1.71.0

5 months ago

1.75.0

5 months ago

1.92.0

5 months ago

1.80.0

5 months ago

1.80.1

5 months ago

1.84.0

5 months ago

1.89.0

5 months ago

1.88.0

5 months ago

1.69.0

5 months ago

1.72.0

5 months ago

1.76.0

5 months ago

1.78.0

5 months ago

1.91.1

5 months ago

1.91.0

5 months ago

1.81.0

5 months ago

1.85.0

5 months ago

1.73.0

5 months ago

1.77.0

5 months ago

1.56.0

5 months ago

1.58.1

5 months ago

1.58.0

5 months ago

1.61.0

5 months ago

1.63.0

5 months ago

1.65.0

5 months ago

1.53.0

5 months ago

1.55.0

5 months ago

1.57.0

5 months ago

1.59.0

5 months ago

1.60.0

5 months ago

1.62.0

5 months ago

1.60.2

5 months ago

1.60.1

5 months ago

1.64.0

5 months ago

1.66.0

5 months ago

1.52.1

5 months ago

1.52.0

5 months ago

1.54.1

5 months ago

1.54.0

5 months ago

1.44.0

5 months ago

1.46.0

5 months ago

1.48.0

5 months ago

1.51.0

5 months ago

1.45.1

5 months ago

1.45.0

5 months ago

1.47.1

5 months ago

1.45.3

5 months ago

1.47.0

5 months ago

1.45.2

5 months ago

1.49.0

5 months ago

1.50.0

5 months ago

1.37.0

5 months ago

1.35.0

5 months ago

1.39.1

5 months ago

1.39.2

5 months ago

1.39.0

5 months ago

1.39.3

5 months ago

1.40.0

5 months ago

1.42.0

5 months ago

1.42.1

5 months ago

1.29.0

5 months ago

1.27.0

5 months ago

1.32.0

5 months ago

1.30.0

5 months ago

1.30.1

5 months ago

1.36.0

5 months ago

1.34.0

5 months ago

1.38.0

5 months ago

1.41.0

5 months ago

1.43.1

5 months ago

1.43.0

5 months ago

1.26.0

5 months ago

1.28.0

5 months ago

1.33.0

5 months ago

1.31.0

5 months ago

1.25.0

5 months ago

1.24.1

5 months ago

1.24.0

5 months ago

1.23.0

5 months ago

1.22.0

5 months ago

1.21.2

5 months ago

1.21.1

5 months ago

1.21.0

5 months ago

1.20.0

5 months ago

1.19.0

6 months ago

1.18.0

6 months ago

1.17.0

6 months ago

1.16.0

6 months ago

1.15.0

6 months ago

1.14.0

6 months ago

1.13.0

6 months ago

1.12.0

6 months ago

1.11.0

6 months ago

1.10.0

6 months ago

1.9.0

6 months ago

1.8.0

6 months ago

1.7.3

6 months ago

1.7.2

6 months ago

1.7.1

6 months ago

1.7.0

6 months ago

1.6.1

6 months ago

1.6.0

6 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.4.1

6 months ago

1.4.0

6 months ago

1.3.0

6 months ago

1.2.1

6 months ago

1.2.0

6 months ago

1.1.0

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago