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

chore upgrade ESLint to latest 8.x and migrate to Flat Config #2311

Merged
merged 5 commits into from
Jun 26, 2024

Conversation

algreasley
Copy link
Contributor

@algreasley algreasley commented Jun 19, 2024

ESLint:

  • Switch to Flat Config
  • upgrade to latest 8.x (not 9.x as eslint-plugin-react is not compatible yet, but config will be ready for that being the default in v9+)
  • run migration tool (npx @eslint/migrate-config .eslintrc.yml )
  • ... then later fixed up all the migration cruft, as it was hard to see what was what
  • added hooks plugin (bit surprised it wasn't already there .. only a handful of errors to deal with tho)
  • VS Code ESLint extension requires latest IDE AND an eslint plugin setting to switch on Flat Config (bit daft as eslint v8 just auto-detects and off it goes)

Prettier

  • upgrade to 3.x
  • update config to js, remove redundant entries
  • re-format (see comments for the new types of re-formatting)

@algreasley algreasley marked this pull request as draft June 19, 2024 22:35
@algreasley algreasley force-pushed the chore/5873-upgrade-eslint-prettier branch from 3ca1e22 to 8f99fdc Compare June 24, 2024 11:24
},
},

rules: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rules are exactly the same as before, thankfully so this part of the config "upgrade" was a straightforward lift-and-shift ..

@algreasley algreasley marked this pull request as ready for review June 24, 2024 11:52
Copy link

(auto-deploy) A deployment has been created for this Pull Request

Preview links

As part of the code review process, please ensure that you test against the following

Version URL
Web https://web.env.reactivetrader.com/pull/2311
OpenFin - FX fins://openfin.env.reactivetrader.com/pull/2311/config/rt-fx.json
OpenFin - Credit fins://openfin.env.reactivetrader.com/pull/2311/config/rt-credit.json
OpenFin - Launcher fins://openfin.env.reactivetrader.com/pull/2311/config/launcher.json
OpenFin - Workspace fins://openfin.env.reactivetrader.com/pull/2311/workspace/config/workspace.json
Finsemble https://finsemble.env.reactivetrader.com/pull/2311

Performance

Please ensure that this PR does not degrade the performance of the UI. We should maintain a performance score of 95+.

https://developers.google.com/speed/pagespeed/insights/?url=https://web.env.reactivetrader.com/pull/2311

"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended",
"prettier",

Choose a reason for hiding this comment

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

does this make eslint play nice with prettier? Is this to be able to use prettier as the formatter in vscode?

Copy link
Contributor Author

@algreasley algreasley Jun 24, 2024

Choose a reason for hiding this comment

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

yeah, Ignacio did the detail work on this, but that's the idea - prettier for layout, lint for correctness - and I am 100% behind that decision / philosophy - there's a good article on the different ways you can go with this.
eslint-config-prettier is the option for doing formatting separately (presume it just switches stuff off)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

now the extra config negating eslint rules no longer necessary, it seems, as stylistic rules have been deprecated in these recent versions of the linting packages .. happy days 🙂

grancalavera
grancalavera previously approved these changes Jun 24, 2024
@algreasley algreasley force-pushed the chore/5873-upgrade-eslint-prettier branch 3 times, most recently from bf897a5 to d252a32 Compare June 25, 2024 22:04
@algreasley algreasley force-pushed the chore/5873-upgrade-eslint-prettier branch from d252a32 to df72dbe Compare June 25, 2024 22:27
@algreasley algreasley force-pushed the chore/5873-upgrade-eslint-prettier branch from df72dbe to 6125019 Compare June 25, 2024 22:42
"lint:cache": "npm run lint -- --cache",
"_format": "prettier README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\" \"e2e/**/*.ts\"",
"_format": "prettier README.md src e2e",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same for prettier, less complicated .. just check everything that the tool understands

@@ -139,7 +140,7 @@ export const Tooltip = ({ svgRef }: { svgRef: RefObject<SVGSVGElement> }) => {
svg.removeEventListener("pointermove", onMove)
svg.removeEventListener("pointerleave", onLeave)
}
}, [svgRef])
}, [svgRef, tooltipDivRef])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

first of a handful of corrected hooks, with the new eslint plugin

? useCreditDealerById(acceptedDealerId)
: undefined
)?.name ?? "Unknown Dealer"
const dealerName = useDealerNameById(acceptedDealerId)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

significant change .. tidied this up properly this time, the hook/stream can deal with the missing dealer!

@@ -83,8 +83,4 @@ const ThemeStorageSwitch = ({
)
}

ThemeStorageSwitch.defaultProps = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

wot? defaultProps? .. what decade are we in? 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks to updated rules, this popped up ..

@@ -1,5 +1,4 @@
import { act, fireEvent, render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

simple unused var rule, now applied to tests, as it should be

@@ -141,7 +141,6 @@ function interopOverride(
clientIdentity: OpenFin.ClientIdentity,
) {
// use accessor syntax for this.getClientState as it is not a public inherited method from InteropBroker
// eslint-disable-next-line @typescript-eslint/dot-notation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

briefly upgraded to eslint v9, and this showed up all the unused disable directives .. which was nice of it (I think you can do that with eslint config in < v9, as we won't be upgrading for a while, given the plugin ecosystem state ..

react,
// https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
// compat with ESLint v9, see https://github.com/facebook/react/issues/28313
"react-hooks": hooks,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added hooks plugin .. not FlatConfig-ready, so cannot just add config as tseslint above (this is the future model) ... just a few transgressions to fix

"simple-import-sort/exports": "error",

// as hooks plugin does not play well with Flat Config right now, do this
...hooks.configs.recommended.rules,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hooks - manually spread rules alongside our custom rules .. bit messy, but works

@algreasley algreasley merged commit 2fe3ed2 into master Jun 26, 2024
7 checks passed
@algreasley algreasley deleted the chore/5873-upgrade-eslint-prettier branch June 26, 2024 13:15
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.

2 participants