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

"no-unused-vars" doesn't work with recursive function correctly, when it is declared with function expression #10982

Closed
aliaksandr-yermalayeu opened this issue Oct 15, 2018 · 5 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@aliaksandr-yermalayeu
Copy link

Tell us about your environment

  • ESLint Version: 5.7.0
  • Node Version: 8.11.1
  • npm Version: 5.6.0

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:

{
    "rules": {
        "no-unused-vars": "error"
    }
}
Configuration
{
    "rules": {
        "no-unused-vars": "error"
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

function declaration

// considered error
function a () {
    a();
}

function expression

// error is not happened
var a = function () {
    a();
}

What did you expect to happen?
Second case should cause error the same way as the first one.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Oct 15, 2018
@platinumazure platinumazure added bug ESLint is working incorrectly rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Oct 15, 2018
@platinumazure
Copy link
Member

Hi @aliaksandr-yermalayeu, thanks for the issue.

It seems to me the recursive declaration case should be flagged as used (i.e., neither example should produce a warning). But I'm not 100% sure.

@not-an-aardvark @mysticatea Any thoughts?

@not-an-aardvark
Copy link
Member

The firat example should produce a warning because the function can never be initially called, since it's only referenced from inside itself.

The second example could be made to produce a warning for the same reason, although this would require modifying the rule to be able to infer that the function can only be accessed through the a variable.

@mysticatea
Copy link
Member

It has been introduced in #2095; the rule is addressing function declarations to detect recursive calls, but not variable declarations. We can enhance the rule. Maybe...

  • the rule should ignore references in the VariableDeclarator#init and AssignmentPattern#right if duplicate variables don't exist.

@kaicataldo
Copy link
Member

@mysticatea Just to clarify, are you saying this is a bug?

@mysticatea
Copy link
Member

mysticatea commented Oct 29, 2018

Looks like an enhancement to me.

Re-looked, #2095 was handled as a bug, so this is a bug.

@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 29, 2018
sergei-startsev added a commit to sergei-startsev/eslint that referenced this issue Oct 30, 2018
sergei-startsev added a commit to sergei-startsev/eslint that referenced this issue Oct 30, 2018
@nzakas nzakas closed this as completed in 9436712 Nov 9, 2018
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators May 9, 2019
@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 May 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

5 participants