Skip to content

Commit

Permalink
Fix: eslint.verify should not mutate config argument (fixes #8329) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto authored and vitorbal committed Mar 28, 2017
1 parent 927de90 commit 3146167
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/eslint.js
Expand Up @@ -778,17 +778,18 @@ module.exports = (function() {
// search and apply "eslint-env *".
const envInFile = findEslintEnv(text || textOrSourceCode.text);

config = Object.assign({}, config);

if (envInFile) {
if (!config || !config.env) {
config = Object.assign({}, config || {}, { env: envInFile });
} else {
config = Object.assign({}, config);
if (config.env) {
config.env = Object.assign({}, config.env, envInFile);
} else {
config.env = envInFile;
}
}

// process initial config to make it safe to extend
config = prepareConfig(config || {});
config = prepareConfig(config);

// only do this for text
if (text !== null) {
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/eslint.js
Expand Up @@ -3425,6 +3425,16 @@ describe("eslint", () => {

assert(result.length === 0);
});


it("should not modify config object passed as argument", () => {
const config = {};

Object.freeze(config);
assert.doesNotThrow(() => {
eslint.verify("var foo", config);
});
});
});

describe("Variables and references", () => {
Expand Down

0 comments on commit 3146167

Please sign in to comment.