eslint-plugin-no-for-of-loops
Version:
Prevents for..of loops usage
51 lines (37 loc) • 1.66 kB
Markdown
# eslint-plugin-no-for-of-loops
An [eslint](http://eslint.org/) plugin to prevent `for (...of)` loops usage in your code base.
[](https://travis-ci.org/dharFr/eslint-plugin-no-for-of-loops)
[](https://www.npmjs.com/package/eslint-plugin-no-for-of-loops)
[](https://greenkeeper.io/)
## Installation
``` sh
npm install --save-dev eslint-plugin-no-for-of-loops
```
## Usage
In your `.eslintrc`:
``` javascript
{
"plugins": [
"no-for-of-loops"
],
"rules": {
"no-for-of-loops/no-for-of-loops": 2
}
}
```
## Rule
Disallow use of `for (..of)` loops.
## Why
Using `for (...of)` loops requires `Symbol` and iterator polyfills to work on older browsers (see [babel/babel#1534](https://github.com/babel/babel/issues/1534)).
Depending on your browsers target (for example, Android 4.4 in-app Webview is capped to Chrome 33), you might not want to include those polyfills to save a few kilobytes.
See [for..of](http://kangax.github.io/compat-table/es6/#test-for..of_loops) and [Symbol](http://kangax.github.io/compat-table/es6/#test-Symbol) compatibily tables for more details.
## Disabling the rule
Want to disable the rule anyway? Your call :
```javascript
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
for (let i of iterable) {
// ...
}
```
## Credits
This project was initialy forked form [eslint-plugin-no-loops](https://github.com/buildo/eslint-plugin-no-loops). Kudos!