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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint.useFlatConfig": true
}
42 changes: 0 additions & 42 deletions packages/client/.eslintrc.yml

This file was deleted.

34 changes: 20 additions & 14 deletions packages/client/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ export const test = base.extend<IPlaywrightFixtures>({
fxPagesRec: async ({ context }, use, workerInfo) => {
const contextPages = context.pages()
if (isOpenFin(workerInfo)) {
const pages = fxOpenfinUrlPaths.reduce((rec, urlPath) => {
const page = contextPages.find(
(p) => p.url() === `${process.env.E2E_RTC_WEB_ROOT_URL}/${urlPath}`,
)
if (!page) throw Error(`Openfin page at ${urlPath} was not found`)
return { ...rec, [urlPathToFxPage(urlPath)]: page }
}, {} as Record<FXPage, Page>)
const pages = fxOpenfinUrlPaths.reduce(
(rec, urlPath) => {
const page = contextPages.find(
(p) => p.url() === `${process.env.E2E_RTC_WEB_ROOT_URL}/${urlPath}`,
)
if (!page) throw Error(`Openfin page at ${urlPath} was not found`)
return { ...rec, [urlPathToFxPage(urlPath)]: page }
},
{} as Record<FXPage, Page>,
)
use(pages)
} else {
const mainWindow =
Expand All @@ -111,13 +114,16 @@ export const test = base.extend<IPlaywrightFixtures>({
creditPagesRec: async ({ context }, use, workerInfo) => {
const contextPages = context.pages()
if (isOpenFin(workerInfo)) {
const pages = creditOpenfinUrlPaths.reduce((rec, urlPath) => {
const page = contextPages.find(
(p) => p.url() === `${process.env.E2E_RTC_WEB_ROOT_URL}/${urlPath}`,
)
if (!page) throw Error(`Openfin page at ${urlPath} was not found`)
return { ...rec, [urlPathToCreditPage(urlPath)]: page }
}, {} as Record<CreditPage, Page>)
const pages = creditOpenfinUrlPaths.reduce(
(rec, urlPath) => {
const page = contextPages.find(
(p) => p.url() === `${process.env.E2E_RTC_WEB_ROOT_URL}/${urlPath}`,
)
if (!page) throw Error(`Openfin page at ${urlPath} was not found`)
return { ...rec, [urlPathToCreditPage(urlPath)]: page }
},
{} as Record<CreditPage, Page>,
)
use(pages)
} else {
const mainWindow =
Expand Down
93 changes: 93 additions & 0 deletions packages/client/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import js from "@eslint/js"
import react from "eslint-plugin-react"
import hooks from "eslint-plugin-react-hooks"
import simpleImportSort from "eslint-plugin-simple-import-sort"
import globals from "globals"
import tseslint from "typescript-eslint"

// Tried to introduce typechecking to this file, but requires
// * .js to be added to tsconfig.json
// * // @ts-check at the top of this file
// * this /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile} */
// ... and even then eslint-plugin-react has no (useful) types .. sigh
//
export default [
js.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {
// https://github.com/lydell/eslint-plugin-simple-import-sort
"simple-import-sort": simpleImportSort,
// https://typescript-eslint.io/getting-started/
"@typescript-eslint": tseslint.plugin,
// https://github.com/jsx-eslint/eslint-plugin-react
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

},
languageOptions: {
parser: tseslint.parser,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.browser,
},
},
settings: {
react: {
version: "detect",
},
},
// note: many tseslint rules require the base eslint rule to be disabled
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 ..

// https://typescript-eslint.io/rules/no-unused-vars/
// with options to ignore _-prefixed args
"no-unused-vars": "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.

this was not working properly, as you'll see from the diffs .. apparently one has to switch the existing rule off to allow the typescript-eslint version to do its thing correctly .. ridiculous

"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
// https://eslint.org/docs/latest/rules/no-loss-of-precision
"no-loss-of-precision": "off",
"@typescript-eslint/no-loss-of-precision": "off",
// https://typescript-eslint.io/rules/no-unused-expressions/
// with options to allow terse conditionals in functions (debatable)
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
enforceForJSX: true,
},
],

// with new flat config, we need to "switch on" the import errors
// ref https://github.com/lydell/eslint-plugin-simple-import-sort#usage
"simple-import-sort/imports": "error",
"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

},
},
{
// special blanket rules for mocks/tests
files: ["**/*.{service-mock,mock,test,spec}.{ts,tsx}", "**/__mocks__/*"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-var-requires": "off",
},
},
]
Loading