We have been stalled on ESLint 3.8.0 for some time. Current ESLint is 3.13.0. We have been unable to upgrade because of more aggressive reporting on some rules, including indentation. ESLint configuration options and bugfixes are now such that we can reasonably upgrade. PR-URL: https://github.com/nodejs/node/pull/10561 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
/**
|
|
* @fileoverview Rule to flag for-in loops without if statements inside
|
|
* @author Nicholas C. Zakas
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = {
|
|
meta: {
|
|
docs: {
|
|
description: "require `for-in` loops to include an `if` statement",
|
|
category: "Best Practices",
|
|
recommended: false
|
|
},
|
|
|
|
schema: []
|
|
},
|
|
|
|
create(context) {
|
|
|
|
return {
|
|
|
|
ForInStatement(node) {
|
|
|
|
/*
|
|
* If the for-in statement has {}, then the real body is the body
|
|
* of the BlockStatement. Otherwise, just use body as provided.
|
|
*/
|
|
const body = node.body.type === "BlockStatement" ? node.body.body[0] : node.body;
|
|
|
|
if (body && body.type !== "IfStatement") {
|
|
context.report({ node, message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype." });
|
|
}
|
|
}
|
|
};
|
|
|
|
}
|
|
};
|