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 3 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
---

Fix `declaration-block-no-redundant-longhand-properties` false positives for `inherit` keyword
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -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:

<!-- prettier-ignore -->
```css
a {
margin-top: 1px;
margin-right: 2px;
margin-bottom: 3px;
margin-left: inherit;
}
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this as our patterns don't tend to show edge cases.

We can add something to do extended description at the top instead. For example, expand the following line

This rule will only complain if you've used the longhand equivalent of all the properties that the shorthand will set.

To:

"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."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review! I removed a description of edge case. 616a536
Then, I updated the description to your suggestion. f442a05

## Optional secondary options

### `ignoreShorthands: ["/regex/", /regex/, "string"]`
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 longhandMustValues = ['inherit'];
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

/** @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 (longhandMustValues.includes(decl.value)) {
return;
}

const prop = decl.prop.toLowerCase();
const unprefixedProp = vendor.unprefixed(prop);
const prefix = vendor.prefix(prop);
Expand Down