Skip to content
Permalink
Browse files

Fix: env is rewritten by modules (fixes #4814)

  • Loading branch information...
mysticatea committed Dec 27, 2015
1 parent 6a607bd commit d3e8179b0de73e3275978d3d30089f8a6d5c2320
Showing with 31 additions and 1 deletion.
  1. +1 −1 lib/eslint.js
  2. +30 −0 tests/lib/eslint.js
@@ -393,7 +393,7 @@ function prepareConfig(config) {
if (typeof config.env === "object") {
Object.keys(config.env).forEach(function(env) {
if (config.env[env] && environments[env] && environments[env].parserOptions) {
assign(parserOptions, environments[env].parserOptions);
parserOptions = ConfigOps.merge(parserOptions, environments[env].parserOptions);
}
});
}
@@ -3189,6 +3189,36 @@ describe("eslint", function() {
eslint.verify("var { a='a' } = {};", { parserOptions: { ecmaVersion: 6 }});
});

it("should not rewrite env setting in core (https://github.com/eslint/eslint/issues/4814)", function() {
// This test focuses on the instance of https://github.com/eslint/eslint/blob/v2.0.0-alpha-2/conf/environments.js#L26-L28

// This `verify()` takes the instance and runs https://github.com/eslint/eslint/blob/v2.0.0-alpha-2/lib/eslint.js#L416
eslint.defineRule("test", function() {
return {};
});
eslint.verify("var a = 0;", {
env: {node: true},
parserOptions: {sourceType: "module"},
rules: {test: 2}
});

// This `verify()` takes the instance and tests that the instance was not modified.
var ok = false;
eslint.defineRule("test", function(context) {
assert(
context.parserOptions.ecmaFeatures.globalReturn,
"`ecmaFeatures.globalReturn` of the node environment should not be modified."
);
ok = true;
return {};
});
eslint.verify("var a = 0;", {
env: {node: true},
rules: {test: 2}
});

assert(ok);
});
});

// only test in Node.js, not browser

0 comments on commit d3e8179

Please sign in to comment.
You can’t perform that action at this time.