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

Fix ESLint config #5132

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Fix ESLint config #5132

merged 4 commits into from
Jan 14, 2025

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 11, 2025

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 for yarn lint:eslint so that CI will fail if the count increases.

References

Changelog

N/A (developer change only)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire requested review from a team as code owners January 11, 2025 00:54
Copy link

socket-security bot commented Jan 11, 2025

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] 🔁 npm/[email protected] None 0 85.8 kB diego

View full report↗︎

@mcmire mcmire marked this pull request as draft January 13, 2025 15:40
@mcmire mcmire force-pushed the fix-eslint branch 6 times, most recently from b74fbee to 94f738a Compare January 13, 2025 20:18
@mcmire mcmire marked this pull request as ready for review January 13, 2025 20:21
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',
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 list of globs should be functionally equivalent as we had some overlap previously.

],
extends: [nodejs],
rules: {
// TODO: Re-enable this
'n/no-sync': '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 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}'],
Copy link
Contributor Author

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,
Copy link
Contributor Author

@mcmire mcmire Jan 13, 2025

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',
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 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
Copy link
Contributor Author

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
Copy link
Contributor Author

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({
Copy link
Contributor Author

@mcmire mcmire Jan 13, 2025

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
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

@mcmire mcmire enabled auto-merge (squash) January 14, 2025 17:59
@mcmire mcmire merged commit 7409b3f into main Jan 14, 2025
226 checks passed
@mcmire mcmire deleted the fix-eslint branch January 14, 2025 18:56
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.

9 participants