diff --git a/docs/user-guide/configure.md b/docs/user-guide/configure.md index 4fb0e6c8a7..5505f9acdb 100644 --- a/docs/user-guide/configure.md +++ b/docs/user-guide/configure.md @@ -297,6 +297,8 @@ Here is how overrides work in a configuration file: - Glob pattern overrides have higher precedence than the regular configuration in the same config file. Multiple overrides within the same config are applied in order. That is, the last override block in a config file always has the highest precedence. - A glob specific configuration works almost the same as any other Stylelint config. Override blocks can contain any configuration options that are valid in a regular config. - Multiple glob patterns can be provided within a single override block. A file must match at least one of the supplied patterns for the configuration to apply. +- Singular config values like `defaultSeverity` and `customSyntax` will be replaced by overrides. +- Complex config values like `plugins`, `extends`, `rules`, etc. will be appended. ## `defaultSeverity` diff --git a/lib/augmentConfig.js b/lib/augmentConfig.js index 636ffde31f..ceb7402f62 100644 --- a/lib/augmentConfig.js +++ b/lib/augmentConfig.js @@ -8,6 +8,7 @@ const normalizeAllRuleSettings = require('./normalizeAllRuleSettings'); const normalizePath = require('normalize-path'); const path = require('path'); +/** @typedef {import('stylelint').ConfigExtends} StyleLintConfigExtends */ /** @typedef {import('stylelint').ConfigPlugins} StylelintConfigPlugins */ /** @typedef {import('stylelint').ConfigProcessor} StylelintConfigProcessor */ /** @typedef {import('stylelint').ConfigProcessors} StylelintConfigProcessors */ @@ -234,7 +235,7 @@ function loadExtendedConfig(stylelint, configDir, extendLookup) { /** * When merging configs (via extends) - * - plugin and processor arrays are joined + * - plugin, extends, overrides, processor arrays are joined * - rules are merged via Object.assign, so there is no attempt made to * merge any given rule's settings. If b contains the same rule as a, * b's rule settings will override a's rule settings entirely. @@ -289,6 +290,21 @@ function mergeConfigs(a, b) { } } + /** @type {{extends: StyleLintConfigExtends[]}} */ + const extendsMerger = {}; + + if (a.extends || b.extends) { + extendsMerger.extends = []; + + if (a.extends) { + extendsMerger.extends = extendsMerger.extends.concat(a.extends); + } + + if (b.extends) { + extendsMerger.extends = [...new Set(extendsMerger.extends.concat(b.extends))]; + } + } + const rulesMerger = {}; if (a.rules || b.rules) {