Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: avoid crashing when using baseConfig with extends (fixes #8791) (#…
…8797)

Due to a bug, an invalid Config instance was getting used when applying extensions to a `baseConfig` object. This updates the `Config` constructor to use the correct context, and to make sure the config cache exists when the `baseConfig` is evaluated.
  • Loading branch information
not-an-aardvark committed Jun 26, 2017
1 parent 03213bb commit 0d041e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/config.js
Expand Up @@ -66,13 +66,14 @@ class Config {
this.parser = options.parser;
this.parserOptions = options.parserOptions || {};

this.configCache = new ConfigCache();

this.baseConfig = options.baseConfig
? ConfigOps.merge({}, ConfigFile.loadObject(options.baseConfig, this))
: { rules: {} };
this.baseConfig.filePath = "";
this.baseConfig.baseDirectory = this.options.cwd;

this.configCache = new ConfigCache();
this.configCache.setConfig(this.baseConfig.filePath, this.baseConfig);
this.configCache.setMergedVectorConfig(this.baseConfig.filePath, this.baseConfig);

Expand Down
5 changes: 3 additions & 2 deletions lib/config/config-file.js
Expand Up @@ -560,11 +560,12 @@ function loadFromDisk(resolvedPath, configContext) {
/**
* Loads a config object, applying extends if present.
* @param {Object} configObject a config object to load
* @param {Config} configContext Context for the config instance
* @returns {Object} the config object with extends applied if present, or the passed config if not
* @private
*/
function loadObject(configObject) {
return configObject.extends ? applyExtends(configObject, "") : configObject;
function loadObject(configObject, configContext) {
return configObject.extends ? applyExtends(configObject, configContext, "") : configObject;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/config.js
Expand Up @@ -158,6 +158,24 @@ describe("Config", () => {
assert.deepEqual(customBaseConfig, { foo: "bar" });
assert.equal(configHelper.options.format, "foo");
});

it("should create config object when using baseConfig with extends", () => {
const customBaseConfig = {
extends: path.resolve(__dirname, "..", "fixtures", "config-extends", "array", ".eslintrc")
};
const configHelper = new Config({ baseConfig: customBaseConfig }, linter);

assert.deepEqual(configHelper.baseConfig.env, {
browser: false,
es6: true,
node: true
});
assert.deepEqual(configHelper.baseConfig.rules, {
"no-empty": 1,
"comma-dangle": 2,
"no-console": 2
});
});
});

describe("findLocalConfigFiles()", () => {
Expand Down

0 comments on commit 0d041e7

Please sign in to comment.