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

Ability to disable unused variables per function #639

Closed
satazor opened this issue Sep 10, 2012 · 7 comments
Closed

Ability to disable unused variables per function #639

satazor opened this issue Sep 10, 2012 · 7 comments
Milestone

Comments

@satazor
Copy link

satazor commented Sep 10, 2012

/**
 * Emits an event.
 *
 * @param {String}   event   The event name
 * @param {...mixed} [$args] The arguments to pass to each listener
*/
emit: function (event, $args) {
    this._doSomething.apply(this, arguments);
},

I find the warnings regarding unused variables very useful but I would like JSHint to ignore it in certain cases.
Above is a valid use case in which I want the arguments to be there for readability but they are not used.
I tried the inline /*jshint unused:false*/ without success.

@Couto
Copy link

Couto commented Sep 10, 2012

+1

@satazor
Copy link
Author

satazor commented Sep 10, 2012

Another use case is that when generating the documentation with JSDoc and probably others, it throws warnings when we document parameters that aren't define in the function itself.

@kkapsner
Copy link

unused is complete not working in function scope:

/*jshint unused: false*/

function test(){
  /*jshint unused: true*/
  var unused;
}

will pass without error.

I think this is a bug.

@satazor
Copy link
Author

satazor commented Sep 13, 2012

jshint does not read the unused option in the middle of code/inside a function.
Thats why I opened this issue.

@niknah
Copy link

niknah commented Nov 18, 2012

The way I got around this was by using void...

function y(x) {
void(x);
}

There is a performance hit with void if you use them on too many arguments, but it's ok with one argument, I tested it here...
http://jsperf.com/does-void-slow-anything-down

jugglinmike pushed a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014
This commit makes it possible to disable 'unused' option per
function:

	//jshint unused:true
	var a;

	function foo(b) {
		//jshint unused:false
		return 1;
	}

	foo();

	// ->
	// Line 1: 'a' is defined but never used.

Closes jshintGH-639.
@ohmirocks
Copy link

HI,
Is this issue fixed. We are still having this problem in our CI builds when it tries to generate the checkstyle file

@jugglinmike
Copy link
Member

@ohmirocks This issue was closed from commit 4ac15f6 , which was intended to implement the requested feature. If it is not working for you, we'd certainly appreciate an example which demonstrates your problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants