Search code examples
javascripteslint

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


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 a global variable is used, I can do /* global SomeVar*/ and it will mute the warning of a not-defined variable. Maybe something similar could be done on functions like in the example?


Solution

  • 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
    }