Do not split classes by non-ASCII whitespace #166
Merged
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.
Hello, recently applying
prettier-plugin-tailwindcss
broke our styling 😭 so here is a fix.Problem
According to the web standard, HTML's
class
attribute is split by ASCII whitespace into a set of classes. In other words, non-ASCII whitespace characters are not class separators.For example,
px-1 py-2
is one class (notice that the spece in between is a U+3000), not two classes (px-1
andpy-2
).However, this plugin wrongly treats non-ASCII whitespace as a class separator, which may lead to unintended change of meaning of code.
The concrete scenario is that, when I newly applied
prettier-plugin-tailwindcss
to our project there was code like:where
px-1
andz-10
weren't effective due to the U+3000.After applying this plugin this turned into:
Now
z-10
revived andw-full
went ineffective instead, which led to unwanted styling change.Solution
This PR fixes the problem by treating only ASCII whitespace as separators.
Note
Of course use of
U+3000
is a mistake and should have been prevented by some sort of linting. However, eslint-plugin-tailwindcss had the same issue 😢