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 shorthand-property-no-redundant-values false negatives for var() #7656

Closed
gregmatys opened this issue Apr 26, 2024 · 10 comments
Closed

Fix shorthand-property-no-redundant-values false negatives for var() #7656

gregmatys opened this issue Apr 26, 2024 · 10 comments
Labels
status: wip is being worked on by someone type: bug a problem with a feature or rule

Comments

@gregmatys
Copy link

gregmatys commented Apr 26, 2024

What minimal example or steps are needed to reproduce the bug?

a { padding: 0 var(--padding) 0; }

What minimal configuration is needed to reproduce the bug?

{ "rules": { "shorthand-property-no-redundant-values": true } }

How did you run Stylelint?

Demo

Which Stylelint-related dependencies are you using?

json { "stylelint": "15.6.0" }

What did you expect to happen?

fix redundant values

What actually happened?

nothing

Do you have a proposal to fix the bug?

--

@ybiquitous ybiquitous added status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule labels Apr 26, 2024
@ybiquitous
Copy link
Member

@gregmatys Thanks for the report with the reproducible demo. This is a bug.

I've labeled the issue as ready to implement. Please consider contributing if you have time.

There are steps on how to fix a bug in a rule in the Developer guide.

@ybiquitous ybiquitous changed the title shorthand-property-no-redundant-values doesn't work with var() Fix shorthand-property-no-redundant-values false negatives for var() Apr 26, 2024
@Mouvedia
Copy link
Member

Mouvedia commented Apr 26, 2024

Do we allow the erasion of var(…)?
i.e. do we eval --padding in your example?

e.g.

  /* --padding is 0 */
  padding: 0 var(--padding) 0;

to

  padding: 0;

or without eval

  /* --padding is unknown */
  padding: 0 var(--padding) 0;

to

  padding: 0 var(--padding);

?

The latter is safer because it keeps var(--padding) in the source.
Another possibility is to do the former only if the custom property declaration is within the same file.

@ybiquitous
Copy link
Member

"without eval" makes sense to me.

@ybiquitous ybiquitous 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 26, 2024
@gregmatys
Copy link
Author

without evaluation for sure
because var() can be dynamic!

@ybiquitous
Copy link
Member

I just opened PR #7657. It supports not only var(), but also other functions such as calc(). Please feel free to comment on the PR if you have any concerns. 🙏🏼

@romainmenke
Copy link
Member

romainmenke commented Apr 26, 2024

🤔 Is it an issue that with var() we can not know what that actual value will be?

:root {
	--padding: 20px;
}

@media screen {
	:root {
		--padding: 20px 5px;
	}
}

.a {
	padding: 0 var(--padding) 0; /* unknown what --padding actually is */
}

.b {
	padding: 0 20px 5px 0; /* no error */
}

.c {
	padding: 0 20px 0; /* Expected "0 20px 0" to be "0 20px" */
}

https://stylelint.io/demo/#N4Igxg9gJgpiBcCBOEIBcAEwA6A7baAtIQA4CGUUAlrgObwYBMADCQB4DceAvnngAIBbGNTIYAzmCQwYuLHzTwU6efjQFi5SjXpNWbDAFZ2XNb1zm8AOjE41W6nQbMMANzJIAFJoqPaASgxmU0tcKwAjVQIHHWc9diME4J4+MLAotBinIPiDZIs8EAAaEAAzKgAbGAA5MmEEEBg2OpIqqzBxcWLwCFxy2ga7DAxsRrY0WShxUYYAbTxh4dHxNABPKoqaIkg+qlpCFbJcKA8oUYWMAF0ebp3+gDEIJEEyNAaAK3Fe7tgSLsQhiMQCt1jBNrh1AggRVXjAVqMihdlmsNltCHc9gc0EcTkgzlDRjCJvCQDduEA

@Mouvedia
Copy link
Member

Mouvedia commented Apr 26, 2024

--padding: 20px 5px;

To me that's a blocker even if it eval the (re)declarations of the current file.
i.e. if the custom property can be reset dynamically the rule shouldn't report

The resetting cannot be ruled out for 2 reasons:

  • setProperty
  • other files

tl;dr: IMHO it should be ignored
i.e. this issue should be closed as by design

The PR could add support for functions like calc though.

@romainmenke
Copy link
Member

this issue should be closed as by design

In that case we should probably make that explicit behavior by adding a test case for it.

I agree that whenever var() is involved it becomes exceedingly hard to give correct and meaningful feedback, let alone do auto fixes.

@ybiquitous
Copy link
Member

Thanks for the feedback. I missed cases like --padding: 20px 5px;. I agree var should be ignored for this rule. 👍🏼

I will continue to work on PR #7657 to exclude var support since calc support still makes sense.

I'm closing this issue.

@ybiquitous ybiquitous closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2024
@gregmatys
Copy link
Author

Thanks for your work on that issue. You're right it's hard to precisely exclude the var issue here.

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: bug a problem with a feature or rule
Development

No branches or pull requests

4 participants