-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[infra] Migrate to use eslint without airbnb config #19269
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
Conversation
Deploy preview: https://deploy-preview-19269--material-ui-x.netlify.app/ Bundle size report
|
7dc84b1
to
c478774
Compare
/* I use this method to parse whatever component props are passed in and format them for the code example, | ||
so the code example includes the same props as the rendered component. e.g. the views={['month']} */ | ||
// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types | ||
function formatComponentProps(componentProps?: Object, spacing: number = 1) { |
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.
We can't just update the type here?
eslint.config.mjs
Outdated
// TODO move to @mui/internal-code-infra/eslint, these are false positive | ||
'react/no-unstable-nested-components': ['error', { allowAsProps: true }], | ||
// migration rules | ||
'@typescript-eslint/no-namespace': 'off', |
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.
We already have
Lines 417 to 423 in c478774
{ | |
// TODO: typescript namespaces found to be harmful. Refactor to different patterns. More info: https://github.com/mui/mui-x/pull/19071 | |
ignores: ['packages/x-scheduler/**/*', 'packages/x-virtualizer/**/*'], | |
rules: { | |
'@typescript-eslint/no-namespace': '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.
Both are different. By default, the rule is turned off and only enabled for x-scheduler
and x-virtualizer
packages.
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.
My mistake. Its ignores
and not files
.
): GridValidRowModel[] => { | ||
let filteredRows = [...rows]; | ||
if (filterModel && filterModel.quickFilterValues?.length! > 0) { | ||
if (filterModel && (filterModel.quickFilterValues?.length as number) > 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.
If quickFilterValues
can be nullable, then why not just handle it like
if (filterModel && (filterModel.quickFilterValues?.length as number) > 0) { | |
if (filterModel?.quickFilterValues && filterModel.quickFilterValues.length > 0) { |
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain | ||
const getOptionValue = resolvedColumn?.getOptionValue!; |
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.
Thanks, Can't unsee now how ridiculous this pattern actually is 😄
685dbad
to
507e709
Compare
507e709
to
a42d48b
Compare
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.
Ok for me.
Would prefer to fix
https://github.com/mui/mui-x/pull/19269/files#diff-136cfbf653bed6242fa84d92939470db5864af54d7ba79551edfbdbbcfd11c4cR28
and
https://github.com/mui/mui-x/pull/19269/files#diff-b0ed7ac72c2450e42859b95ec4e83bb79c3dbfdd7b8bae6d7af5b379b0547704R30
if we safely can.
Otherwise, to the X team for a final approval
07394f9
to
0cc7ec2
Compare
|
||
const metrics = (rotationScale?.domain() as (string | number)[]) ?? []; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain | ||
const angles = metrics.map((key) => rotationScale?.(key)!); |
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.
@alexfauquette should do something if rotationScale is not present instead? 🤔
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.
is not if rotationScale
is not present. It's if key
is not part of rotationScale
domain. Which is not possible
if (rotationScale === undefined) { return []; }
const metrics = rotationScale.domain() as (string | number)[];
const angles = metrics.map((key) => rotationScale(key)!);
To remove the !
we should support the case where scale return undefined
but it feels weirds to handle a case that should not exist just to please TS
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 eslint rule issue is with forcing an optional rotationScale(key)!
would be acceptable.
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.
And if you're certain that rotationScale
can't have nullish values, you should express that as rotationScale!(key)!
, not rotationScale?.(key)!
.
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.
For now, I have changed it to rotationScale!.(key)!
to satisfy TS without any runtime changes.
const isOptionEqualToValue = React.useCallback( | ||
(option: ValueOptions, value: ValueOptions) => getOptionValue(option) === getOptionValue(value), | ||
(option: ValueOptions, value: ValueOptions) => | ||
getOptionValue?.(option) === getOptionValue?.(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.
tbh, this still feels wrong, this would always return true
if getOptionValue
is undefined, even if value
and option
are not equivalent. If there's a valid reason where resolvedColumn?.getOptionLabel
can be undefined
, shouldn't it be more like:
const getOptionValue = resolvedColumn?.getOptionValue ?? (value) => value;
const getOptionLabel = resolvedColumn?.getOptionLabel ?? (label) => label;
?
Otherwise can we express it correctly in the types? I don't have enough context to fully judge this though.
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 didn't want to meddle too much with the runtime because of the same reason. @cherniavskii Could you get this resolved ?
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.
OK, should be done.
Basically, if resolvedColumn
is not a single select column, we should just return null.
I've made getOptionLabel
and getOptionValue
non-nullable, because we assign default ones anyway.
typeof scrollCoordinates.left !== undefined || | ||
typeof scrollCoordinates.top !== undefined | ||
typeof scrollCoordinates.left !== 'undefined' || | ||
typeof scrollCoordinates.top !== 'undefined' |
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.
Good catch!
0cc7ec2
to
6c70c24
Compare
ec9a539
to
53482d3
Compare
53482d3
to
edaa791
Compare
See context - mui/mui-public#556
Major changes -
@typescript-eslint/no-non-null-asserted-optional-chain
has been turned on and will report error. So no more of doingobject?.property!
this. I have disabled the current issues and fixed in places where I could.V extends any
since it doesn't actually do anything.class-methods-use-this
has been turned off since we endup always disabling it anyway.📈 BENCHMARK RESULTS
Command:
pnpm eslint:ci