1

Can anyone give me some pointers on fixing a warning I'm getting with JSLint.

I have the following code:

/* global window, define, module */
(function(global, factory) {
    var Gauge = factory(global);
    if(typeof define === "function" && define.amd) {
      // AMD support
      define(function() {return Gauge;});
    }else if(typeof module === "object" && module.exports) {
      // CommonJS support
      module.exports = Gauge;
    }else {
      // We are probably running in the browser
      global.Gauge = Gauge;
    }
})(typeof window === "undefined" ? this : window, function(global, undefined) {

On the final line (typeof window === "undefined" ... I'm getting this warning:

Line 14: Shadowing of global property 'undefined' no-shadow-restricted-names

I'd like to get rid of this warning if possible.

CLiown
  • 13,665
  • 48
  • 124
  • 205
  • 1
    I guess that the problem is that you are passing undefined to your function with alias factory and so you may potentially modify it, so that's why the no-shadow-restricted-names gives you a warning, you may try using function(global, factory = undefined) ... – Silvio Biasiol Feb 18 '19 at 15:59
  • 1
    Thank you @SilvioBiasiol thats fixed the warning. – CLiown Feb 18 '19 at 16:08
  • No problem, happy to help :) – Silvio Biasiol Feb 18 '19 at 16:13

1 Answers1

3

You'll either want to drop the undefined parameter from the function(global, undefined) { function, or disable the warning on that particular line (since it guards against other scripts failing to heed this warning). Alternatively, use a build system to automatically prepend this UMD header to your modules, and run jslint only on the source.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375