JSPM

flatlint

1.5.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7176
  • Score
    100M100P100Q129943F
  • License MIT

JavaScript tokens-based linter

Package Exports

  • flatlint/with-plugins

Readme

FlatLint

Token-based JavaScript linter that fixes Syntax Errors

Install

npm i flatlint

Available fixes

Assignment without parentheses after &&
-a && b = c;
+a && (b = c);
Convert , to ; at the end of statement
-const a = 5,
+const a = 5;
forgotten round braces in if statement
-if a > 5 {
+if (a > 5) {
    alert();
}
remove useless round brace
-const a = 5);
+const a = 5;
add missing quote
-const a = 'hello
+const a = 'hello'

-fn('hello);
+fn('hello');

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`, {
    plugins: [
        ['wrap-assignment-in-parens', {
            report: () => `Wrap the assignment in parentheses after '&&'`,
            replace: () => ({
                '__a && __b = __c': '__a && (__b = __c)',
            }),
        }],
    ],
});

License

MIT