@putout/plugin-convert-for-to-for-of

putout plugin adds ability to convert for to for-of

Usage no npm install needed!

<script type="module">
  import putoutPluginConvertForToForOf from 'https://cdn.skypack.dev/@putout/plugin-convert-for-to-for-of';
</script>

README

putout-plugin-convert-for-to-for-of NPM version Dependency Status

putout plugin adds ability to convert for to for-of loop.

Install

npm i @putout/plugin-convert-for-to-for-of -D

Rule

Rule convert-for-to-for-of is enabled by default, to disable add to .putout.json:

{
    "rules": {
        "convert-for-to-for-of/n": "off",
        "convert-for-to-for-of/length": "off"
    }
}

❌ Incorrect code example

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

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

✅ Correct code Example

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

License

MIT