npm.io
6.0.1 • Published 1 week ago

@putout/plugin-parens

Licence
MIT
Version
6.0.1
Deps
0
Size
12 kB
Vulns
0
Weekly
0
Stars
797

@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-from-await": "on",
        "parens/add-missing-for-template": "on",
        "parens/add-missing-for-assign": "on",
        "parens/remove-useless-from-await": "on",
        "parens/remove-useless-from-params": "on",
        "parens/remove-useless-from-object": "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-from-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-from-await

Checkout in Putout Editor.

Example of incorrect code
const s = (await m());
Example of correct code
const s = await m();

remove-useless-from-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;

remove-useless-from-object

Checkout in Putout Editor.

Example of incorrect code
createNestedDirectory(({}) as any);
Example of correct code
createNestedDirectory({} as any);

License

MIT

Keywords