@putout/plugin-parens

3.0.0ย โ€ขย Publicย โ€ขย Published

@putout/plugin-parens NPM version

๐ŸŠPutout plugin adds ability to add missing parens. Check out in ๐ŸŠPutout Editor.

Install

npm i @putout/plugin-parens

Rules

Config

Short:

{
    "rules": {
        "parens/add-missing": "on",
        "parens/remove-useless": "on"
    }
}

Full:

{
    "rules": {
        "parens/add-missing-for-await": "on",
        "parens/add-missing-for-template": "on",
        "parens/add-missing-for-assign": "on",
        "parens/remove-useless-for-await": "on",
        "parens/remove-useless-for-params": "on"
    }
}

add-missing-for-assign

The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. It may be triggered when a single = sign was used instead of == or ===.

(c) MDN

To disable use:

{
    "rules": {
        "parens/add-missing-for-assign": "off"
    }
}
-a && b = a;
+a && (b = a);

add-missing-for-await

โŒ Example of incorrect code

await asyncFn().filter(Boolean);

โœ… Example of correct code

(await asyncFn()).filter(Boolean);

add-missing-for-template

The JavaScript exception "tagged template cannot be used with optional chain" occurs when the tag expression of a tagged template literal is an optional chain, or if there's an optional chain between the tag and the template.

(c) MDN

Checkout in ๐ŸŠPutout Editor.

{
    "rules": {
        "parens/add-missing-for-template": "off"
    }
}

โŒ Example of incorrect code

getConsoleLog?.()``;
String?.raw``;
String?.raw!``;

โœ… Example of correct code

(getConsoleLog?.())``;
(String?.raw)``;
(String?.raw)!``;

remove-useless-for-await

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const s = (await m());

โœ… Example of correct code

const s = await m();

remove-useless-for-params

Uncaught SyntaxError: Invalid destructuring assignment target

(c) Chrome

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const a = ((b)) => c;

โœ… Example of correct code

const a = (b) => c;

License

MIT

Package Sidebar

Install

npm i @putout/plugin-parens

Weekly Downloads

2,070

Version

3.0.0

License

MIT

Unpacked Size

11.1 kB

Total Files

9

Last publish

Collaborators

  • coderaiser