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

Add "ignoreLonghands": [] to declaration-block-no-redundant-longhand-properties #7232

Closed
Mouvedia opened this issue Oct 14, 2023 · 18 comments · Fixed by #7611
Closed

Add "ignoreLonghands": [] to declaration-block-no-redundant-longhand-properties #7232

Mouvedia opened this issue Oct 14, 2023 · 18 comments · Fixed by #7611
Assignees
Labels
status: wip is being worked on by someone type: new option a new option for an existing rule

Comments

@Mouvedia
Copy link
Member

Mouvedia commented Oct 14, 2023

use cases

rationale

If a browser doesn't support the new arity for a given shorthand, it will drop it altogether.
For example if we were to introduce an enhancement for the current fixer of text-decoration by adding support to
text-decoration-thickness, for a lot of users of the rule it would introduce a hard to detect regression.
They would have to rely on "ignoreShorthands": ["text-decoration"] which is arguably a downgrade compared to the status quo. Hence a new option is required to be more granular and cross-browser.

text-decoration

rationale for new fix

#6580 (comment)
#7060

without option

a {
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-color: green;
  text-decoration-thickness: 1px;
}

becomes

a {
  text-decoration: underline solid green 1px;
}

with "ignoreLonghands": ["text-decoration-thickness"]

a {
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-color: green;
  text-decoration-thickness: 1px;
}

becomes

a {
	text-decoration: underline solid green;
	text-decoration-thickness: 1px;
}

references

https://bugs.webkit.org/show_bug.cgi?id=190774
https://drafts.csswg.org/css-text-decor-4/#text-decoration-property

implementation details

Firefox 69 supports this feature (preffed off) under the name text-decoration-width, behind the pref layout.css.text-decoration-width.enabled.
text-decoration-skip is not part of the shorthand but will have to be eventually added in a separate PR.

browser support

https://caniuse.com/?search=text-decoration-thickness

background

rationale

https://caniuse.com/background-img-opts

example

{
  "fix": true,
  "rules": {
    "declaration-block-no-redundant-longhand-properties": [
      true,
      { "ignoreLonghands": ["background-size", "background-origin", "background-clip"] }
    ],
  }
}
a {
  background-image: none;
  background-position: 0% 0%;
  background-size: auto auto;
  background-repeat: repeat;
  background-origin: padding-box;
  background-clip: border-box;
  background-attachment: scroll;
  background-color: transparent;
}

becomes

a {
  background: repeat scroll 0% 0% none transparent;
  background-size: auto auto;
  background-origin: padding-box;
  background-clip: border-box;
}
@Mouvedia Mouvedia added status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules labels Oct 14, 2023
@Mouvedia Mouvedia changed the title Add text-decoration-width fix support to declaration-block-no-redundant-longhand-properties Add text-decoration-thickness fix support to declaration-block-no-redundant-longhand-properties Oct 14, 2023
@Mouvedia Mouvedia added status: needs discussion triage needs further discussion and removed status: ready to implement is ready to be worked on by someone labels Oct 14, 2023
@Mouvedia
Copy link
Member Author

Mouvedia commented Oct 14, 2023

Iv reverted to status: needs discussion because on a browser that doesn't support text-decoration-thickness

a {
  text-decoration-thickness: 1px;
}

will simply be ignored, but

a {
  text-decoration: underline solid green 1px;
}

will be dropped altogether because it will consider it invalid.
i.e. style, line and color will be ignored as well

tl;dr: if it's not configurable (pick between 3 or 4) it's not worth adding IMHO
i.e. it would require ignoreProperty: ["/regex/", /regex/, "string"]
e.g. ignoreProperty: ["text-decoration-thickness"]

@ybiquitous
Copy link
Member

Hum, I think it's still worth to support text-decoration-thickness in the following case:

a {
	text-decoration-line: underline;
	text-decoration-style: solid;
	text-decoration-color: green;
	text-decoration-thickness: 1px;

	/* ↓↓↓ autofixed */

	text-decoration: underline solid green 1px;
}

At the same time, we'd like to keep the current behavior if text-decoration-thickness is absent:

a {
	text-decoration-line: underline;
	text-decoration-style: solid;
	text-decoration-color: green;

	/* ↓↓↓ autofixed */

	text-decoration: underline solid green;
}

Can we achieve this by the rule's implementation? @mattxwang

@Mouvedia
Copy link
Member Author

Mouvedia commented Oct 16, 2023

That's possible, but as I have explained in the previous comment, it is not worth adding unless we have a new option that let's us ignore text-decoration-thickness for this rule.
e.g. if ignored

a {
	text-decoration-line: underline;
	text-decoration-style: solid;
	text-decoration-color: green;
	text-decoration-thickness: 1px;
}

would autofix to

a {
	text-decoration: underline solid green;
	text-decoration-thickness: 1px; // only this line is dropped if the browser doesn't support it
}

i.e. the existing ignoreShorthand: : ["text-decoration"] is not granular enough and would be considered a downgrade compared to the status quo.

@ybiquitous
Copy link
Member

Currently, caniuse shows 93% coverage at the global:

image

It may make sense to wait until this coverage increases more. We can revisit this issue when the coverage is enough.

@Mouvedia
Copy link
Member Author

It wouldn't change my opinion: it requires a new option.
I wish the option I proposed would have other use cases though.

@ybiquitous
Copy link
Member

@Mouvedia You mean a new option like ignoreProperties, right? To be honest, I'm concerned that a new option may be confused with ignoreShorthands.

@Mouvedia
Copy link
Member Author

Mouvedia commented Oct 16, 2023

@ybiquitous ignoreLonghands wouldn't be confusing. The problem is not the name, it's that it wouldn't be warranted if we only had one use case. But I found another one: background used to be the shorthand of 5 properties, but now it's 8.
i.e. ignoreLonghands: ["background-size", "background-origin", "background-clip"]

Should I create a new issue for that option?

@ybiquitous
Copy link
Member

Make sense. Adding a new ignoreLonghands option sounds good to me. 👍🏼

Should I create a new issue for that option?

No need. Let's continue the discussion here so that we can easily understand the context.

So could you update the issue title and comment on a blueprint for the new option?

@Mouvedia Mouvedia changed the title Add text-decoration-thickness fix support to declaration-block-no-redundant-longhand-properties Add "ignoreLonghands": [] to declaration-block-no-redundant-longhand-properties Oct 17, 2023
@Mouvedia Mouvedia added type: new option a new option for an existing rule and removed type: enhancement a new feature that isn't related to rules labels Oct 17, 2023
@mattxwang
Copy link
Member

Ah! I think this issue slipped by me earlier. This is certainly doable, though it'll require quite a bit of refactoring to get it to work nicely with the existing approach. After v16, I am happy to work on this a bit (since, for better or worse, I've been heavily involved with this rule and its autofix).

@ybiquitous ybiquitous added status: ready to implement is ready to be worked on by someone and removed status: needs discussion triage needs further discussion labels Oct 24, 2023
Copy link
Contributor

This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant.

@github-actions github-actions bot added status: ask to implement ask before implementing as may no longer be relevant and removed status: ready to implement is ready to be worked on by someone labels Jan 22, 2024
@Mouvedia
Copy link
Member Author

After v16, I am happy to work on this a bit (since, for better or worse, I've been heavily involved with this rule and its autofix).

@mattxwang are you still planning to work on it?
@ybiquitous I might work on it if @mattxwang doesn't assign himself; can we switch to ready to implement?

@mattxwang
Copy link
Member

@Mouvedia go for it, I've been swamped with work lately and haven't had the chance to work on Stylelint :(

@ybiquitous
Copy link
Member

@Mouvedia It still makes sense to implement the new option ignoreLonghands. Let's switch to "ready to implement".

@jeddy3 Please comment if you have any concerns.

@Mouvedia Mouvedia added status: ready to implement is ready to be worked on by someone and removed status: ask to implement ask before implementing as may no longer be relevant labels Feb 2, 2024
@Mouvedia
Copy link
Member Author

Mouvedia commented Feb 2, 2024

Based on @jeddy3's 👍 I've labeled the issue as ready to implement. Please consider contributing if you have time.

There are steps on how to add a new option in the Developer guide.

Copy link
Contributor

github-actions bot commented Mar 3, 2024

This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant.

@github-actions github-actions bot added status: ask to implement ask before implementing as may no longer be relevant and removed status: ready to implement is ready to be worked on by someone labels Mar 3, 2024
@Mouvedia Mouvedia added status: ready to implement is ready to be worked on by someone and removed status: ask to implement ask before implementing as may no longer be relevant labels Apr 13, 2024
@Mouvedia Mouvedia self-assigned this Apr 13, 2024
@Mouvedia Mouvedia added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Apr 13, 2024
@Mouvedia
Copy link
Member Author

Mouvedia commented Apr 17, 2024

a {
	text-decoration-line: underline;
	text-decoration-style: solid;
	text-decoration-color: green;

	/* ↓↓↓ autofixed */

	text-decoration: underline solid green;
}

This is certainly doable, though it'll require quite a bit of refactoring to get it to work nicely with the existing approach.
After v16, I am happy to work on this a bit (since, for better or worse, I've been heavily involved with this rule and its autofix).

@mattxwang are you still interested in implementing that enhancement?
i.e. autofix with optional longhands missing
If so can you create an issue?

@mattxwang
Copy link
Member

@mattxwang are you still interested in implementing that enhancement? i.e. autofix with optional longhands missing If so can you create an issue?

I don't think I'd be able to dedicate time to this until the summer (~June) after I'm done teaching. If you'd like to take it on, go for it!

(would you still want me to draft up an issue)?

@Mouvedia
Copy link
Member Author

(would you still want me to draft up an issue)?

When you will have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone type: new option a new option for an existing rule
Development

Successfully merging a pull request may close this issue.

3 participants