-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
Fix ESLint config #5132
Fix ESLint config #5132
Conversation
Updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
b74fbee
to
94f738a
Compare
The upgrade to ESLint 9 which occurred in a previous commit was not done correctly. It seems that an array must be passed to `createConfig` instead of a series of arguments. As a result, a lot of lint rules were accidentally disabled. This commit fixes the ESLint config and corrects any lint violations. Unsurprisingly, upgrading the ESLint packages created a bunch of new lint violations, so those have been turned into warnings rather than errors in this commit. To prevent new instances of these violations from occurring, however, a script has been added which acts as a quality gate, running `eslint` as before, but then capturing existing warning counts and comparing them to a previously generated threshold file, exiting with non-zero if there is an increase in warnings for any particular ESLint rule. This script is also now used for `yarn lint:eslint` so that CI will fail if the count increases.
@@ -62,45 +58,54 @@ const config = createConfig( | |||
}, | |||
{ | |||
files: [ | |||
'**/jest.config.js', |
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 list of globs should be functionally equivalent as we had some overlap previously.
], | ||
extends: [nodejs], | ||
rules: { | ||
// TODO: Re-enable this | ||
'n/no-sync': 'off', |
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 rule was previously disabled earlier in this file but the Node rules may re-enable this rule so we here we explicitly disable it.
}, | ||
{ | ||
files: ['*.test.{ts,js}', '**/tests/**/*.{ts,js}'], |
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.
Globs changed in ESLint 9. You need to prepend the glob with **/
if you want to look for files in any directory, not just the root.
// Disable `projectService` because we run into out-of-memory issues. | ||
// See this ticket for inspiration out how to solve this: | ||
// <https://github.com/typescript-eslint/typescript-eslint/issues/1192> | ||
projectService: false, |
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.
Disabling projectService
is inconsistent with the module template, but I had to do this in order to even run eslint
. Disabling projectService
does not seem to make eslint
run more slowly.
@@ -110,6 +115,8 @@ const config = createConfig( | |||
'@typescript-eslint/promise-function-async': 'off', | |||
|
|||
// TODO: re-enable most of these rules | |||
'@typescript-eslint/explicit-function-return-type': 'off', | |||
'@typescript-eslint/naming-convention': 'off', |
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 rule was previously disabled earlier in this file but the TypeScript rules may re-enable this rule so we here we explicitly disable it.
@@ -1580,7 +1580,6 @@ export class KeyringController extends BaseController< | |||
* @deprecated Use `withKeyring` instead. | |||
*/ | |||
async cancelQRSynchronization(): Promise<void> { | |||
// eslint-disable-next-line n/no-sync |
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 am unsure why the Node rules were getting applied to these files. ESLint was reporting that this rule no longer applied, so I removed it. (Similar for other cases.)
@@ -1982,7 +1982,6 @@ export class PermissionController< | |||
target: string, | |||
): void { | |||
if (!isPlainObject(caveat)) { | |||
// eslint-disable-next-line @typescript-eslint/no-throw-literal |
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.
ESLint reported that this rule no longer applied.
@@ -44,7 +44,7 @@ function buildMessenger() { | |||
* @param options.getSubjectNames - Permissions controller list of domains with permissions | |||
* @returns The network controller restricted messenger. | |||
*/ | |||
export function buildSelectedNetworkControllerMessenger({ |
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.
ESLint was reporting that this should not be exported. It was not used as far as I could tell.
@@ -3,7 +3,7 @@ import { BaseControllerV1 } from '@metamask/base-controller'; | |||
import type { ApprovalType } from '@metamask/controller-utils'; | |||
import type { Hex, Json } from '@metamask/utils'; | |||
// This package purposefully relies on Node's EventEmitter module. | |||
// eslint-disable-next-line import/no-nodejs-modules | |||
// eslint-disable-next-line import-x/no-nodejs-modules |
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.
We are now using eslint-plugin-import-x
, a fork of eslint-plugin-import
.
@@ -1110,7 +1110,7 @@ describe('PhishingDetector', () => { | |||
]; | |||
|
|||
// CID should be blocked | |||
for await (const entry of expectedToBeBlocked) { |
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 await
was never necessary here and ESLint now reports that it should be removed.
Explanation
The upgrade to ESLint 9 which occurred in a previous commit was not performed correctly. It seems that an array must be passed to
createConfig
instead of a series of arguments, and that was not done. As a result, a lot of lint rules were disabled accidentally.This commit fixes the ESLint config and corrects any lint violations. Unsurprisingly, upgrading the ESLint packages created a bunch of new lint violations, so those have been turned into warnings rather than errors in this commit. To prevent new instances of these violations from occurring, however, a script has been added which acts as a quality gate, running
eslint
as before, but then capturing existing warning counts and comparing them to a previously generated threshold file, exiting with non-zero if there is an increase in warnings for any particular ESLint rule. This script is also now used foryarn lint:eslint
so that CI will fail if the count increases.References
Changelog
N/A (developer change only)
Checklist