Skip to content

Commit

Permalink
Fix extends in configOverrides (stylelint#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtheclark authored and sergesemashko committed Mar 3, 2017
1 parent c68fd82 commit 712a82d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
48 changes: 33 additions & 15 deletions lib/__tests__/standalone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,22 +323,40 @@ describe("standalone with config locatable from process.cwd not file", () => {
})
})

it("Setting `plugins` inside `configOverrides` object should overrides the ones set in `config` object", () => {
return standalone({
code: ".bar {}",
configBasedir: __dirname,
config: {
plugins: [],
rules: {
"plugin/warn-about-bar": "always",
describe("configOverrides", () => {
it("Setting `plugins` inside `**/__tests__/**` object should override the ones set in `config` object", () => {
return standalone({
code: ".bar {}",
configBasedir: __dirname,
config: {
plugins: [],
rules: {
"plugin/warn-about-bar": "always",
},
},
},
configOverrides: {
plugins: ["./fixtures/plugin-warn-about-bar"],
},
}).then((linted) => {
expect(linted.results[0].warnings.length).toBe(1)
expect(linted.results[0].warnings[0].text).toBe("found .bar (plugin/warn-about-bar)")
configOverrides: {
plugins: ["./fixtures/plugin-warn-about-bar"],
},
}).then((linted) => {
expect(linted.results[0].warnings.length).toBe(1)
expect(linted.results[0].warnings[0].text).toBe("found .bar (plugin/warn-about-bar)")
})
})

it("Setting `extends` inside `configOverrides` object should override the ones set in `config` object", () => {
return standalone({
code: ".bar {}",
configBasedir: __dirname,
config: {
extends: ["foo"],
},
configOverrides: {
extends: ["./fixtures/config-block-no-empty"],
},
}).then((linted) => {
expect(linted.results[0].warnings.length).toBe(1)
expect(linted.results[0].warnings[0].text).toContain("block-no-empty")
})
})
})

Expand Down
6 changes: 4 additions & 2 deletions lib/augmentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const FILE_NOT_FOUND_ERROR_CODE = "ENOENT"
function augmentConfigBasic(
stylelint/*: stylelint$internalApi*/,
config/*: stylelint$config*/,
configDir/*: string*/
configDir/*: string*/,
allowOverrides/*:: ?: boolean*/
)/*: Promise<stylelint$config>*/ {
return Promise.resolve().then(() => {
if (!allowOverrides) return config
return _.merge(config, stylelint._options.configOverrides)
}).then(augmentedConfig => {
return extendConfig(stylelint, augmentedConfig, configDir)
Expand Down Expand Up @@ -67,7 +69,7 @@ function augmentConfigFull(

const configDir = stylelint._options.configBasedir || path.dirname(filepath || "")

return augmentConfigBasic(stylelint, config, configDir).then(augmentedConfig => {
return augmentConfigBasic(stylelint, config, configDir, true).then(augmentedConfig => {
return addIgnorePatterns(stylelint, augmentedConfig)
}).then(augmentedConfig => {
return addPluginFunctions(augmentedConfig)
Expand Down

0 comments on commit 712a82d

Please sign in to comment.