Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Disable eslint no-unused-vars warning on global functions

If you are not work­ing in a nodejs or com­monjs or mod­u­lar envi­ron­ment, and you have func­tions that are defined in the global scope in a dif­fer­ent file, you have prob­a­bly noticed that eslint com­plains with the no-unused-vars lint error.

The only way that ive found that actu­ally pre­vents eslint from com­plain­ing is by adding an eslint rule for a sin­gle line.
You could also poten­tially add it to the glob­als object in your .eslin­trc file but I believe that leaks con­cerns and adds an extra step towards maintenance.

Here’s how its done.

// This is my global function that will used in another file
function foo(options) { // eslint-disable-line no-unused-vars 
}

NOTE: One of the other things I tried was adding /* exported foo */ at the top of my file, but for some rea­son it didn’t work. Just putting it out there in case some­one else gets lucky.

Ryan Sukale

Ryan is a UX engineer living in San Francisco, California.

You may also like...