Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-no-loops

Package Overview
Dependencies
Maintainers
7
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-loops - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

.github/workflows/ci.yml

26

lib/no-loops.js
'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 }
}
]
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc