Upgrade: Reduce number of false-positive migrations of the important modifier#14737
Merged
graphite-app[bot] merged 1 commit intonextfrom Oct 22, 2024
Conversation
Contributor
Author
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @philipp-spiess and the rest of your teammates on |
929dec1 to
7f5f83b
Compare
7f5f83b to
efa812f
Compare
adamwathan
reviewed
Oct 21, 2024
packages/@tailwindcss-upgrade/src/template/codemods/important.ts
Outdated
Show resolved
Hide resolved
| ) { | ||
| continue | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Could we in theory scan backwards and forwards to look for quotes _on the same line? I feel like this logic may be too restrictive.
Contributor
Author
There was a problem hiding this comment.
liked that, implemented 😎
Contributor
There was a problem hiding this comment.
I think that change disappeared — don't see it in the diff 😬
b8bc6a9 to
0799c2d
Compare
dfc38cd to
c1207c2
Compare
thecrypticace
approved these changes
Oct 22, 2024
philipp-spiess
commented
Oct 22, 2024
packages/@tailwindcss-upgrade/src/template/codemods/important.ts
Outdated
Show resolved
Hide resolved
Contributor
Author
Merge activity
|
philipp-spiess
added a commit
that referenced
this pull request
Oct 22, 2024
…modifier (#14737) The important candidate migration is one of the most broad we have since it matches for any utility that are prefixed with an exclamation mark. When running the codemodes on our example projects, we noticed that this was instead creating false-positives with candidates used in code positions, e.g: ```ts export default { shouldNotUse: !border.shouldUse, } ``` To prevent false-positives, this PR adds a heuristics to detect wether or not a candidate is used in a non-code position. We do this by checking the character before and after the modifier and only allow quotes or spaces. This can cause candidates to not migrate that are valid Tailwind CSS classes, e.g.: ```ts let classNames = `!underline${isHovered ? ' font-bold' : ''}` ``` This, however, is not a big issue since v4 can parse the v3 important prefix too.
e1f0adf to
34f708a
Compare
…modifier (#14737) The important candidate migration is one of the most broad we have since it matches for any utility that are prefixed with an exclamation mark. When running the codemodes on our example projects, we noticed that this was instead creating false-positives with candidates used in code positions, e.g: ```ts export default { shouldNotUse: !border.shouldUse, } ``` To prevent false-positives, this PR adds a heuristics to detect wether or not a candidate is used in a non-code position. We do this by checking the character before and after the modifier and only allow quotes or spaces. This can cause candidates to not migrate that are valid Tailwind CSS classes, e.g.: ```ts let classNames = `!underline${isHovered ? ' font-bold' : ''}` ``` This, however, is not a big issue since v4 can parse the v3 important prefix too.
34f708a to
338a780
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The important candidate migration is one of the most broad we have since it matches for any utility that are prefixed with an exclamation mark.
When running the codemodes on our example projects, we noticed that this was instead creating false-positives with candidates used in code positions, e.g:
To prevent false-positives, this PR adds a heuristics to detect wether or not a candidate is used in a non-code position. We do this by checking the character before and after the modifier and only allow quotes or spaces.
This can cause candidates to not migrate that are valid Tailwind CSS classes, e.g.:
This, however, is not a big issue since v4 can parse the v3 important prefix too.