Skip to content

Commit

Permalink
Fix declaration-block-no-redundant-longhand-properties false positi…
Browse files Browse the repository at this point in the history
…ves for `inherit` keyword (#6419)
  • Loading branch information
kimulaco committed Oct 21, 2022
1 parent d171517 commit e3585ed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fair-oranges-love.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword
Expand Up @@ -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:

Expand Down
Expand Up @@ -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; }',
},
Expand Down
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e3585ed

Please sign in to comment.