Package Exports
- flatlint/with-plugins
Readme
FlatLint
Token-based JavaScript linter that fixes Syntax Errors
Install
npm i flatlintAvailable 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' 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