-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add rules for no-color-css-vars
#61
Conversation
|
@@ -0,0 +1,75 @@ | |||
{ | |||
"--color-canvas-default-transparent": "canvasDefaultTransparent", |
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.
How are we generating this map?
Is there a risk of this falling out of sync with primitives?
@langermank Found it! It was |
@@ -25,12 +25,12 @@ | |||
"@changesets/cli": "^2.16.0", | |||
"@github/prettier-config": "0.0.4", | |||
"@primer/primitives": "^5.1.0", | |||
"eslint": "^8.0.1", | |||
"eslint": "^8.42.0", |
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.
to use new features: sourceCode.getText
and sourceCode.getScope
This is compatible with version in dotcom, github/github/ui/packages/eslintrc/package.json#L19
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.
Thank you!!! 🎉 you're the best
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 looking pretty cool ✨ We will also need to add this rule to a few places for documentation:
meta: { | ||
type: 'suggestion', | ||
hasSuggestions: true, | ||
fixable: 'code', |
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.
So cool 🔥
}, | ||
{ | ||
code: `<Box sx={{boxShadow: '0 0 0 2px var(--color-canvas-subtle)'}} />`, | ||
output: `<Box sx={{boxShadow: '0 0 0 2px canvas.subtle'}} />`, |
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.
boxShadow
doesn't support referencing variables like this. Instead, you have to pass a function like this:
boxShadow: theme => `0 0 0 2px ${theme.colors.canvas.subtle}`
It might be tricky to update the plugin to support this, so let's check if this is a common pattern before investing the time in updating the plugin.
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.
Thank you! That was a real example from dotcom I grabbed. I'll see if there's more than one, though.
Closing in favor of #81 |
As we begin testing new CSS color variable names, I'd like to try and pair down the surface area as much as possible. There are many (~200) cases in github/github where teams are referencing color CSS variables within the
sx
prop and other styled-system props, and I think it makes sense to try and enforce primitives the way Primer React consumes them currently.This test should check for the
sx
prop or color related styled-system props such ascolor
orbackgroundColor
, and if it finds a CSS variable in the provided JSON object suggest a fix.I hand wrote the JSON object because the names are so different, it would be impossible to infer when to camelCase. I opted to handle the most common colors and will likely need to hand edit some component specific issues I found in github/github.
I also plan to followup with another plugin that will actually allow the use of CSS variables in some cases, but it will do an autofix with the new color variable the same way we do in stylelint.
Closes https://github.com/github/primer/issues/2347