Socket
Book a DemoInstallSign in
Socket

@putout/plugin-for-of

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/plugin-for-of

🐊Putout plugin adds ability to apply for...of

Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@putout/plugin-for-of NPM version

The for...of statement creates a loop which invokes a custom iteration hook with statements to be executed for the value of each element of an array.

(c) MDN

🐊Putout plugin adds support of transformation for...of statements.

Install

npm i @putout/plugin-for-of

Configuration

{
    "rules": {
        "for-of/map": "on",
        "for-of/for": "on"
    }
}

map

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

(c) MDN

❌ Example of incorrect code

names.map((name) => {
    alert(`hello ${name}`);
});

✅ Example of correct code

for (const name of names) {
    alert(`hello ${name}`);
}

for

The for statement creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement to be executed in the loop.

(c) MDN

for-n

❌ Example of incorrect code

const n = items.length;

for (let i = 0; i < n; i++) {
    const item = items[i];
    log(item);
}

✅ Example of correct code

for (const item of items) {
    log(item);
}

for-length

❌ Example of incorrect code

for (let i = 0; i < array.length; i++) {
    const item = array[i];
    console.log(item);
}

✅ Example of correct code

for (const item of items) {
    log(item);
}

for-entries

❌ Example of incorrect code

for (let i = 0; i < array.length; i++) {
    const item = array[i];
    console.log(i, item);
}

✅ Example of correct code

for (const [i, item] of array.entries()) {
    console.log(i, item);
}

for-entries-n

❌ Example of incorrect code
const n = array.length;
for (let i = 0; i < n; i++) {
    const item = array[i];
    console.log(i, item);
}

✅ Example of correct code

for (const [i, item] of array.entries()) {
    console.log(i, item);
}

License

MIT

Keywords

putout

FAQs

Package last updated on 11 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts