Skip to content

Upgrade: Reduce number of false-positive migrations of the important modifier #14737

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

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Oct 21, 2024

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:

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.:

let classNames = `!underline${isHovered ? ' font-bold' : ''}`

This, however, is not a big issue since v4 can parse the v3 important prefix too.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @philipp-spiess and the rest of your teammates on Graphite Graphite

@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch from 929dec1 to 7f5f83b Compare October 21, 2024 11:47
@philipp-spiess philipp-spiess marked this pull request as ready for review October 21, 2024 11:47
@philipp-spiess philipp-spiess requested a review from a team as a code owner October 21, 2024 11:47
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch from 7f5f83b to efa812f Compare October 21, 2024 12:19
) {
continue
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

liked that, implemented 😎

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that change disappeared — don't see it in the diff 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

@thecrypticace forgot to push it 🫠

@adamwathan adamwathan force-pushed the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch from b8bc6a9 to 0799c2d Compare October 21, 2024 19:56
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch 3 times, most recently from dfc38cd to c1207c2 Compare October 22, 2024 11:35
@philipp-spiess philipp-spiess changed the title Upgrade: Redce number of false-positive migrations of the important modifier Upgrade: Reduce number of false-positive migrations of the important modifier Oct 22, 2024
Copy link
Member Author

philipp-spiess commented Oct 22, 2024

Merge activity

  • Oct 22, 12:07 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 12:09 PM EDT: A user added this pull request to the Graphite merge queue.
  • Oct 22, 12:29 PM EDT: A user merged this pull request with the Graphite merge queue.

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.
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch from e1f0adf to 34f708a Compare October 22, 2024 16:19
…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.
@philipp-spiess philipp-spiess force-pushed the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch from 34f708a to 338a780 Compare October 22, 2024 16:24
@graphite-app graphite-app bot merged commit 338a780 into next Oct 22, 2024
2 checks passed
@graphite-app graphite-app bot deleted the 10-21-upgrade_redce_number_of_false-positive_migrations_of_the_important_modifier branch October 22, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants