X Tutup
The Wayback Machine - https://web.archive.org/web/20221224171401/https://github.com/tailwindlabs/tailwindcss/pull/2590
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 鈥淪ign up for GitHub鈥, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show "Did you mean?" message when users @apply errant class #2590

Merged
merged 7 commits into from Oct 19, 2020
Merged

feat: Show "Did you mean?" message when users @apply errant class #2590

merged 7 commits into from Oct 19, 2020

Conversation

mattrothenberg
Copy link
Contributor

@mattrothenberg mattrothenberg commented Oct 16, 2020

Howdy!

Currently, when you mis-@apply a class name, the error message doesn't help you figure out what you might have been trying to type instead. For instance, I get bit by this one all of the time 馃憞

/* 馃槺 */
body {
  @apply anti-aliased;
}

@apply cannot be used with .anti-aliased because .anti-aliased either cannot be found, or its actual definition includes a pseudo-selector like :hover, :active, etc. If you're sure that .anti-aliased exists, make sure that any @import statements are being properly processed before Tailwind CSS sees your CSS, as @apply can only be used for classes in the same CSS tree.

I think we can make this error message even more helpful with one extra line...

Did you mean .antialiased?

To this end, I've added some very na茂ve logic to the applyComplexClasses.js module, such that it compares the given class (that's being @apply'ed) against the list of all available classes with the assistance of the library DidYouMean.js.

In fact, I was inspired by @yuki24's amazing work on https://github.com/ruby/did_you_mean, and would welcome his suggestions for actually implementing this in a sophisticated way, should this feature sound interesting to the Tailwind team.

Open Questions

  • What happens if multiple suggestions are recommended?
  • Is this library fast enough, or will this significantly slow down compilation?

Thanks for all your hard work 鉂わ笍

@adamwathan
Copy link
Member

adamwathan commented Oct 16, 2020

Hey! Not opposed to adding this but could you do it here instead?

https://github.com/tailwindlabs/tailwindcss/blob/master/src/flagged/applyComplexClasses.js

That is the new version of apply that will be replacing the current one in Tailwind 2.0 in like 3-4 weeks.

@mattrothenberg
Copy link
Contributor Author

mattrothenberg commented Oct 16, 2020

@adamwathan Updated. Turns out that DidYouMean library is really widely used in the JS ecosystem, so there's that.

@yuki24
Copy link

yuki24 commented Oct 19, 2020

@adamwathan @mattrothenberg Nothing is more fulfilling than seeing a pull request like this! Thank you for your fantastic work 鉂わ笍

@adamwathan
Copy link
Member

adamwathan commented Oct 19, 2020

Sorry, I promoted "applyComplexClasses" to be the default apply behavior and now the files you changed don't exist and GitHub is confused 馃槵 If you don't mind updating I can merge.

@mattrothenberg
Copy link
Contributor Author

mattrothenberg commented Oct 19, 2020

@adamwathan Updated. I think the merge went OK and that I updated the right bits.

@adamwathan adamwathan merged commit 7572b02 into tailwindlabs:master Oct 19, 2020
@adamwathan
Copy link
Member

adamwathan commented Oct 19, 2020

Looks good, thanks!

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.

None yet

3 participants
X Tutup