This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 427310 - [eslint] report unused parameters
Summary: [eslint] report unused parameters
Status: RESOLVED FIXED
Alias: None
Product: Orion (Archived)
Classification: ECD
Component: JS Tools (show other bugs)
Version: 5.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 6.0 M1   Edit
Assignee: Michael Rennie CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-03 13:11 EST by Michael Rennie CLA
Modified: 2014-04-04 16:51 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2014-02-03 13:11:07 EST
eslint should show an error / warning for unused parameters in function delcarations/expressions.
Comment 1 Mark Macdonald CLA 2014-02-03 14:24:00 EST
"no-unused-vars" could be modified to look at parameters pretty easily. I think this should be a user setting though, separate from "Unused variables". Parameters are trickier to get right.

Like this:
> function Parent() {}
> Parent.prototype.method = function(a, b) {
>    console.log(a); console.log(b);
> };
> function Child() {}
> Child.prototype = Object.create(Parent.prototype);  // inherit
> 
> var c = new Child();
> c.method = function(a, b) {
>     b.whatever();
> };

^ Here `a` is unused in c.method() but the user can't remove it or it'll break the method signature contract from the superclass. I believe ESLint's implementation of no-unused-vars has some heuristics for dealing with this, which we should try to copy.
Comment 2 Michael Rennie CLA 2014-02-06 10:27:33 EST
(In reply to Mark Macdonald from comment #1)

> ^ Here `a` is unused in c.method() but the user can't remove it or it'll
> break the method signature contract from the superclass.

I think it is ok to mark 'a' with the suggestion being 'remove with possible side effects' as we do in JDT. I envision eventually we will provide support that if the param is doc'd it will not be reported if it is unused - until then we just mark any parameters that are unused like mentioned above or 'Parameter 'a' is not used' without any mention of removing them.

> I believe ESLint's
> implementation of no-unused-vars has some heuristics for dealing with this,
> which we should try to copy.

agreed.
Comment 4 libing wang CLA 2014-04-04 16:51:09 EDT
(In reply to Michael Rennie from comment #3)
> New rule + tests pushed to:
> http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/
> ?id=e8524f403c5f04f5681cb1425abde5f2469d62c5

Neat. I happened to notice this feature when I tried to fix Bug 432060 in my orion selfhosting. I deleted some unused vars in my code. It was very helpful.