-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Identify CSS units and variables #1450
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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,71 @@ | ||
width: calc(100% + 20px); | ||
width: calc(100% - 20px); | ||
width: calc(5px * 2); | ||
width: calc(10px / 2); | ||
height: -20px; | ||
content: 'this - is not an operator'; | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "100"], | ||
["unit", "%"], | ||
["operator", "+"], | ||
["number", "20"], | ||
["unit", "px"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "100"], | ||
["unit", "%"], | ||
["operator", "-"], | ||
["number", "20"], | ||
["unit", "px"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "5"], | ||
["unit", "px"], | ||
["operator", "*"], | ||
["number", "2"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "width"], | ||
["punctuation", ":"], | ||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "10"], | ||
["unit", "px"], | ||
["operator", "/"], | ||
["number", "2"], | ||
["punctuation", ")"], | ||
["punctuation", ";"], | ||
|
||
["property", "height"], | ||
["punctuation", ":"], | ||
["number", "-20"], | ||
["unit", "px"], | ||
["punctuation", ";"], | ||
|
||
["property", "content"], | ||
["punctuation", ":"], | ||
["string", "'this - is not an operator'"], | ||
["punctuation", ";"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
This file contains 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,21 @@ | ||
100% | ||
1rem | ||
500ms | ||
.5s | ||
-3px | ||
-0.618vw | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "100"], ["unit", "%"], | ||
["number", "1"], ["unit", "rem"], | ||
["number", "500"], ["unit", "ms"], | ||
["number", ".5"], ["unit", "s"], | ||
["number", "-3"], ["unit", "px"], | ||
["number", "-0.618"], ["unit", "vw"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for units. |
This file contains 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,34 @@ | ||
var(--color-primary) | ||
var(--level-3) | ||
calc(100% - var(--margin-size) * 2) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", "var"], | ||
["punctuation", "("], | ||
["variable", "--color-primary"], | ||
["punctuation", ")"], | ||
|
||
["function", "var"], | ||
["punctuation", "("], | ||
["variable", "--level-3"], | ||
["punctuation", ")"], | ||
|
||
["function", "calc"], | ||
["punctuation", "("], | ||
["number", "100"], | ||
["unit", "%"], | ||
["operator", "-"], | ||
["function", "var"], | ||
["punctuation", "("], | ||
["variable", "--margin-size"], | ||
["punctuation", ")"], | ||
["operator", "*"], | ||
["number", "2"], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for variables. |
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.
This pattern will also include possible default values.
But we can use the naming convention of custom properties to make a simple pattern which matches all variables accessed via
var
or not.Using that,
/(^|[^-\w\xA0-\uFFFF])--[-_a-z\xA0-\uFFFF][-\w\xA0-\uFFFF]*/i
should do the job.Depending on whether we insert it before
property
we can also highlight the custom property declarations.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.
Gah, hit merge too quickly!
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.
It's alright, I reviewed too late.