-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Change eslint configuration and fix resulting issues #4423
Conversation
…ake sure hooks are called in the same order.
@@ -27,7 +27,7 @@ export default function FavoritesDropdown({ fetch, urlTemplate }) { | |||
}, [fetch]); | |||
|
|||
// fetch items on init | |||
useEffect(() => fetchItems(false), []); | |||
useEffect(() => fetchItems(false), [fetchItems]); |
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.
Are you sure this should be fixed? According to comment, it should fetch items only once, but with this fix it will re-load items each time fetchItems
changed
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.
Not sure at all - it's part of the automatic fixes.
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'm also not sure how it supposed to work. Maybe @gabrieldutra will help 🤔
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'm testing these eslint changes, it's indeed a case where it makes it mandatory. In this specific case I think it's ok to keep the dependency as fetchItems
should only change if the fetch
prop change (in this case I think we do want the items to be loaded again).
Though from a quick search there are discussions around this (like this one). Just need to confirm if there's a more correct React way (they do mention useMemo
, but imo that only applies to when you don't have a Promise to solve).
A side note I just noticed: I'd avoid the () => executeFunction()
for useEffect
as the return value is used for cleaning. Anyway, I'll check other replacements to see if they can be problematic.
@@ -34,7 +34,7 @@ function useGrantees(url) { | |||
|
|||
const addPermission = useCallback((userId, accessType = 'modify') => $http.post( | |||
url, { access_type: accessType, user_id: userId }, | |||
).catch(() => notification.error('Could not grant permission to the user'), [url])); | |||
).catch(() => notification.error('Could not grant permission to the user')), [url]); |
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.
👍
@@ -77,7 +77,7 @@ function UserSelect({ onSelect, shouldShowUser }) { | |||
useEffect(() => { | |||
setLoadingUsers(true); | |||
debouncedSearchUsers(searchTerm); | |||
}, [searchTerm]); | |||
}, [debouncedSearchUsers, searchTerm]); |
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.
Probably it should be replaced with use-debounced
🤔 But let's keep as is for now
@@ -58,7 +58,7 @@ export default function Renderer({ data, options, onOptionsChange }) { | |||
options, // detect changes for all options except bounds, but pass them all! | |||
); | |||
} | |||
}, [map, geoJson, data, optionsWithoutBounds]); | |||
}, [map, geoJson, data, optionsWithoutBounds, options]); |
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 change will cause performance issues - see comment above
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.
@gabrieldutra Can you please address this in #4425 as well?
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.
Done 👍
@@ -16,7 +16,7 @@ function generateRowKeyPrefix() { | |||
|
|||
export default function Renderer({ data, options }) { | |||
const funnelData = useMemo(() => prepareData(data.rows, options), [data, options]); | |||
const rowKeyPrefix = useMemo(() => generateRowKeyPrefix(), [funnelData]); | |||
const rowKeyPrefix = useMemo(() => generateRowKeyPrefix(), []); |
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.
rowKeyPrefix
should be generated every time funnelData
changes to ensure that Ant Table will properly update rows
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 was checking, useEffect
doesn't require dependencies to be used (useMemo
does), so the options: 1 - Move it to useEffect
and useState
for the rowKeyPrefix; 2 - eslint-disable;
I think 2 is the quick one ^^
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.
1 is more confusing (IMO) - this use case is perfect for useMemo
, but not as obvious with useState
+ useEffect
. So I'm for 2, or I can try to find another (?) solution.
"eslint": "^5.16.0", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-import-resolver-webpack": "^0.8.3", | ||
"eslint-loader": "^2.1.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.
Isn't this necessary to load eslint with webpack? I started getting an error for it (webpack.config.js
points to eslint-loader
)
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.
Just confirming that, I'll open a PR with some updates, if you want I can do that along with 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.
My bad... I just removed all the previous *eslint*
dependencies 😬
@kravets-levko regarding the other 3 issues Arik mentioned (the |
@gabrieldutra I'm not sure if an issue will be noticeable or easy to reproduce. But reading the error + the code it does seem like the code that uses these |
The perfect solution is to use |
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.
Also, I'm not sure if that code should use
useRef
instead oflet
Seemed the best option to solve this 👍.
BTW, I didn't see a reason to refactor that to use I realized that the useSearchResults
, so I just applied the same useRef
fix as it was quicker.useRef
in that file causes issues, so moved to use useSearchResults
.
@@ -58,7 +58,7 @@ export default function Renderer({ data, options, onOptionsChange }) { | |||
options, // detect changes for all options except bounds, but pass them all! | |||
); | |||
} | |||
}, [map, geoJson, data, optionsWithoutBounds]); | |||
}, [map, geoJson, data, optionsWithoutBounds, options]); |
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.
Done 👍
@kravets-levko good to go? |
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.
Seems everything is fine 👍
What type of PR is this?
Description
We were using airbnb's eslint settings, which at the time seemed like a good setting to use. The problem was that they were outdated and had a mix of styling rules (like which type of quotes to use or line length) and actual linting rules. We are also using Prettier to format our code and it has some conflicting style choices with the eslint rules.
While this can be resolved by using prettier-eslint, it's less recommended these days. I decided to find us better defaults that will be more about linting and les about style. In search of a better default, I decided to pick
create-react-app
's eslint configuration, as it's very likely we will adoptcreate-react-app
once we get rid of Angular..js in our codebase.(later I found eslint-config-prettier, which just disables the conflicting rules, but already invested the work in doing the switch)
This resulted in a few new rules that found some issues in our codebase:
eslint --fix
. @gabrieldutra @kravets-levko can you make sure it all makes sense?useCallback
's dependencies found an actual bug in our code:fd7d19a.
I also added Prettier config and removed some dead code, but I will apply Prettier on the codebase in a separate PR to make it easier the code changes in this PR.
There were 3 issues that I wasn't sure how to fix, although they did seem like an actual issue: