-
Notifications
You must be signed in to change notification settings - Fork 22
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
Create only-extend-defined rule #37
base: master
Are you sure you want to change the base?
Conversation
}, | ||
|
||
configs: { | ||
recommended: { | ||
rules: { | ||
'react-with-styles/only-spread-css': 'error', | ||
'react-with-styles/no-unused-styles': 'error', | ||
'react-with-styles/only-extend-defined': 'error', |
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.
FWIW, adding this to the recommended list makes this a breaking change. Sometimes we add rules at first and then when we are ready to make a breaking change, we lump all of the modifications to the recommended config into one breaking change.
However, given how rarely we work on this particular plugin, it might make sense to do this now.
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.
might still be worth it to ship it as minor first (without this line) and then do a followup as a major that enables it.
extendedStyle.properties.forEach((property) => { | ||
if (property.computed) { | ||
// Skip over computed properties for now. | ||
// e.g. `{ [foo]: { ... } }` |
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 think this raises an interesting question: should there be a rule to disallow computed properties for extendable styles (or for styles in general)?
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've seen a lot of usages of constants for things around responsiveness (e.g. [responsive.mediumAndAbove]
). I think we would begin to limit ourselves a lot if we disallowed computed properties.
I wonder if we can ensure that the same variable is used in both places... I can take a look tonight.
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.
Ah right! Can we add some valid and invalid test cases for nested styles? Media queries, @supports
queries, pseudo-elements, pseudo-selectors, etc.
|
||
if (property.type === 'ExperimentalSpreadProperty' || property.type === 'SpreadElement') { | ||
// Skip over object spread for now. | ||
// e.g. `{ ...foo }` |
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.
Same here, should spreading in extendable styles be disallowed?
)(Foo); | ||
`.trim(), | ||
errors: [{ | ||
message: '`background` is not extendable', |
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 think we can make this error message a little more helpful:
foo.background
is not extendable because it is undefined
)(Foo); | ||
`.trim(), | ||
errors: [{ | ||
message: '`bar` is not extendable', |
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.
Same here, add "because it is undefined" or something similar
foo: { | ||
background: () => true, | ||
color: () => true, | ||
fontSize: () => true, |
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.
Should we have some valid and invalid examples where the functions use args?
"only-extend-defined" ESLint Rule
Ensures that any extendable styles are defined in the component's style definition. This PR was created based on feedback on the extending styles PR.
Failing Example