-
Notifications
You must be signed in to change notification settings - Fork 860
[ESLint] Warn about static z-index #9236
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
base: main
Are you sure you want to change the base?
[ESLint] Warn about static z-index #9236
Conversation
6782d45 to
66ef4bd
Compare
44ecf1e to
fe9080c
Compare
fe9080c to
7b8869b
Compare
💚 Build SucceededHistory
|
💚 Build Succeeded
History
|
acstll
left a comment
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.
Tested in Kibana, ran tests locally and it's working nicely, as expected. Added a comment about 2 uses cases I found that hopefully we can also cover. Let me know what you think. Thanks for tackling this one!
| `, | ||
| languageOptions, | ||
| errors: [{ messageId: 'noStaticZIndexSpecific' }], | ||
| }, |
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.
while testing in Kibana, I found 2 use cases that are not covered by the rule, the most common one being "nested" style objects, the other are arrays — would that be too tricky to implement?
I tried reproducing these locally, adding these:
{
// Invalid: Variable with static value used in css prop (object style, nested)
filename: 'test.tsx',
code: dedent`
import React from 'react';
import { css } from '@emotion/react';
const myCss = css({ container: zIndex: 100 }});
function TestComponent() {
return <div css={myCss}>test</div>
}`,
languageOptions,
errors: [{ messageId: 'noStaticZIndexSpecificDeclaredVariable' }],
},
{
// Invalid: css array, one with static z-index
filename: 'test.tsx',
code: dedent`
import { css } from '@emotion/react';
function TestComponent() {
return <div css={[someStyle, css({ zIndex: 9 })]}>test</div>
}
`,
languageOptions,
errors: [{ messageId: 'noStaticZIndexSpecific' }],
},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.
Incredible find, thank you, Arturo 🙏🏻 and for adding the test cases, I'll cover these
| if ( | ||
| (didReport = checkPropertySpecifiesInvalidZIndex( | ||
| propertyName, | ||
| propertyNode.value.value | ||
| )) | ||
| ) { | ||
| context.report(messageToReport); | ||
| } |
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.
[non-blocking] I would avoid assignments inside conditions mostly for readability (TIL there's even a rule for that: no-cond-assign 😀)
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 agree, thank you for catching this!
| @@ -0,0 +1 @@ | |||
| - Add a `no-static-z-index` rule No newline at end of file | |||
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.
| - Add a `no-static-z-index` rule | |
| - Added `no-static-z-index` rule |
Summary
Note
This PR was co-authored with Gemini 3 Pro.
Why are we making this change?
Resolves #9230
It was raised as a suggestion on an internal meeting. If people do not reuse
euiThemetokens it's hard to assure the correct hierarchy.Screenshots #
Impact to users
🟢 No impact. Just a dev warning.
QA