Skip to content

Commit

Permalink
Add docs, merge "extends" in overrides
Browse files Browse the repository at this point in the history
This is an incremental commit, I think I need an explicit list of what should get merged how
  • Loading branch information
jasikpark committed Oct 4, 2022
1 parent 576598e commit d471842
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/user-guide/configure.md
Expand Up @@ -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`

Expand Down
18 changes: 17 additions & 1 deletion lib/augmentConfig.js
Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d471842

Please sign in to comment.