diff --git a/.changeset/fair-oranges-love.md b/.changeset/fair-oranges-love.md new file mode 100644 index 0000000000..c410c6befe --- /dev/null +++ b/.changeset/fair-oranges-love.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword 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: 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..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,6 +20,8 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties', }; +const IGNORED_VALUES = new Set(['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 (IGNORED_VALUES.has(decl.value)) { + return; + } + const prop = decl.prop.toLowerCase(); const unprefixedProp = vendor.unprefixed(prop); const prefix = vendor.prefix(prop);