Détail du package

samadhi

coderaiser14.1kMIT3.0.5

Linter that fixes syntax errors

linter, js

readme

Samadhi License NPM version Build Status Coverage Status

Samadhi (Sanskrit, समाधि) is a state of meditative consciousness.

image

🧘🏽Samadhi linter finds and fixes syntax errors.

Install

npm i samadhi --save

Available fixes

<summary>function declaration half converted from arrow expression</summary> diff -function parse(source) => { +function parse(source) { return source; }
<summary>broken string</summary> diff -const a = 'hello; +const a = 'hello'; -const b = ‘hello world’; +const b = 'hello world'; -x('hello); +x('hello'); const m = { - z: x('hello + z: x('hello'), }
<summary>forgotten round braces in if statement</summary> diff -if a > 5 { +if (a > 5) { alert(); }
<summary>missing initializer</summary> diff -const {code, places} await samadhi(source); +const {code, places} = await samadhi(source);
<summary>import identifier</summary> diff -import hello from hello; +import hello from 'hello';
<summary>comma after statement</summary> diff function x() { - return 'hello', + return 'hello'; } -const a = 5, +const a = 5;
<summary>useless comma</summary> diff const a = { - b: 'hello',, + b: 'hello', }
<summary>useless semicolon</summary> diff const a = { - b: 'hello'; + b: 'hello', }
<summary>useless coma</summary> diff const a = class { - b() {}, + b() {} }
<summary>assign from</summary> diff -const a = from 'a'; +const a = require('a');
<summary>export without const</summary> diff -export x = () => {}; +export const x = () => {};
<summary>wrong brace</summary> diff -import a from 'a'); +import a from '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