Skip to content
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

Upgraded frontend-build version to v12 #836

Closed
wants to merge 26 commits into from

Conversation

BilalQamar95
Copy link
Contributor

@BilalQamar95 BilalQamar95 commented Jul 18, 2022

Git Ticket: 42: Upgrade eslint to v8.x

What changed?

  • Updated frontend-build to v12 (Eslint was updated in frontend-build version resulting in it's version being bumped to v12. This PR updates frontend-build to reciprocate eslint version update)
  • Resolved eslint issues

For all changes

  • Ensure adequate tests are in place (or reviewed existing tests cover changes)

Only if submitting a visual change

  • Ensure to attach screenshots
  • Ensure to have UX team confirm screenshots

@BilalQamar95 BilalQamar95 requested a review from a team July 18, 2022 11:30
@BilalQamar95 BilalQamar95 self-assigned this Jul 18, 2022
@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Base: 82.43% // Head: 83.17% // Increases project coverage by +0.73% 🎉

Coverage data is based on head (83eb04b) compared to base (bb0c728).
Patch coverage: 84.14% of modified lines in pull request are covered.

❗ Current head 83eb04b differs from pull request most recent head d6b9112. Consider uploading reports for the commit d6b9112 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #836      +/-   ##
==========================================
+ Coverage   82.43%   83.17%   +0.73%     
==========================================
  Files         398      386      -12     
  Lines        8989     8510     -479     
  Branches     1895     1828      -67     
==========================================
- Hits         7410     7078     -332     
+ Misses       1546     1400     -146     
+ Partials       33       32       -1     
Impacted Files Coverage Δ
src/components/App/index.jsx 0.00% <0.00%> (ø)
...rc/components/AuthenticatedEnterpriseApp/index.jsx 0.00% <0.00%> (ø)
...mponents/BulkEnrollmentPage/stepper/ReviewStep.jsx 50.00% <0.00%> (-10.00%) ⬇️
src/components/CodeManagement/index.jsx 0.00% <0.00%> (-50.00%) ⬇️
src/components/CodeSearchResults/index.jsx 84.37% <ø> (ø)
...mponents/ContentHighlights/ContentHighlightSet.jsx 0.00% <0.00%> (-25.00%) ⬇️
...entHighlights/ContentHighlightSetCardContainer.jsx 0.00% <0.00%> (ø)
src/components/ContentHighlights/data/reducer.js 0.00% <0.00%> (ø)
src/components/EnterpriseList/index.jsx 80.70% <0.00%> (ø)
src/components/FileInput/index.jsx 35.00% <0.00%> (ø)
... and 329 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@BilalQamar95 BilalQamar95 reopened this Jul 28, 2022
.eslintrc Outdated
Comment on lines 57 to 59
"react/no-unstable-nested-components": [
2, { "allowAsProps": true }
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't think we should change this rule as it tries to prevent creating potentially unstable components, when React components are defined inline with another component, which indeed does feel like an anti-pattern.

Could we abstract these inline components as a completely standalone component instead?

.eslintrc Outdated
@@ -1,6 +1,6 @@
{
"extends": "@edx/eslint-config",
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, ideally this repo (or most MFE repos) wouldn't need a custom .eslintrc file. Most of the stuff in this file is legacy from when this repo was first created in 2018, before @edx/frontend-build existed.

OK to keep for now, but I'd love to see this repo move away from a custom .eslintrc file in favor of using the default .eslintrc config from @edx/frontend-build.

subscription: [{}, () => {}],
};
}), [selectedCourses]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here:

  1. Technically, selectedCourses will have a new array reference on each re-render of StepperWrapper, essentially getting re-created each time. This could cause value to change indefinitely instead of being memoized as intended. Either selectedCourses should be computed inside the useMemo or the selectedCourses itself should be memoized.
  2. Why was selectedEmails replaced with an empty array here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was covered in one of the previous commits, made in light of changes suggested by you on this PR.

);
function BulkEnrollmentSubmitWrapper({ bulkEnrollInfo = defaultBulkEnrollInfo, ...props }) {
return (
<ToastsContext.Provider value={useMemo(() => ({ addToast }), [])}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: abstract the useMemo into a variable contextValue instead of defining it inline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was covered in one of the previous commits, made in light of changes suggested by you on this PR.

return (
<Provider store={mockStore({ portalConfiguration: { enterpriseId: '1234' } })}>
<Router history={history}>
<ToastsContext.Provider value={useMemo(() => ({ addToast: mockAddToast }), [])}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: abstract the useMemo out of the return statement into its own variable contextValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was covered in one of the previous commits, made in light of changes suggested by you on this PR.

@@ -26,11 +26,12 @@ const ToastsProvider = ({ children }) => {
};

return (
// eslint-disable-next-line react/jsx-no-constructed-context-values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this context value be computed with a useMemo to avoid ignoring this ESLint rule?

<div className="justify-content-center">
{config.display_name}
</div>
<span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unrelated to your change, but we're using block elements (p) inside of inline elements (span) which is typically an anti-pattern / not best practice. Any reason not to change the span to be div here?

@@ -18,6 +18,7 @@ import { features } from '../../config';
import NotFoundPage from '../../components/NotFoundPage';
import { EnterpriseSubsidiesContext } from '../../components/EnterpriseSubsidiesContext';

// eslint-disable-next-line react/function-component-definition
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why is this rule disabled here but in other test files, you've replaced arrow function components with function?

Copy link
Contributor Author

@BilalQamar95 BilalQamar95 Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing it here results in following error,
The module factory of jest.mock() is not allowed to reference any out-of-scope variables.

@@ -69,6 +69,7 @@ export const useSubscriptions = ({ enterpriseId, errors, setErrors }) => {
loadCustomerAgreementData();
}, [loadCustomerAgreementData]);

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(loadCustomerAgreementData, [enterpriseId]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid ignoring ESLint rules about react-hooks/exhaustive-deps. Is there a fix here to avoid getting the error?

Copy link
Contributor Author

@BilalQamar95 BilalQamar95 Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be to replace enterpriseId with loadCustomerAgreementData in dependency array. When it comes to useEffect, I generally avoid making these changes just to satisfy the linter

@@ -47,6 +47,7 @@ export const useLinkManagement = (enterpriseUUID) => {
};
}, [enterpriseUUID]);

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(loadLinks, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generally avoid ignoring ESLint rules about react-hooks/exhaustive-deps. Is there a solution here to avoid needing to disable this rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be to either add loadLinks to the dependency array or remove the array entirely. I have seen these being ignored for useEffect in other areas/repos as well. One such example would be in SSOConfigConfiguredCard.jsx

@BilalQamar95
Copy link
Contributor Author

PR upgrading frontend-build to v12 was already merged, therefore I'm closing this on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants