Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 440929

Summary: [eslint] create a "no-shadow-global" rule
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: JS ToolsAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: Michael_Rennie
Version: 5.0   
Target Milestone: 9.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Mark Macdonald CLA 2014-07-31 16:11:51 EDT
The "browser" environment, which we typically code against, exports a ton of global symbols, including many commonly used variable names:
> close, closed, find, focus, length, location, name, open, parent, stop, top, ...

1) I've often made the mistake of defining some local variable that shadows one of these names:

> /*eslint-env browser*/
> var name = file.Name;
> console.log("Writing to file:" + name);

2) Later when I refactor the code and delete/rename the variable, I forget to update some references. Those references now resolve to the global symbol, so there is no "{x} is undefined" warning from the linter:

> /*eslint-env browser*/
> var filename = file.Name;
> console.log("Writing to file:" + name); // now refers to window.name

3) The code fails at runtime.

We should consider making a rule that warns when a local variable shadows a global symbol:

> var name = file.Name;      // 'name' shadows a symbol from the 'browser' environment.

This could check parameter names as well as variable names.