@putout/plugin-assignment
🐊Putout plugin adds ability to transform code related to assignment
Last updated 10 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-assignment 
SYNC missed versions from official npm registry.

@putout/plugin-assignment NPM version

The assignment operator (=) is used to assign a value to a variable. The assignment operation evaluates to the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables.

????Putout plugin adds ability to transform to new Node.js API and apply best practices.

Install

npm i putout @putout/plugin-assignment -D

Rules

Config

{
    "rules": {
        "assignment/convert-to-arrow-function": "on",
        "assignment/convert-to-comparison": "on",
        "assignment/convert-to-declaration": "on",
        "assignment/simplify": "on",
        "assignment/split": "on"
    }
}

convert-to-arrow-function

An arrow function expression is a compact alternative to a function expression.

(c) MDN

Rule adds ability to convert assignment to arrow function.

❌ Example of incorrect code

const createRegExp = a = RegExp(a, 'g');

βœ… Example of correct code

const createRegExp = (a) => RegExp(a, 'g');

convert-to-comparison]

You should almost never have an if...else with an assignment like a = b as a condition.

(c) MDN

❌ Example of incorrect code

if (a = b) {}

βœ… Example of correct code

if (a === b) {}

convert-to-declaration

The const declaration declares block-scoped local variables. The value of a constant can't be changed through reassignment using the assignment operator, but if a constant is an object, its properties can be added, updated, or removed.

(c) MDN

Checkout in ????Putout Editor.

❌ Example of incorrect code

a = 5;

βœ… Example of correct code

const a = 5;

simplify

❌ Example of incorrect code

const {a} = {
    a: 5,
};

const [b] = [5];
const c = (() => 7)();

βœ… Example of correct code

const a = 5;
const b = 5;
const c = 7;

split

Rule adds ability to find and split variable declarations because (re)moving a line is simpler and less error prone then changing coma (=) to colon (;).

For the same reason, diff of changed declarations are more comfortable to read. Checkout in ????Putout Editor.

❌ Example of incorrect code

a = b = c = 1;

βœ… Example of correct code

a = 1;
b = a;
c = a;

License

MIT

Current Tags

  • 2.1.0                                ...           latest (9 months ago)

4 Versions

  • 2.1.0                                ...           9 months ago
  • 2.0.0                                ...           10 months ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |