-
-
Notifications
You must be signed in to change notification settings - Fork 228
feat: add support for invalid utility class diagnostics #1496
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
Open
felicijus
wants to merge
8
commits into
tailwindlabs:main
Choose a base branch
from
felicijus:feature/invalid-class-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+618
−2
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a5b9836
feat: add support for invalid class diagnostics and update settings
felicijus 0e4fb16
feat: refactor isClassValid function to improve invalid class checks
felicijus f4d6cdb
feat: update invalid class severity level from warning to info
felicijus 535429c
feat: add support for invalid class code actions and update diagnosti…
felicijus 3742366
feat: add tests for invalid class diagnostics and update related logic
felicijus 5ff8448
feat: add test for valid classes and update invalid class code action…
felicijus c8597ed
fix: getClassNamesInClassList to ignore newlines and spaces
felicijus 9cc237b
feat: add comprehensive tests for invalid class diagnostics and updat…
felicijus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
packages/tailwindcss-language-server/tests/diagnostics/invalid-class/css-multi-prop.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "code": ".test { @apply px-4; color: red; @apply nonexistent }", | ||
| "language": "css", | ||
| "expected": [ | ||
| { | ||
| "code": "invalidClass", | ||
| "source": "tailwindcss", | ||
| "className": { | ||
| "className": "nonexistent", | ||
| "classList": { | ||
| "classList": "nonexistent", | ||
| "important": false, | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 40 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 51 | ||
| } | ||
| } | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 40 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 51 | ||
| } | ||
| }, | ||
| "relativeRange": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 11 | ||
| } | ||
| } | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 40 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 51 | ||
| } | ||
| }, | ||
| "severity": 3, | ||
| "message": "Unknown utility class 'nonexistent'." | ||
| } | ||
| ] | ||
| } |
59 changes: 59 additions & 0 deletions
59
packages/tailwindcss-language-server/tests/diagnostics/invalid-class/css-multi-rule.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "code": ".test { @apply px-4 }\n.test { @apply nonexistent }", | ||
| "language": "css", | ||
| "expected": [ | ||
| { | ||
| "code": "invalidClass", | ||
| "source": "tailwindcss", | ||
| "className": { | ||
| "className": "nonexistent", | ||
| "classList": { | ||
| "classList": "nonexistent", | ||
| "important": false, | ||
| "range": { | ||
| "start": { | ||
| "line": 1, | ||
| "character": 15 | ||
| }, | ||
| "end": { | ||
| "line": 1, | ||
| "character": 26 | ||
| } | ||
| } | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 1, | ||
| "character": 15 | ||
| }, | ||
| "end": { | ||
| "line": 1, | ||
| "character": 26 | ||
| } | ||
| }, | ||
| "relativeRange": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 11 | ||
| } | ||
| } | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 1, | ||
| "character": 15 | ||
| }, | ||
| "end": { | ||
| "line": 1, | ||
| "character": 26 | ||
| } | ||
| }, | ||
| "severity": 3, | ||
| "message": "Unknown utility class 'nonexistent'." | ||
| } | ||
| ] | ||
| } |
59 changes: 59 additions & 0 deletions
59
packages/tailwindcss-language-server/tests/diagnostics/invalid-class/css.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "code": ".test { @apply nonexistent; }", | ||
| "language": "css", | ||
| "expected": [ | ||
| { | ||
| "code": "invalidClass", | ||
| "source": "tailwindcss", | ||
| "className": { | ||
| "className": "nonexistent", | ||
| "classList": { | ||
| "classList": "nonexistent", | ||
| "important": false, | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 15 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 26 | ||
| } | ||
| } | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 15 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 26 | ||
| } | ||
| }, | ||
| "relativeRange": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 0 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 11 | ||
| } | ||
| } | ||
| }, | ||
| "range": { | ||
| "start": { | ||
| "line": 0, | ||
| "character": 15 | ||
| }, | ||
| "end": { | ||
| "line": 0, | ||
| "character": 26 | ||
| } | ||
| }, | ||
| "severity": 3, | ||
| "message": "Unknown utility class 'nonexistent'." | ||
| } | ||
| ] | ||
| } |
58 changes: 58 additions & 0 deletions
58
...ages/tailwindcss-language-server/tests/diagnostics/invalid-class/jsx-concat-positive.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "code": "<div className={`nonexistent ${'px-4'}`}>", | ||
| "language": "javascriptreact", | ||
| "expected": [ | ||
| { | ||
| "className": { | ||
| "classList": { | ||
| "classList": "nonexistent $", | ||
| "range": { | ||
| "end": { | ||
| "character": 30, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 17, | ||
| "line": 0 | ||
| } | ||
| } | ||
| }, | ||
| "className": "nonexistent", | ||
| "range": { | ||
| "end": { | ||
| "character": 28, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 17, | ||
| "line": 0 | ||
| } | ||
| }, | ||
| "relativeRange": { | ||
| "end": { | ||
| "character": 11, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 0, | ||
| "line": 0 | ||
| } | ||
| } | ||
| }, | ||
| "code": "invalidClass", | ||
| "message": "Unknown utility class 'nonexistent'.", | ||
| "range": { | ||
| "end": { | ||
| "character": 28, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 17, | ||
| "line": 0 | ||
| } | ||
| }, | ||
| "severity": 3, | ||
| "source": "tailwindcss" | ||
| } | ||
| ] | ||
| } |
58 changes: 58 additions & 0 deletions
58
...ges/tailwindcss-language-server/tests/diagnostics/invalid-class/jsx-template-literal.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "code": "<div className={`nonexistent ${'px-4'}`}>", | ||
| "language": "javascriptreact", | ||
| "expected": [ | ||
| { | ||
| "className": { | ||
| "classList": { | ||
| "classList": "nonexistent $", | ||
| "range": { | ||
| "end": { | ||
| "character": 30, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 17, | ||
| "line": 0 | ||
| } | ||
| } | ||
| }, | ||
| "className": "nonexistent", | ||
| "range": { | ||
| "end": { | ||
| "character": 28, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 17, | ||
| "line": 0 | ||
| } | ||
| }, | ||
| "relativeRange": { | ||
| "end": { | ||
| "character": 11, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 0, | ||
| "line": 0 | ||
| } | ||
| } | ||
| }, | ||
| "code": "invalidClass", | ||
| "message": "Unknown utility class 'nonexistent'.", | ||
| "range": { | ||
| "end": { | ||
| "character": 28, | ||
| "line": 0 | ||
| }, | ||
| "start": { | ||
| "character": 17, | ||
| "line": 0 | ||
| } | ||
| }, | ||
| "severity": 3, | ||
| "source": "tailwindcss" | ||
| } | ||
| ] | ||
| } |
27 changes: 27 additions & 0 deletions
27
packages/tailwindcss-language-server/tests/diagnostics/invalid-class/simple.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "code": "<div class=\"px-4 nonexistent-class\"></div>", | ||
| "expected": [ | ||
| { | ||
| "code": "invalidClass", | ||
| "source": "tailwindcss", | ||
| "className": { | ||
| "className": "nonexistent-class", | ||
| "classList": { | ||
| "classList": "px-4 nonexistent-class", | ||
| "range": { | ||
| "start": { "line": 0, "character": 12 }, | ||
| "end": { "line": 0, "character": 34 } | ||
| } | ||
| }, | ||
| "relativeRange": { | ||
| "start": { "line": 0, "character": 5 }, | ||
| "end": { "line": 0, "character": 22 } | ||
| }, | ||
| "range": { "start": { "line": 0, "character": 17 }, "end": { "line": 0, "character": 34 } } | ||
| }, | ||
| "range": { "start": { "line": 0, "character": 17 }, "end": { "line": 0, "character": 34 } }, | ||
| "severity": 3, | ||
| "message": "Unknown utility class 'nonexistent-class'." | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd write all of these using testInline now. The .json file based tests will eventually disappear when I have the time to refactor everything (I'm slowly working on a larger change right now that'll also end up moving most relevant tests to the language service instead anyway)