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

Unused var error missing when using es6 modules #2678

Closed
dominicbarnes opened this issue Jun 3, 2015 · 9 comments · Fixed by DavidKindler/meteor#3 · May be fixed by iamstoick/javascript#11
Closed

Unused var error missing when using es6 modules #2678

dominicbarnes opened this issue Jun 3, 2015 · 9 comments · Fixed by DavidKindler/meteor#3 · May be fixed by iamstoick/javascript#11
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

@dominicbarnes
Copy link
Contributor

It appears that when you use ES6 modules to export a function, the no-unused-var rule does not run properly on those function arguments. (vars declared in the function body still lint correctly)

function fn1({ a, b }) {
  console.log(a);
}

fn1();

export function fn2({ x, y }) {
  console.log(x);
}

fn2();

Given the following config:

{
  "env": {
    "es6": true
  },
  "ecmaFeatures": {
    "modules": true
  },
  "rules": {
    "no-unused-vars": 2
  }
}

When I run this in the CLI:

$ eslint --reset test.js

test.js
  2:18  error  b is defined but never used  no-unused-vars

✖ 1 problem (1 error, 0 warnings)

Notice that fn1 gets linted correctly, but fn2 does not report the unused y var.

@gyandeeps gyandeeps added the triage An ESLint team member will look at this issue soon label Jun 3, 2015
@gyandeeps
Copy link
Member

What version of eslint are you using?

@dominicbarnes
Copy link
Contributor Author

The latest :)

$ eslint --version
v0.22.1

@gyandeeps gyandeeps added bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jun 3, 2015
@nzakas
Copy link
Member

nzakas commented Jun 3, 2015

Why is this a bug? b is never used in your example?

@nzakas
Copy link
Member

nzakas commented Jun 3, 2015

Oh I see, it's missing y.

Are you using Babel-eslint?

@dominicbarnes
Copy link
Contributor Author

Nah, I'm just using eslint core.

@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 3, 2015
@nzakas
Copy link
Member

nzakas commented Jun 3, 2015

Thanks. We should double check that escope is doing the right thing here.

nzakas added a commit that referenced this issue Jun 4, 2015
Fix: Check unused vars in exported functions (fixes #2678)
@yangit
Copy link

yangit commented Oct 5, 2015

export default (a, b)=> {
  console.log(a);
};

this code still yields no errors.
Version is eslint 1.6.1
Settings as mentioned above

{
  "env": {
    "es6": true
  },
  "ecmaFeatures": {
    "modules": true
  },
  "rules": {
    "no-unused-vars": 2
  }
}

Expected output is to get a no-unused-vars error for b variable.

@ilyavolodin
Copy link
Member

@yangit Could you open a new issues?

@yangit
Copy link

yangit commented Oct 5, 2015

Done #4047

@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
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
5 participants