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 with basic keywords #6748

Conversation

mattxwang
Copy link
Member

@mattxwang mattxwang commented Mar 30, 2023

Which issue, if any, is this issue related to?

Closes #6738.

Is there anything in the PR that needs further explanation?

The scope of this PR is broader than autofixing, since we also shouldn't flag instances which use a basic keyword. Let me know if additional test cases / documentation are desired!

Note that we already had this feature for inherit; this PR just expands it to use basicKeywords.

If we'd like, we could also create a more "aggressive" approach that converts

margin-top: inset;
margin-bottom: inset;
margin-right: inset;
margin-left: inset;

to

margin: inset;

which is valid (to my understanding). The rule doesn't currently behave this way with inherit; but, happy to add this if we think it's helpful!


Spec ref for shorthand properties not supporting CSS-wide keywords:

If a shorthand is specified as one of the CSS-wide keywords [css-values-3], it sets all of its sub-properties to that keyword, including any that are reset-only sub-properties. (Note that these keywords cannot be combined with other values in a single declaration, not even in a shorthand.)

@changeset-bot
Copy link

changeset-bot bot commented Mar 30, 2023

🦋 Changeset detected

Latest commit: ceafc35

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mattxwang mattxwang force-pushed the fix-declaration-block-no-redundant-longhand-properties-basic-keywords branch from 2ff0bd7 to 41b76d3 Compare March 30, 2023 06:04
@ybiquitous
Copy link
Member

@mattxwang Thanks for the pull request!

If we'd like, we could also create a more "aggressive" approach that converts

How do you estimate the work? We could address it with another pull request if it is a bit hard.
Of course, if you prefer, you can do it with this pull request. I'll leave it to you.

@mattxwang
Copy link
Member Author

How do you estimate the work? We could address it with another pull request if it is a bit hard.

I think leaving it to another PR is a good idea; in particular, this PR reduces false positives, while the other change would reduce false negatives. I can open an issue and allow for some discussion after merging this PR!

mattxwang and others added 2 commits March 31, 2023 00:01
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM 👍🏼

@ybiquitous ybiquitous merged commit 874ee84 into main Mar 31, 2023
14 checks passed
@ybiquitous ybiquitous deleted the fix-declaration-block-no-redundant-longhand-properties-basic-keywords branch March 31, 2023 13:29
@pbojinov
Copy link

pbojinov commented Apr 11, 2023

After upgrading to 15.4.0 I started noticing declaration-block-no-redundant-longhand-properties come up for styles that have a top, right, bottom, left set to 0 for position absolutes. What would be the best way to handle this inset besides disabling the next line?

.example {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  /* stylelint-disable-next-line declaration-block-no-redundant-longhand-properties */
  left: 0;
}

@ybiquitous
Copy link
Member

ybiquitous commented Apr 11, 2023

@pbojinov You mean you don't want to use the inset shorthand, right? If so, using a disabled comment is a way as you commented.

As another way, you can either turn off the rule or ignore only inset via a config like this:

{
  "rules": {
    "declaration-block-no-redundant-longhand-properties": null
  }
}
{
  "rules": {
    "declaration-block-no-redundant-longhand-properties": [true, {"ignoreShorthands": ["inset"]}]
  }
}

@Mouvedia
Copy link
Member

related: #7214 (comment)

@mattxwang
Copy link
Member Author

related: #7214 (comment)

Sorry, I think I'm missing something - how is this related to the linked comment? I can submit a fix if so (since I probably introduced the bug 😓 )

@Mouvedia
Copy link
Member

Mouvedia commented Oct 12, 2023

It's just a reminder so that, if we tackle "CSS-wide keywords" for this rule, we take into account what has been learned from this PR. You don't have to do anything :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix declaration-block-no-redundant-longhand-properties autofix with basic keywords
4 participants