samadhi
Linter that fixes syntax errors
Last updated 6 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install samadhi 
SYNC missed versions from official npm registry.

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

Avaliable fixes

<summary>function declaration half converted from arrow expression</summary>
-function parse(source) => {
+function parse(source) {
    return source;
}
<summary>broken string</summary>
-const a = 'hello;
+const a = 'hello';
const b = 'world';


-x('hello);
+x('hello');
const m = {
-    z: x('hello
+    z: x('hello'),
}
<summary>forgotten round braces in if statement</summary>
-if a > 5 {
+if (a > 5) {
    alert();
}
<summary>missing initializer</summary>
-const {code, places} await samadhi(source);
+const {code, places} = await samadhi(source);
<summary>import identifier</summary>
-import hello from hello;
+import hello from 'hello';
<summary>comma after statement</summary>
function x() {
-    return 'hello',
+    return 'hello';
}

-const a = 5,
+const a = 5;
<summary>useless comma</summary>
const a = {
-    b: 'hello',,
+    b: 'hello',
}
<summary>useless semicolon</summary>
const a = {
-    b: 'hello';
+    b: 'hello',
}

const a = class {
-    b() {},
+    b() {}
}
<summary>assign from</summary>
-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

Current Tags

  • 2.10.0                                ...           latest (5 months ago)

19 Versions

  • 2.10.0                                ...           5 months ago
  • 2.9.3                                ...           5 months ago
  • 2.9.2                                ...           5 months ago
  • 2.9.1                                ...           5 months ago
  • 2.9.0                                ...           5 months ago
  • 2.8.0                                ...           5 months ago
  • 2.7.0                                ...           6 months ago
  • 2.6.0                                ...           6 months ago
  • 2.5.1                                ...           6 months ago
  • 2.5.0                                ...           6 months ago
  • 2.4.0                                ...           6 months ago
  • 2.3.0                                ...           6 months ago
  • 2.2.0                                ...           6 months ago
  • 2.1.0                                ...           6 months ago
  • 2.0.0                                ...           6 months ago
  • 1.3.0                                ...           6 months ago
  • 1.2.0                                ...           6 months ago
  • 1.1.1                                ...           6 months ago
  • 1.0.0                                ...           6 months ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (10)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE