Skip to content
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

Merged
merged 3 commits into from
Feb 5, 2014
Merged

#586 add hoisting check to no-unreachable #590

merged 3 commits into from
Feb 5, 2014

Conversation

makepanic
Copy link
Contributor

Added check for no-unreachable if node has:

  • node.type equals FunctionDeclaration
  • node.type equals VariableDeclaration and every declaration has no init

I 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.

return isAllowed;
}

function checkNodeFieldForUnreachable(node, field) {
Copy link
Member

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?

@nzakas
Copy link
Member

nzakas commented Feb 5, 2014

Can you also add some details in the rule documentation explaining this case?

@makepanic
Copy link
Contributor Author

I added a note that describes the cases that don't trigger the no-unreachable warning and added jsdoc comments.

* @param {ASTNode} node
* @returns {boolean} if the node doesn't trigger unreachable
*/
function isUnreachableAllowed(node) {
Copy link
Member

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;

@nzakas
Copy link
Member

nzakas commented Feb 5, 2014

Thanks for the fast turnaround on the review comments!

nzakas added a commit that referenced this pull request Feb 5, 2014
add hoisting check to no-unreachable (fixes #586)
@nzakas nzakas merged commit 2fe0615 into eslint:master Feb 5, 2014
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FunctionDeclaration after ReturnStatement triggers false positive from no-unreachable
3 participants