Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint: disable warning - `defined but never used` for specific function?

So I have this function:

function render(){     // do stuff } 

I do not call that function, because it is called from html as an event function, like:

<textarea id="input" class="input-box" onkeyup="render()"></textarea> 

Well eslint does not see that, so it gives that warning (render is defined, but never used). Is there a way to specify that function is called elsewhere? Or just mute the warning?

For example if global variable is used, I can do /* global SomeVar*/ and it will mute warning of not defined variable. Maybe something similar could be done on functions like in example?

like image 624
Andrius Avatar asked Jul 30 '17 12:07

Andrius


People also ask

How do I get rid of the ESLint warning?

disable warnings eslintUse /* eslint-disable */ to ignore all warnings in a file. You may use special comments to disable some warnings. Use // eslint-disable-next-line to ignore the next line. Use /* eslint-disable */ to ignore all warnings in a file.

How do you fix no-unused-vars in ESLint?

Add no-unused-vars-rest to the plugins section of your . eslintrc configuration file, and configure the rule under the rules section. Don't forget to disable the core rule no-unused-vars . Alternatively you may use the plugin's recommended configuration, which applies the above configuration.

How do I disable typescript ESLint?

If you are using ESLint and you need to disable the next line, use this code: eslint-disable-next-line.


2 Answers

Provide a config comment telling it to ignore that rule (defined but never used is the no-unused-vars rule)

function render() { // eslint-disable-line no-unused-vars     // do stuff     var x; // still raises defined but never used } 
like image 57
Alex K. Avatar answered Sep 28 '22 10:09

Alex K.


If you dont want to change the code.

ESLint provides both a way to disable, both to enable the linting via comments. You only added before functions /* eslint-disable */ and after functions /* eslint-enable */

Example

/* eslint-disable */ <-- Before function  function render(){    // do stuff }  /* eslint-enable */  <-- After function 

More info

like image 30
Alex Montoya Avatar answered Sep 28 '22 10:09

Alex Montoya