-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#586 add hoisting check to no-unreachable #590
Conversation
return isAllowed; | ||
} | ||
|
||
function checkNodeFieldForUnreachable(node, field) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like this abstraction. Can you add some doc comments to it?
Can you also add some details in the rule documentation explaining this case? |
I added a note that describes the cases that don't trigger the |
* @param {ASTNode} node | ||
* @returns {boolean} if the node doesn't trigger unreachable | ||
*/ | ||
function isUnreachableAllowed(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The control flow in this function is beyond odd. Use this instead:
function isUnreachableAllowed(node) {
return node.type === "FunctionDeclaration" ||
node.type === "VariableDeclaration" &&
node.declarations.every(function(declaration){
return declaration.type === "VariableDeclarator" && declaration.init === null;
});
}
--cyclomaticComplexity;
Thanks for the fast turnaround on the review comments! |
add hoisting check to no-unreachable (fixes #586)
Added check for no-unreachable if node has:
node.type
equalsFunctionDeclaration
node.type
equalsVariableDeclaration
and every declaration has no initI also added some tests that verify the new implementation and refactored the initial loop to a function to avoid repetition. This pull request should resolve #586
If there's anything wrong feel free to tell me.