From 5b00e0f878105624c014acfc025b063bb73dcdc8 Mon Sep 17 00:00:00 2001 From: jasikpark Date: Fri, 30 Sep 2022 18:45:39 +0000 Subject: [PATCH 01/14] Add test for passing extends to stylelint overrides --- lib/__tests__/applyOverrides.test.js | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/__tests__/applyOverrides.test.js b/lib/__tests__/applyOverrides.test.js index c9eefd1310..30b255841b 100644 --- a/lib/__tests__/applyOverrides.test.js +++ b/lib/__tests__/applyOverrides.test.js @@ -198,6 +198,45 @@ describe('two matching overrides', () => { expect(applied).toEqual(expectedConfig); }); + + test('with extends', () => { + const config = { + extends: ['stylelint-config1'], + rules: { + 'block-no-empty': true, + 'unit-disallowed-list': ['px'], + }, + overrides: [ + { + files: ['*.module.css'], + extends: ['stylelint-config2'], + rules: { + 'color-no-hex': true, + }, + }, + { + files: ['*.css'], + extends: ['stylelint-config3'], + rules: { + 'block-no-empty': null, + }, + }, + ], + }; + + const expectedConfig = { + extends: ['stylelint-config1', 'stylelint-config2', 'stylelint-config3'], + rules: { + 'block-no-empty': null, + 'unit-disallowed-list': ['px'], + 'color-no-hex': true, + }, + }; + + const applied = applyOverrides(config, __dirname, path.join(__dirname, 'style.module.css')); + + expect(applied).toEqual(expectedConfig); + }); }); describe('no matching overrides', () => { From 40298f6c491d01597d68d8fb011c587ccdd6baf9 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Tue, 4 Oct 2022 16:15:25 -0500 Subject: [PATCH 02/14] Add docs, merge "extends" in overrides This is an incremental commit, I think I need an explicit list of what should get merged how --- docs/user-guide/configure.md | 2 ++ lib/augmentConfig.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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) { From 0fe1ad69983108cd980fad0a2df8c18d0be9620d Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Tue, 4 Oct 2022 16:28:41 -0500 Subject: [PATCH 03/14] Actually return the merged value --- lib/augmentConfig.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/augmentConfig.js b/lib/augmentConfig.js index ceb7402f62..7ff45b1ee7 100644 --- a/lib/augmentConfig.js +++ b/lib/augmentConfig.js @@ -290,7 +290,7 @@ function mergeConfigs(a, b) { } } - /** @type {{extends: StyleLintConfigExtends[]}} */ + /** @type {{extends: StyleLintConfigExtends}} */ const extendsMerger = {}; if (a.extends || b.extends) { @@ -314,6 +314,7 @@ function mergeConfigs(a, b) { const result = { ...a, ...b, + ...extendsMerger, ...processorMerger, ...pluginMerger, ...overridesMerger, From ee96de54bfa901fbe648b8c6e8f33069477a04e5 Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Thu, 6 Oct 2022 09:25:22 +0100 Subject: [PATCH 04/14] Create grumpy-scissors-watch.md --- .changeset/grumpy-scissors-watch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/grumpy-scissors-watch.md diff --git a/.changeset/grumpy-scissors-watch.md b/.changeset/grumpy-scissors-watch.md new file mode 100644 index 0000000000..dc4834696c --- /dev/null +++ b/.changeset/grumpy-scissors-watch.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `extends` in `overrides` to be consistent with `plugins` behaviour From c331d7d9b8b28af7e5bd548e33ac8e4113ebb5f5 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Fri, 7 Oct 2022 12:45:38 -0500 Subject: [PATCH 05/14] Update docs/user-guide/configure.md Co-authored-by: Richard Hallows --- docs/user-guide/configure.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user-guide/configure.md b/docs/user-guide/configure.md index 5505f9acdb..5e72f91f06 100644 --- a/docs/user-guide/configure.md +++ b/docs/user-guide/configure.md @@ -297,8 +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. +- `customSyntax` will be replaced by overrides. +- `plugins`, `extends`, `rules`, etc. will be appended. ## `defaultSeverity` From 37e06f492fe7b1a3f6390bc0e1bc28740708d05e Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Tue, 11 Oct 2022 11:35:45 +0100 Subject: [PATCH 06/14] Update grumpy-scissors-watch.md --- .changeset/grumpy-scissors-watch.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/grumpy-scissors-watch.md b/.changeset/grumpy-scissors-watch.md index dc4834696c..1643381d1c 100644 --- a/.changeset/grumpy-scissors-watch.md +++ b/.changeset/grumpy-scissors-watch.md @@ -1,5 +1,5 @@ --- -"stylelint": patch +"stylelint": major --- -Fixed: `extends` in `overrides` to be consistent with `plugins` behaviour +Change: `extends` in `overrides` to be consistent with `plugins` behaviour From 1e176e4f8240ae6568d7add39a1f9573222647a1 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Wed, 12 Oct 2022 17:33:47 -0500 Subject: [PATCH 07/14] Add recommended changelog explainer --- .changeset/grumpy-scissors-watch.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.changeset/grumpy-scissors-watch.md b/.changeset/grumpy-scissors-watch.md index 1643381d1c..b931e6f5d4 100644 --- a/.changeset/grumpy-scissors-watch.md +++ b/.changeset/grumpy-scissors-watch.md @@ -3,3 +3,23 @@ --- Change: `extends` in `overrides` to be consistent with `plugins` behaviour + +`overrides.extends` is fixed to make consistency with the `overrides.plugins` behavior and be merged not replaced. + +If you would like to keep the previous behavior, you would need to change your config as below: + +```diff json +{ +- "extends": ["config-a"] + "overrides": [ + { + "rules": ["*.module.css"], + "extends": ["config-b"] + }, ++ { ++ "rules": ["*.css"], ++ "extends": ["config-a"] ++ }, + ] +} +``` \ No newline at end of file From cddf24231bd4475c0af1b594ef6e247cd8507a3a Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Wed, 12 Oct 2022 20:54:39 -0500 Subject: [PATCH 08/14] make prettier happy :) --- .changeset/grumpy-scissors-watch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/grumpy-scissors-watch.md b/.changeset/grumpy-scissors-watch.md index b931e6f5d4..7238e25ab3 100644 --- a/.changeset/grumpy-scissors-watch.md +++ b/.changeset/grumpy-scissors-watch.md @@ -22,4 +22,4 @@ If you would like to keep the previous behavior, you would need to change your c + }, ] } -``` \ No newline at end of file +``` From 8d082155079e6e461b5c4e38c251a2f70949c19b Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Mon, 24 Oct 2022 14:53:00 +0100 Subject: [PATCH 09/14] Update grumpy-scissors-watch.md --- .changeset/grumpy-scissors-watch.md | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/.changeset/grumpy-scissors-watch.md b/.changeset/grumpy-scissors-watch.md index 7238e25ab3..7979660b68 100644 --- a/.changeset/grumpy-scissors-watch.md +++ b/.changeset/grumpy-scissors-watch.md @@ -2,24 +2,4 @@ "stylelint": major --- -Change: `extends` in `overrides` to be consistent with `plugins` behaviour - -`overrides.extends` is fixed to make consistency with the `overrides.plugins` behavior and be merged not replaced. - -If you would like to keep the previous behavior, you would need to change your config as below: - -```diff json -{ -- "extends": ["config-a"] - "overrides": [ - { - "rules": ["*.module.css"], - "extends": ["config-b"] - }, -+ { -+ "rules": ["*.css"], -+ "extends": ["config-a"] -+ }, - ] -} -``` +Change: `extends` in `overrides` to merge to be consistent with `plugins` behaviour From 77e5e2a94bbcd2bf8f788ec5123b0d81c23b9086 Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Mon, 24 Oct 2022 14:57:13 +0100 Subject: [PATCH 10/14] Create to-15.md --- docs/migration-guide/to-15.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/migration-guide/to-15.md diff --git a/docs/migration-guide/to-15.md b/docs/migration-guide/to-15.md new file mode 100644 index 0000000000..0bb9b41170 --- /dev/null +++ b/docs/migration-guide/to-15.md @@ -0,0 +1,23 @@ +# Migrating to 15.0.0 + +## Change of `overrides.extends` behaviour + +The `overrides.extends` behaviour was changed to be merged not replaced, to make it consistency with the `overrides.plugins`. + +If you would like to keep the previous behavior, you should change your config to: + +```diff json +{ +- "extends": ["config-a"] + "overrides": [ + { + "rules": ["*.module.css"], + "extends": ["config-b"] + }, ++ { ++ "rules": ["*.css"], ++ "extends": ["config-a"] ++ }, + ] +} +``` From ce0dbea7508ba9aef67f13e667de790e80e5faca Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Mon, 24 Oct 2022 15:06:25 +0100 Subject: [PATCH 11/14] Update to-15.md --- docs/migration-guide/to-15.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/migration-guide/to-15.md b/docs/migration-guide/to-15.md index 0bb9b41170..c94353fb57 100644 --- a/docs/migration-guide/to-15.md +++ b/docs/migration-guide/to-15.md @@ -1,8 +1,8 @@ # Migrating to 15.0.0 -## Change of `overrides.extends` behaviour +## Change of `overrides.`extends` behavior -The `overrides.extends` behaviour was changed to be merged not replaced, to make it consistency with the `overrides.plugins`. +We changed the `overrides.extends` behavior to merge rather than replace, to make it consistent with the `overrides.plugins`. If you would like to keep the previous behavior, you should change your config to: From e16131cd12dcbe08aded473d57caeea4f586b36d Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Tue, 25 Oct 2022 10:14:39 +0100 Subject: [PATCH 12/14] Update docs/migration-guide/to-15.md Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> --- docs/migration-guide/to-15.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration-guide/to-15.md b/docs/migration-guide/to-15.md index c94353fb57..c2fbca34fa 100644 --- a/docs/migration-guide/to-15.md +++ b/docs/migration-guide/to-15.md @@ -17,7 +17,7 @@ If you would like to keep the previous behavior, you should change your config t + { + "rules": ["*.css"], + "extends": ["config-a"] -+ }, ++ } ] } ``` From e825a05dbfb8c8b06271732303a2055dc65a7ff1 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:56:09 +0900 Subject: [PATCH 13/14] Update docs/migration-guide/to-15.md --- docs/migration-guide/to-15.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration-guide/to-15.md b/docs/migration-guide/to-15.md index c2fbca34fa..d913f6083d 100644 --- a/docs/migration-guide/to-15.md +++ b/docs/migration-guide/to-15.md @@ -1,6 +1,6 @@ # Migrating to 15.0.0 -## Change of `overrides.`extends` behavior +## Change of `overrides.extends` behavior We changed the `overrides.extends` behavior to merge rather than replace, to make it consistent with the `overrides.plugins`. From 01cd74e6803a3b4f75758421867324f2d677a0c9 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:57:36 +0900 Subject: [PATCH 14/14] Update docs/migration-guide/to-15.md --- docs/migration-guide/to-15.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration-guide/to-15.md b/docs/migration-guide/to-15.md index d913f6083d..dfdfdd7948 100644 --- a/docs/migration-guide/to-15.md +++ b/docs/migration-guide/to-15.md @@ -8,7 +8,7 @@ If you would like to keep the previous behavior, you should change your config t ```diff json { -- "extends": ["config-a"] +- "extends": ["config-a"], "overrides": [ { "rules": ["*.module.css"],