Consistent const violations (#6100)
* Changed updateExpression to report itself as violation instead of its argument * Update getBindingIdentifiers to work with forXStatement and return proper node as violation * Updated unaryExpression violation to be consistent with changes.
This commit is contained in:
committed by
Justin Ridgewell
parent
3c4f19a28d
commit
d8b4073536
@@ -36,13 +36,13 @@ export default function({ messages, types: t }) {
|
||||
violation.get("right").node,
|
||||
),
|
||||
);
|
||||
} else if (violation.parentPath.isUpdateExpression()) {
|
||||
violation.parentPath.replaceWith(
|
||||
statementBeforeExpression(throwNode, violation.parent),
|
||||
} else if (violation.isUpdateExpression()) {
|
||||
violation.replaceWith(
|
||||
statementBeforeExpression(throwNode, violation.node),
|
||||
);
|
||||
} else if (violation.parentPath.isForXStatement()) {
|
||||
violation.parentPath.ensureBlock();
|
||||
violation.parentPath.node.body.body.unshift(throwNode);
|
||||
} else if (violation.isForXStatement()) {
|
||||
violation.ensureBlock();
|
||||
violation.node.body.body.unshift(throwNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ const collectorVisitor = {
|
||||
ForXStatement(path, state) {
|
||||
const left = path.get("left");
|
||||
if (left.isPattern() || left.isIdentifier()) {
|
||||
state.constantViolations.push(left);
|
||||
state.constantViolations.push(path);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -140,12 +140,12 @@ const collectorVisitor = {
|
||||
},
|
||||
|
||||
UpdateExpression(path, state) {
|
||||
state.constantViolations.push(path.get("argument"));
|
||||
state.constantViolations.push(path);
|
||||
},
|
||||
|
||||
UnaryExpression(path, state) {
|
||||
if (path.node.operator === "delete") {
|
||||
state.constantViolations.push(path.get("argument"));
|
||||
state.constantViolations.push(path);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -89,6 +89,9 @@ getBindingIdentifiers.keys = {
|
||||
FunctionDeclaration: ["id", "params"],
|
||||
FunctionExpression: ["id", "params"],
|
||||
|
||||
ForInStatement: ["left"],
|
||||
ForOfStatement: ["left"],
|
||||
|
||||
ClassDeclaration: ["id"],
|
||||
ClassExpression: ["id"],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user