Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix declaration-block-no-redundant-longhand-properties false positives for inherit keyword #6419

Merged
merged 7 commits into from Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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