@putout/plugin-extract-sequence-expressions

3.5.0 • Public • Published

@putout/plugin-extract-sequence-expressions NPM version

The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand. This lets you create a compound expression in which multiple expressions are evaluated, with the compound expression's final value being the value of the rightmost of its member expressions.

(c) MDN

🐊Putout plugin adds ability to extract sequence expressions. Check out in 🐊Putout Editor.

☝️Remember, when you writing a transform you can skip all parts related to extracting sequence expressions and just reuse current plugin it will make your code simpler and less error prone.

Install

npm i @putout/plugin-extract-sequence-expressions -D

Rule

{
    "rules": {
        "extract-sequence-expressions": "on"
    }
}

Example of incorrect code

module.exports.x = 1,
module.exports.y = 2;

fn((a, b));
fn(a), 'hello';

fn(a), b = 3;
fn(a), fn(b);

if (a, b, c) {}

Example of correct code

module.exports.x = 1;
module.exports.y = 2;

fn(a, b);
fn(a, 'hello');

fn(a);
b = 3;

fn(a);
fn(b);

a;
b;

if (c) {}

Comparison

Linter Rule Fix
🐊 Putout extract-sequence-expressions
ESLint no-sequences

License

MIT

/@putout/plugin-extract-sequence-expressions/

    Package Sidebar

    Install

    npm i @putout/plugin-extract-sequence-expressions

    Weekly Downloads

    10,354

    Version

    3.5.0

    License

    MIT

    Unpacked Size

    7.48 kB

    Total Files

    4

    Last publish

    Collaborators

    • coderaiser