samadhi
v2.10.0
Published
Linter that fixes syntax errors
Downloads
12,647
Readme
Samadhi
![Coverage Status](https://coveralls.io/repos/coderaiser/samadhi/badge.svg?branch=master&service=github)
Samadhi (Sanskrit, समाधि) is a state of meditative consciousness.
🧘🏽Samadhi linter finds and fixes syntax errors.
Install
npm i samadhi --save
Avaliable fixes
-function parse(source) => {
+function parse(source) {
return source;
}
-const a = 'hello;
+const a = 'hello';
const b = 'world';
-x('hello);
+x('hello');
const m = {
- z: x('hello
+ z: x('hello'),
}
-if a > 5 {
+if (a > 5) {
alert();
}
-const {code, places} await samadhi(source);
+const {code, places} = await samadhi(source);
-import hello from hello;
+import hello from 'hello';
function x() {
- return 'hello',
+ return 'hello';
}
-const a = 5,
+const a = 5;
const a = {
- b: 'hello',,
+ b: 'hello',
}
const a = {
- b: 'hello';
+ b: 'hello',
}
const a = class {
- b() {},
+ b() {}
}
-const a = from 'a';
+const a = require('a');
API
lint(source: string, options: Options)
Possible options:
interface Options {
isJSX: boolean;
isTS: boolean;
startLine: number;
}
Here is example:
import {lint} from 'samadhi';
const source = `
function x() => {
return 'hello';
}
`;
const [code, places] = await lint(source);
// places:
[{
rule: 'parser (quick-lint-js)',
message: `functions/methods should not have '=>'`,
position: {
line: 2,
column: 8,
},
}];
You can also fix
results:
const [code] = await lint(source, {
fix: true,
});
// returns
function x() {
return 'hello';
}
License
MIT