Repository navigation
feat: report a check that a string holds a Tailwind class - #2
Merged
Merged
Conversation
The PHPStan rule html.classAsString reports a positive check of a string, or of a search result, for a utility with [ ] or after a variant. The parameter htmlAssertions.camelCaseClasses adds camelCase. StringCalls maps each call to its parameters and result. html.markupAsString reads more calls and reports ?-> once. The package requires ext-mbstring.
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.
What
A new PHPStan rule,
html.classAsString. It reports a check in a test that a string holds a Tailwind class:Such a check passes when the class is anywhere: on another element, inside a longer class, in a script or in a comment.
How the rule decides
[ ]or after a variant. Plain words, kebab-case and custom properties are not reported. camelCase is reported only with the new parameterhtmlAssertions.camelCaseClasses: true.str_contains,strpos,substr_count,preg_match,Str::) is read only as the value of a check. The check claims found or absent by the kind of the result (bool, position, count, string, collection). A loose comparison such astoEqual(0)says neither.mixedand a class attribute value are not reported.Other changes
StringCallsmaps every call to its parameters by position and name. Both rules read it.html.markupAsStringalso reads theIgnoringCase,IgnoringLineEndingsandNotWithassertions,Str::doesntContainandStr::isMatch. It reports a?->call one time, not two times.composer.jsonrequiresext-mbstring. The package usedmb_trim()already.Test
composer teston PHP 8.5: 146 tests, PHPStan max, type coverage 100 %.ClassChecks.phpnames its expected result. Each line was red once.