-
Notifications
You must be signed in to change notification settings - Fork 68
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
Fix some false positives with ternary operators and cssMap #1781
Fix some false positives with ternary operators and cssMap #1781
Conversation
🦋 Changeset detectedLatest commit: a0f1be1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for compiled-css-in-js canceled.
|
code: outdent` | ||
import { cssMap } from '${imp}'; | ||
const styles = cssMap({ | ||
warning: { | ||
borderColor: '...', // 2 |
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.
the false positive, if depth in correct order for shorthand properties in the same bucket for cssMap AND if key not static
test case has been moved to the valid
section, as I've fixed the false positive
It's now called depth in correct order for shorthand properties in the same bucket for cssMap AND if key not static
on line 423
@@ -303,26 +344,24 @@ const parseCssMap = ( | |||
// If we know what key in the cssMap function call to traverse, | |||
// we can make sure we only traverse that. | |||
if (property.key.type === 'Literal' && key === property.key.value) { | |||
properties.push(...getObjectCSSProperties(context, property.value)); | |||
break; | |||
return getObjectCSSProperties(context, property.value); |
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.
slight optimisation
@@ -310,6 +392,54 @@ tester.run('shorthand-property-sorting', shorthandFirst, { | |||
export const EmphasisText = ({ children }) => <span css={styles}>{children}</span>; | |||
`, | |||
}, | |||
|
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 false negative already existed in the rule, it's just that we didn't have a test case for it
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 won't try to mentally run through the union
stuff, but tests and the code that's obvious makes sense to me!
What is this change?
Fix two edge cases:
css
function calls through ternary operators, we should not get an ESLint violation.cssMap
function call, we should not get an ESLint violation.Note that there still remain a lot of other (pre-existing) edge cases -- this rule is really hard to make fully rigorous, sorry 🙇 For example, this will still cause a false positive:
Why are we making this change?
We've received an internal query about a false positive with
css
, and it looks like it's pretty easy to fix.PR checklist
Don't delete me!
I have...
website/