Permalink
Browse files

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 0d041e715927d28ef1c6f4e72c539148404966a5
Showing with 23 additions and 3 deletions.
  1. +2 −1 lib/config.js
  2. +3 −2 lib/config/config-file.js
  3. +18 −0 tests/lib/config.js
View
@@ -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);
@@ -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;
}
/**
View
@@ -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()", () => {

0 comments on commit 0d041e7

Please sign in to comment.