Disallow multi-line 'if', 'while' and 'for' conditionals
yokuze opened this issue · 1 comments
yokuze commented
Long if
statement conditionals are sometimes broken up into multiple lines to avoid having a single long line. However, the result is difficult to read and leads to some unusual indentation issues. Consider these examples:
https://github.com/eslint/eslint/blob/3e522be/lib/rules/indent.js#L656 and
if (node.parent && (
node.parent.type === "FunctionExpression" ||
node.parent.type === "FunctionDeclaration" ||
node.parent.type === "ArrowFunctionExpression"
)) {
{
checkIndentInFunctionBlock(node);
return;
}
and https://github.com/eslint/eslint/blob/3e522be/lib/rules/indent.js#L466
if (calleeNode.parent &&
(calleeNode.parent.type === "Property" ||
calleeNode.parent.type === "ArrayExpression")) {
// If function is part of array or object, comma can be put at left
indent = getNodeIndent(calleeNode, false, false);
}
and https://github.com/eslint/eslint/blob/3e522be/lib/rules/indent.js#L422
while (
stmt.type === "UnaryExpression" && (
stmt.operator === "!" ||
stmt.operator === "~" ||
stmt.operator === "+" ||
stmt.operator === "-") ||
stmt.type === "AssignmentExpression" ||
stmt.type === "LogicalExpression" ||
stmt.type === "SequenceExpression" ||
stmt.type === "VariableDeclarator") {
stmt = stmt.parent;
}
Find and enable an existing rule or create a new plugin that disallows multi-line conditionals in if
, else if
, for
and while
statements.
yokuze commented
Fixed with: silvermine/eslint-plugin-silvermine#3