-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Add react-hooks lint rules for APM folder, fix dependencies #42129
Conversation
x-pack/legacy/plugins/apm/public/components/app/Settings/AddSettings/AddSettingFlyout.tsx
Show resolved
Hide resolved
x-pack/legacy/plugins/apm/public/components/app/TransactionOverview/List/index.tsx
Show resolved
Hide resolved
💚 Build Succeeded |
@@ -120,15 +120,19 @@ export function KueryBar() { | |||
let didCancel = false; | |||
|
|||
async function loadIndexPattern() { | |||
setState({ ...state, isLoadingIndexPattern: true }); | |||
setState(value => ({ ...value, isLoadingIndexPattern: 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.
Better 👍
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.
... again: did the linter catch this? If so, that's great!
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.
yep!
preservePreviousResponse, | ||
dispatchStatus, | ||
...effectKey | ||
/* eslint-enable react-hooks/exhaustive-deps */ |
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 it complaining about counter
not being used?
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 guess that's fine. Although would be better if we could avoid disabling the lint rule somehow...
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.
Yeah, and we can't add fn
because it's usually recreated every render. Passing fn as a dependency would be more correct, but it would mean that we require the consumer to wrap the function that is passed to useFetcher
in useCallback()
. Adding result.data
breaks stuff as well. I figure we have to do a significant rewrite of this hook to have correct dependencies.
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.
Okay, let's just leave it at this, then
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.
Nice work! This is gonna catch some bugs - I can feel it! :)
Would the lint rule catch this issue (missing const { data } = useFetcher(() => {
if (start && end) {
return loadServiceList({ start, end, uiFilters });
}
}, [start, end]); I'd be surprised if it did, since it's a custom hook. |
@sqren There's seemingly an additionalHooks option, we can probably use that: I'll give it a shot, and update the PR if it works. |
@@ -0,0 +1,7 @@ | |||
module.exports = { |
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.
Can we keep the behaviour we are already doing for other overrides of keep everything from eslint in a global configuration other than have nested config files? Like for example https://github.com/elastic/kibana/blob/master/.eslintrc.js#L390,
You can just add other object with those rules on that line,
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.
@mistic added another item to the array that only applies to .ts(x)
files (it was already applied to .js
files).
@sqren the |
@dgieselaar Wow! That's super cool! |
@@ -30,7 +30,7 @@ export function useTransactionBreakdown() { | |||
uiFilters | |||
}); | |||
} | |||
}, [serviceName, start, end, uiFilters]); | |||
}, [serviceName, start, end, transactionType, transactionName, uiFilters]); |
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.
Did you almost forget to fix what brought you here in the first place :p
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.
Super nice with this custom hooks linter 👍 👍
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.
Yeah I actually left it open because I wanted to test it until I found out that the transaction type select was broken. And then I forgot about 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.
But the linter saved us! Already proving its worth! :D
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 changes to the ESLINT rules looks good to me know 👍
💚 Build Succeeded |
…astic#42129) * [APM] Add react-hooks lint rules for APM folder, fix dependencies Closes elastic#42128. * Validate useFetcher dependencies as well * Add useFetcher hook; move eslint config to kibana eslint config
…astic#42129) * [APM] Add react-hooks lint rules for APM folder, fix dependencies Closes elastic#42128. * Validate useFetcher dependencies as well * Add useFetcher hook; move eslint config to kibana eslint config
Closes #42128.