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

Don't print an error on unused params in ES5 setters #2133

Closed
mgol opened this issue Mar 23, 2015 · 5 comments
Closed

Don't print an error on unused params in ES5 setters #2133

mgol opened this issue Mar 23, 2015 · 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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@mgol
Copy link
Contributor

mgol commented Mar 23, 2015

The following code:

(function () {
    "use strict";

    var o = {
        set b(a) {
        }
    };

    o.b = 2;
})();

triggers the error:

5:8 - a is defined but never used

In ES5 setters parameter is required, though and you can imagine a scenario where you want to use a setter without using the parameter.

This is similar to try {...} catch (e) {} where you need the parameter as well even if you don't need it. ESLint doesn't error on unused catch parameter.

The example was run on http://eslint.org/demo/.

@mgol mgol changed the title Don't error on unused params in ES5 setters Don't print an error on unused params in ES5 setters Mar 23, 2015
@BenoitZugmeyer
Copy link
Contributor

Just passing by:

though and you can imagine a scenario where you want to use a setter without using the parameter.

I can't imagine such scenario and I'm curious, what is your use case?

@mgol
Copy link
Contributor Author

mgol commented Mar 23, 2015

I can't imagine such scenario and I'm curious, what is your use case?

One example is if you have to work in non-strict code and you still want to have a particular setter to throw:

var o = {
    get x() {return 2;}
    set x(v) {throw new Error('o.x cannot be modified!');}
};
console.log(o.x);
o.x = 3;

@BenoitZugmeyer
Copy link
Contributor

Nice, thank you!

@nzakas nzakas added triage An ESLint team member will look at this issue soon enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Mar 23, 2015
@nzakas
Copy link
Member

nzakas commented Mar 23, 2015

Yeah, I think the analogy of catch is spot-on. You literally have no choice but to provide the argument even if you arent going to use it. We should just skip checking it.

@nzakas
Copy link
Member

nzakas commented Mar 24, 2015

Working on this.

@nzakas nzakas closed this as completed in 5749bfe Mar 27, 2015
nzakas added a commit that referenced this issue Mar 27, 2015
Update: Omit setter param from no-unused-vars (fixes #2133)
@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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants