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

Comments

Projects
None yet
7 participants
@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

This comment has been minimized.

Copy link

Couto commented Sep 10, 2012

+1

@satazor

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

kkapsner commented Sep 12, 2012

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

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

@valueof valueof closed this in 4ac15f6 Dec 16, 2012

jugglinmike added a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014

Ability to disable 'unused' per function.
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

This comment has been minimized.

Copy link

ohmirocks commented Feb 20, 2015

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

@jugglinmike

This comment has been minimized.

Copy link
Member

jugglinmike commented Feb 20, 2015

@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