From 9e4ada39634ce8ea3a74f535f5e74902163b771f Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 06:46:31 +0900 Subject: [PATCH 1/7] Ignore `inherit` in `declaration-block-no-redundant-longhand-properties` --- .../__tests__/index.js | 3 +++ .../index.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js b/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js index 297020b9f3..680a75369c 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/__tests__/index.js @@ -13,6 +13,9 @@ testRule({ { code: 'a { margin-right: 10px; margin-top: 20px; margin-bottom: 30px; }', }, + { + code: 'a { margin-left: inherit; margin-right: 10px; margin-top: 20px; margin-bottom: 30px; }', + }, { code: 'a { padding-left: 10px; margin-right: 10px; margin-top: 20px; margin-bottom: 30px; }', }, diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js index dec1ec8dfc..b351b9df14 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js @@ -20,6 +20,8 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties', }; +const longhandMustValues = ['inherit']; + /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { return (root, result) => { @@ -61,6 +63,10 @@ const rule = (primary, secondaryOptions) => { const longhandDeclarations = new Map(); eachDecl((decl) => { + if (longhandMustValues.includes(decl.value)) { + return; + } + const prop = decl.prop.toLowerCase(); const unprefixedProp = vendor.unprefixed(prop); const prefix = vendor.prefix(prop); From 94a21c3dd197144ac92c4803641b86c4fb6402c0 Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 07:00:22 +0900 Subject: [PATCH 2/7] Add example to docs --- .../README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/README.md b/lib/rules/declaration-block-no-redundant-longhand-properties/README.md index 5955ce0a5e..08c59a6d5a 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/README.md +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/README.md @@ -145,6 +145,18 @@ a { } ``` +You should use a longhand property to have only the specific value inherited. So, the following patterns are also not considered problems: + + +```css +a { + margin-top: 1px; + margin-right: 2px; + margin-bottom: 3px; + margin-left: inherit; +} +``` + ## Optional secondary options ### `ignoreShorthands: ["/regex/", /regex/, "string"]` From 84059cbaf134c213a804633de27f66043495b6a0 Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 07:14:13 +0900 Subject: [PATCH 3/7] Add changeset --- .changeset/fair-oranges-love.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fair-oranges-love.md diff --git a/.changeset/fair-oranges-love.md b/.changeset/fair-oranges-love.md new file mode 100644 index 0000000000..6996a2334b --- /dev/null +++ b/.changeset/fair-oranges-love.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fix `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword From 117e5f63aa66a80e58ef28223fff0bace1c5b34a Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 21:31:41 +0900 Subject: [PATCH 4/7] Fix changeset comment --- .changeset/fair-oranges-love.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fair-oranges-love.md b/.changeset/fair-oranges-love.md index 6996a2334b..c410c6befe 100644 --- a/.changeset/fair-oranges-love.md +++ b/.changeset/fair-oranges-love.md @@ -2,4 +2,4 @@ "stylelint": patch --- -Fix `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword +Fixed: `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword From 39f4f273aba6354ce2ef8d4245bbf55dbb2c8b0d Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 21:35:03 +0900 Subject: [PATCH 5/7] Fix to use `Set` --- .../index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js index b351b9df14..7e841811ac 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/index.js +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/index.js @@ -20,7 +20,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties', }; -const longhandMustValues = ['inherit']; +const IGNORED_VALUES = new Set(['inherit']); /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { @@ -63,7 +63,7 @@ const rule = (primary, secondaryOptions) => { const longhandDeclarations = new Map(); eachDecl((decl) => { - if (longhandMustValues.includes(decl.value)) { + if (IGNORED_VALUES.has(decl.value)) { return; } From 616a536d977f7a6c6ce283634a942737045fce77 Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 21:36:12 +0900 Subject: [PATCH 6/7] Revert "Add example to docs" This reverts commit 94a21c3dd197144ac92c4803641b86c4fb6402c0. --- .../README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/README.md b/lib/rules/declaration-block-no-redundant-longhand-properties/README.md index 08c59a6d5a..5955ce0a5e 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/README.md +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/README.md @@ -145,18 +145,6 @@ a { } ``` -You should use a longhand property to have only the specific value inherited. So, the following patterns are also not considered problems: - - -```css -a { - margin-top: 1px; - margin-right: 2px; - margin-bottom: 3px; - margin-left: inherit; -} -``` - ## Optional secondary options ### `ignoreShorthands: ["/regex/", /regex/, "string"]` From f442a05438dcbcb783ee6c388f34dc801783e47a Mon Sep 17 00:00:00 2001 From: kimulaco Date: Fri, 21 Oct 2022 21:48:32 +0900 Subject: [PATCH 7/7] Add description about inherit --- .../README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/declaration-block-no-redundant-longhand-properties/README.md b/lib/rules/declaration-block-no-redundant-longhand-properties/README.md index 5955ce0a5e..1b795cb52e 100644 --- a/lib/rules/declaration-block-no-redundant-longhand-properties/README.md +++ b/lib/rules/declaration-block-no-redundant-longhand-properties/README.md @@ -22,7 +22,7 @@ a { } ``` -This rule will only complain if you've used the longhand equivalent of _all_ the properties that the shorthand will set. +This rule will only complain if you've used the longhand equivalent of _all_ the properties that the shorthand will set and if their values are not `inherit`. This rule complains when the following shorthand properties can be used: