eslint-plugin-no-loops
Advanced tools
Comparing version 0.3.0 to 0.4.0
'use strict'; | ||
module.exports = function (context) { | ||
function reportLoopPresence(node) { | ||
context.report(node, 'loops are not allowed', { identifier: node.name }); | ||
module.exports = { | ||
create(context) { | ||
function reportLoopPresence(node) { | ||
context.report(node, 'loops are not allowed', { identifier: node.name }); | ||
} | ||
return { | ||
ForStatement: reportLoopPresence, | ||
ForInStatement: reportLoopPresence, | ||
WhileStatement: reportLoopPresence, | ||
DoWhileStatement: reportLoopPresence, | ||
ForOfStatement: reportLoopPresence | ||
}; | ||
} | ||
return { | ||
ForStatement: reportLoopPresence, | ||
ForInStatement: reportLoopPresence, | ||
WhileStatement: reportLoopPresence, | ||
DoWhileStatement: reportLoopPresence, | ||
ForOfStatement: reportLoopPresence | ||
}; | ||
}; | ||
} |
{ | ||
"name": "eslint-plugin-no-loops", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Disallow loops", | ||
@@ -25,8 +25,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"babel-eslint": "^6.1.0", | ||
"eslint": "^2.0.0" | ||
"eslint": "^9.4.0" | ||
}, | ||
"peerDependencies": { | ||
"eslint": ">=2.0.0" | ||
"eslint": ">=9" | ||
} | ||
} |
# eslint-plugin-no-loops | ||
It's 2016 and you still use loops? | ||
It's 2024 and you still use loops? | ||
@@ -8,3 +8,3 @@ [![Build Status](https://travis-ci.org/buildo/eslint-plugin-no-loops.svg?branch=master)](https://travis-ci.org/buildo/eslint-plugin-no-loops) | ||
<p align="center"> | ||
<img src="http://img.memegenerator.io/meme/160120/mr8qya.jpg" /> | ||
<img src="https://i.imgflip.com/1oa3kd.jpg" title="made at imgflip.com"/> | ||
</p> | ||
@@ -32,5 +32,17 @@ | ||
## Rule | ||
Disallow use of loops (for, for-in, while, do-while). | ||
Disallow use of loops (for, for-in, while, do-while, for-of). | ||
## Why | ||
You [don't](http://www.codereadability.com/coding-without-loops/) [need](http://joelhooks.com/blog/2014/02/06/stop-writing-for-loops-start-using-underscorejs/) [them](http://www.sitepoint.com/quick-tip-stop-writing-loops-start-thinking-with-maps/). | ||
## I know better, I need one now | ||
If 99% of your code doesn't need them, but you have that single case where a loop makes sense, go ahead! | ||
```javascript | ||
// eslint-disable-next-line no-loops/no-loops | ||
for (let i = 0; i < arr.length; i++) { | ||
// ... | ||
} | ||
``` | ||
What is a rule without its exceptions? |
@@ -17,22 +17,22 @@ 'use strict'; | ||
code: 'for (var i; i <= n; i++) { console.log(i); }', | ||
errors: [ { message: 'loops are not allowed' } ] | ||
errors: [{ message: 'loops are not allowed' }] | ||
}, | ||
{ | ||
code: 'for (i in [1, 2, 3]) { console.log(i); }', | ||
errors: [ { message: 'loops are not allowed' } ] | ||
errors: [{ message: 'loops are not allowed' }] | ||
}, | ||
{ | ||
code: 'while (i <= n) { console.log(i); }', | ||
errors: [ { message: 'loops are not allowed' } ] | ||
errors: [{ message: 'loops are not allowed' }] | ||
}, | ||
{ | ||
code: 'do { console.log(i); } while (i <= n)', | ||
errors: [ { message: 'loops are not allowed' } ] | ||
errors: [{ message: 'loops are not allowed' }] | ||
}, | ||
{ | ||
code: 'for (i of [1, 2, 3]) { console.log(i) }', | ||
parser: 'babel-eslint', | ||
errors: [ { message: 'loops are not allowed' } ] | ||
errors: [{ message: 'loops are not allowed' }], | ||
languageOptions: { ecmaVersion: 6 } | ||
} | ||
] | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4787
1
54
47
7
1