2.11.0 • Published 8 months ago

flatlint v2.11.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 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

8 months ago

2.8.0

8 months ago

2.10.0

8 months ago

2.7.0

8 months ago

2.6.0

8 months ago

2.5.0

8 months ago

2.5.1

8 months ago

2.9.0

8 months ago

2.4.0

8 months ago

2.3.0

8 months ago

2.3.2

8 months ago

2.3.1

8 months ago

2.3.4

8 months ago

2.3.3

8 months ago

2.3.5

8 months ago

2.2.0

8 months ago

2.1.2

8 months ago

2.1.1

8 months ago

2.1.4

8 months ago

2.1.3

8 months ago

2.1.6

8 months ago

2.1.5

8 months ago

2.1.7

8 months ago

2.1.0

8 months ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.0.7

8 months ago

2.0.6

8 months ago

2.0.9

8 months ago

2.0.8

8 months ago

2.0.10

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.115.0

8 months ago

1.114.0

8 months ago

1.116.0

8 months ago

1.111.0

9 months ago

1.113.0

9 months ago

1.112.0

9 months ago

1.110.0

9 months ago

1.109.0

9 months ago

1.108.0

9 months ago

1.107.0

9 months ago

1.103.0

9 months ago

1.106.0

9 months ago

1.106.1

9 months ago

1.102.0

9 months ago

1.101.0

9 months ago

1.105.1

9 months ago

1.105.0

9 months ago

1.101.1

9 months ago

1.99.0

9 months ago

1.100.0

9 months ago

1.104.0

9 months ago

1.98.1

9 months ago

1.98.0

9 months ago

1.97.1

9 months ago

1.97.0

9 months ago

1.98.2

9 months ago

1.94.0

9 months ago

1.96.0

9 months ago

1.95.0

9 months ago

1.79.0

9 months ago

1.90.1

9 months ago

1.90.0

9 months ago

1.82.0

9 months ago

1.86.0

9 months ago

1.67.0

9 months ago

1.70.0

9 months ago

1.74.0

9 months ago

1.93.1

9 months ago

1.93.0

9 months ago

1.83.0

9 months ago

1.87.0

9 months ago

1.68.0

9 months ago

1.71.0

9 months ago

1.75.0

9 months ago

1.92.0

9 months ago

1.80.0

9 months ago

1.80.1

9 months ago

1.84.0

9 months ago

1.89.0

9 months ago

1.88.0

9 months ago

1.69.0

9 months ago

1.72.0

9 months ago

1.76.0

9 months ago

1.78.0

9 months ago

1.91.1

9 months ago

1.91.0

9 months ago

1.81.0

9 months ago

1.85.0

9 months ago

1.73.0

9 months ago

1.77.0

9 months ago

1.56.0

9 months ago

1.58.1

9 months ago

1.58.0

9 months ago

1.61.0

9 months ago

1.63.0

9 months ago

1.65.0

9 months ago

1.53.0

9 months ago

1.55.0

9 months ago

1.57.0

9 months ago

1.59.0

9 months ago

1.60.0

9 months ago

1.62.0

9 months ago

1.60.2

9 months ago

1.60.1

9 months ago

1.64.0

9 months ago

1.66.0

9 months ago

1.52.1

10 months ago

1.52.0

10 months ago

1.54.1

9 months ago

1.54.0

9 months ago

1.44.0

10 months ago

1.46.0

10 months ago

1.48.0

10 months ago

1.51.0

10 months ago

1.45.1

10 months ago

1.45.0

10 months ago

1.47.1

10 months ago

1.45.3

10 months ago

1.47.0

10 months ago

1.45.2

10 months ago

1.49.0

10 months ago

1.50.0

10 months ago

1.37.0

10 months ago

1.35.0

10 months ago

1.39.1

10 months ago

1.39.2

10 months ago

1.39.0

10 months ago

1.39.3

10 months ago

1.40.0

10 months ago

1.42.0

10 months ago

1.42.1

10 months ago

1.29.0

10 months ago

1.27.0

10 months ago

1.32.0

10 months ago

1.30.0

10 months ago

1.30.1

10 months ago

1.36.0

10 months ago

1.34.0

10 months ago

1.38.0

10 months ago

1.41.0

10 months ago

1.43.1

10 months ago

1.43.0

10 months ago

1.26.0

10 months ago

1.28.0

10 months ago

1.33.0

10 months ago

1.31.0

10 months ago

1.25.0

10 months ago

1.24.1

10 months ago

1.24.0

10 months ago

1.23.0

10 months ago

1.22.0

10 months ago

1.21.2

10 months ago

1.21.1

10 months ago

1.21.0

10 months ago

1.20.0

10 months ago

1.19.0

10 months ago

1.18.0

10 months ago

1.17.0

10 months ago

1.16.0

10 months ago

1.15.0

10 months ago

1.14.0

10 months ago

1.13.0

10 months ago

1.12.0

10 months ago

1.11.0

10 months ago

1.10.0

10 months ago

1.9.0

10 months ago

1.8.0

10 months ago

1.7.3

10 months ago

1.7.2

10 months ago

1.7.1

10 months ago

1.7.0

10 months ago

1.6.1

10 months ago

1.6.0

10 months ago

1.5.1

10 months ago

1.5.0

10 months ago

1.4.1

10 months ago

1.4.0

10 months ago

1.3.0

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago