Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: clone config before validating (fixes #12592) #13034

Merged
merged 16 commits into from Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/cli-engine/config-array-factory.js
Expand Up @@ -623,8 +623,11 @@ class ConfigArrayFactory {
* @private
*/
_normalizeConfigData(configData, ctx) {

validateConfigSchema(configData, ctx.name || ctx.filePath);
return this._normalizeObjectConfigData(configData, ctx);
const clonedConfig = JSON.parse(JSON.stringify(configData));
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved

return this._normalizeObjectConfigData(clonedConfig, ctx);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/config-file/cloned-config/eslintConfig.js
@@ -0,0 +1,4 @@
let errorConfig = ["error", {}];
module.exports = {
rules: { camelcase: errorConfig, "default-case": errorConfig }
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 1 addition & 0 deletions tests/fixtures/config-file/cloned-config/index.js
@@ -0,0 +1 @@
var someValue = "bar";
3 changes: 3 additions & 0 deletions tests/fixtures/config-file/cloned-config/inlineText.js
@@ -0,0 +1,3 @@
/*eslint default-case: ["error", {}]*/
/*eslint camelcase: ["error", {}]*/
var someValue = "bar";
26 changes: 26 additions & 0 deletions tests/lib/cli.js
Expand Up @@ -187,6 +187,7 @@ describe("cli", () => {
});
});


describe("when given a config with environment set to Node.js", () => {
it("should execute without any errors", async () => {
const configPath = getFixturePath("configurations", "env-node.json");
Expand Down Expand Up @@ -1160,4 +1161,29 @@ describe("cli", () => {
});
});

describe("testing the cloned config", () => {
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
anikethsaha marked this conversation as resolved.
Show resolved Hide resolved
describe("config file and input file", () => {
it("should not modify original configuration object", async () => {
const configPath = getFixturePath("config-file", "cloned-config", "eslintConfig.js");
const filePath = getFixturePath("config-file", "cloned-config", "index.js");
const args = `--config ${configPath} ${filePath}`;

const exit = await cli.execute(args);

assert.strictEqual(exit, 0);
});
});

describe("inline config and input file", () => {
it("should not modify original configuration object", async () => {
const filePath = getFixturePath("config-file", "cloned-config", "inlineText.js");
const args = `${filePath}`;

const exit = await cli.execute(args);

assert.strictEqual(exit, 0);
});
});
});

});