包详细信息

samadhi

coderaiser28kMIT3.0.5

Linter that fixes syntax errors

linter, js

自述文件

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

更新日志

2025.06.03, v3.0.5

feature:

  • 2059d2c samadhi: @putout/quick-lint v2.0.0

2025.06.03, v3.0.4

feature:

  • 18dc4bc samadhi: putout v40.3.0
  • 7376d82 samadhi: eslint-plugin-putout v27.1.0

2025.03.28, v3.0.3

feature:

  • cb742da samadhi: flatlint v3.0.0

2025.03.26, v3.0.2

fix:

  • bae8d82 samadhi: get rid of mjs

2025.03.26, v3.0.1

fix:

  • 550105e samadhi: convert to ESM

2025.03.26, v3.0.0

feature:

  • 4355b91 samadhi: supertape v11.0.4
  • eaaa9e3 samadhi: putout v39.1.0
  • cd841e7 samadhi: madrun v11.0.0
  • afa2403 samadhi: goldstein v6.0.0
  • 3106866 samadhi: eslint-plugin-putout v26.1.0
  • 28d5b0e samadhi: drop support of node < 20

2025.02.17, v2.15.1

feature:

  • acda73d samadhi: flatlint v2.0.0

2025.02.03, v2.15.0

feature:

  • 8a0f92b samadhi: eslint-plugin-putout v24.0.0
  • 6e05376 samadhi: putout v38.0.5

2025.01.20, v2.14.1

fix:

  • 6154681 samadhi: message

2025.01.20, v2.14.0

feature:

  • 2d04629 samadhi: use FlatLint before QuickLint

2025.01.11, v2.13.1

feature:

  • b3c8bca samadhi: rm unused js-tokens

2025.01.10, v2.13.0

feature:

  • 00cdcfb samadhi: use flatlint

2024.12.19, v2.12.0

feature:

  • 6228198 samadhi: wrong brace
  • 9f595eb samadhi: putout v37.0.1

2024.12.12, v2.11.0

feature:

  • 9ec0aae samadhi: export without const
  • 95c5c8d samadhi: putout v36.17.0
  • 631694a samadhi: eslint-plugin-putout v23.3.0

2024.06.21, v2.10.0

feature:

  • fb369fb samadhi: startLine: add

2024.06.11, v2.9.3

feature:

  • 1fd3e44 samadhi: c8 v10.0.0
  • 02a8ef1 samadhi: goldstein v5.16.0

2024.06.03, v2.9.2

fix:

  • 78c0634 samadhi: tokenize: semicolons

2024.06.03, v2.9.1

feature:

  • 67d6753 samadhi: tokenize: comma: import

2024.06.03, v2.9.0

feature:

  • 8581e07 samadhi: assign from

2024.05.31, v2.8.0

feature:

  • 8cfcdbd samadhi: useless semicolon

2024.05.30, v2.7.0

feature:

  • c979118 fix: useless comma

2024.05.30, v2.6.0

feature:

  • 865722e move out traverse
  • 7bafd9a samadhi: comma

2024.05.30, v2.5.1

fix:

  • 46e5a2e rm debugger

2024.05.30, v2.5.0

feature:

  • f65430b samadhi: comma before const

2024.05.30, v2.4.0

feature:

  • 1f953af tokenize: comma last token in file

2024.05.30, v2.3.0

feature:

  • a4e8f27 samadhi: add ability to handle comma after statement

2024.05.28, v2.2.0

feature:

  • 1d5d04a samadhi: improve support of broken string inside call

2024.05.28, v2.1.0

feature:

  • e94ecd8 samadhi: add support of jsx, typescript

2024.05.27, v2.0.0

feature:

  • 8ed3136 samadhi: returns: {code, places} -> [code, places]

2024.05.27, v1.3.0

feature:

  • a6e7d78 samadhi: import identifier

2024.05.27, v1.2.0

fix:

  • 139d0c0 samadhi: parse-error: no loc

2024.05.23, v1.1.1

fix:

  • 15a97b0 package: repository url

2024.05.23, v1.1.0

feature:

  • 0bb79fd samadhi: add missing initializer