Skip to content

Commit cb74b87

Browse files
not-an-aardvarkilyavolodin
authored andcommitted
Fix: avoid adding globals when an env is used with false (fixes #9202) (#9203)
* Fix: avoid adding globals when an env is used with `false` (fixes #9202) This fixes a regression introduced in f005e24 (merged as part of 60c5148) where globals would get added to environments even when the env was set to `false` in a config file. * Add no-catch-shadow test
1 parent f9b7544 commit cb74b87

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/linter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function addDeclaredGlobals(program, globalScope, config, envContext) {
178178

179179
Object.assign(declaredGlobals, builtin);
180180

181-
Object.keys(config.env).forEach(name => {
181+
Object.keys(config.env).filter(name => config.env[name]).forEach(name => {
182182
const env = envContext.get(name),
183183
environmentGlobals = env && env.globals;
184184

tests/lib/rules/no-catch-shadow.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ ruleTester.run("no-catch-shadow", rule, {
3636
"module.exports = broken;"
3737
].join("\n"),
3838
parserOptions: { ecmaVersion: 6 }
39+
},
40+
{
41+
code: "try {} catch (error) {}",
42+
env: { shelljs: false }
3943
}
4044
],
4145
invalid: [

tests/lib/rules/no-redeclare.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ ruleTester.run("no-redeclare", rule, {
3535
{ code: "var top = 0;", env: { browser: true } },
3636
{ code: "var top = 0;", options: [{ builtinGlobals: true }] },
3737
{ code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaFeatures: { globalReturn: true } }, env: { browser: true } },
38-
{ code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { sourceType: "module" }, env: { browser: true } }
38+
{ code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { sourceType: "module" }, env: { browser: true } },
39+
{
40+
code: "var self = 1",
41+
options: [{ builtinGlobals: true }],
42+
env: { browser: false }
43+
}
3944
],
4045
invalid: [
4146
{ code: "var a = 3; var a = 10;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] },

0 commit comments

Comments
 (0)