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 autofix conflicts #7626

Merged
merged 3 commits into from Apr 19, 2024

Conversation

Mouvedia
Copy link
Contributor

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

Closes #7610

Is there anything in the PR that needs further explanation?

No, it's self-explanatory.

Copy link

changeset-bot bot commented Apr 19, 2024

🦋 Changeset detected

Latest commit: 093fd05

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

@Mouvedia Mouvedia mentioned this pull request Apr 19, 2024
4 tasks
@ybiquitous ybiquitous changed the title Fix declaration-block-no-redundant-longhand-properties autofix conflicts Fix declaration-block-no-redundant-longhand-properties autofix conflicts for border-* Apr 19, 2024
@ybiquitous
Copy link
Member

I notice that this problem is about border-*-style false positive, rather than generic autofix. See the demo:

image

border-*-style props are reported too much, comparing border-*-width and border-*-color.

@Mouvedia
Copy link
Contributor Author

Mouvedia commented Apr 19, 2024

Apart from

Expected shorthand property "border" [(declaration-block-no-redundant-longhand-properties)](https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties) [13:2-19]

which might be covered by #7609 in a particular case:

a {
	border-top-width: foo;
	border-right-width: foo;
	border-bottom-width: foo;
	border-left-width: foo;
	border-top-color: bar;
	border-right-color: bar;
	border-bottom-color: bar;
	border-left-color: bar;
	border-top-style: qux;
	border-right-style: qux;
	border-bottom-style: qux;
	border-left-style: qux;
}

the rest looks OK.
i.e. I expect 7 warnings but only 3 fixes attempted.

are reported too much

Just think about it, the detection of the shorthand possibilities for border-top, border-right, border-left and border-bottom happen once you reach the third match. Just check the implementation, it's logical. It has nothing to do with border-*-style and everything to do with the position of the block. Switch them up you will understand.
e.g. demo

@Mouvedia Mouvedia changed the title Fix declaration-block-no-redundant-longhand-properties autofix conflicts for border-* Fix declaration-block-no-redundant-longhand-properties autofix conflicts Apr 19, 2024
@ybiquitous
Copy link
Member

I understood this PR's fix cannot resolve the false positives. Honestly, I think we should reconsider the rule's implementation, not adding a workaround patch, because this rule has been fixed at many times recently.

@Mouvedia
Copy link
Contributor Author

Mouvedia commented Apr 19, 2024

@ybiquitous I have added an if around the forEach so that it doesn't loop for other shorthands.
I feel that this is a major bug: the autofix is removing code.
This PR is fine as is; it is scoped and I took care of the perf aspect as well.
If you have suggestions for other tests Ill welcome them.
Concerning a refactor, it will have to wait.
I can wait for further review to come in if you are not confident.
I hope it will be part of 16.4.1.

@ybiquitous
Copy link
Member

ybiquitous commented Apr 19, 2024

@Mouvedia I'm against adding this workaround, and again we should reconsider the implementation even if it would be a big change. Honestly, I don't want to review PRs so many times only for one rule, and this workaround may occur other problems.

In addition, this bug has been not found for a long time. You say this is "major", but I guess many people are not in trouble.

I think it's a good timing to detect the rule's better implementation design.

@Mouvedia
Copy link
Contributor Author

Ill just explain what this fix does then, maybe that will change your mind.
The rule creates an array that it populates with longhands that it encounters inside a declaration block, for each shorthand supported. Once the array matches it can move on to the fixer.
Before the fix, once the replacement of the longhands by the shorthand was done it didn't remove those longhands from the other arrays that were being populated at the same time. Inevitably it would cause useless autofixes to be attempted because the arrays weren't cleaned up. The first iteration of the fix was doing the cleanup without any regard of whether the shorthands were affected by the bug. The last iteration only does it for a shortlist of shorthands, it's less future proof and requires to maintain a blacklist.

I hope that's clearer and I managed to convince you.

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.

Okay, I agree with merging this since it resolves at lease autofix problem. But I still have the opinion to reconsider this rule's implementation as soon as possible.

If you fix the changelog, you can merge. LGTM.

.changeset/large-olives-press.md Outdated Show resolved Hide resolved
@Mouvedia
Copy link
Contributor Author

Mouvedia commented Apr 19, 2024

But I still have the opinion to reconsider this rule's implementation as soon as possible.

This is a legitimate worry. Having 2 rules depending on the sets and having to jungle them both every time they are changed can be considered daunting. If we were to take a perf approach for the refactor I think @romainmenke might be interested by it based on his work on #6869.

If you fix the changelog, you can merge. LGTM.

I will fix the changelog.
Let's wait for several days; like you said we are not in a hurry.

@ybiquitous
Copy link
Member

The discussions about this rule have been opened in #7630 and #7631. They indicates there is some problem in the rule implementation.

@Mouvedia
Copy link
Contributor Author

…you can merge…

I have added more tests to cover more permutations.

The discussions about this rule have been opened in #7630 and #7631. They indicates there is some problem in the rule implementation.

We can continue the discussion around maintenance and refactors there.

@Mouvedia Mouvedia merged commit c9e483a into stylelint:main Apr 19, 2024
16 checks passed
@Mouvedia Mouvedia deleted the fix-autofix-longhand branch April 19, 2024 15:30
emmacharp pushed a commit to emmacharp/stylelint that referenced this pull request May 7, 2024
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 conflicts
2 participants