-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"@typescript-eslint/consistent-type-exports": 19, | ||
"@typescript-eslint/no-base-to-string": 3, | ||
"@typescript-eslint/no-duplicate-enum-values": 2, | ||
"@typescript-eslint/no-misused-promises": 3, | ||
"@typescript-eslint/no-unsafe-enum-comparison": 59, | ||
"@typescript-eslint/no-unused-vars": 36, | ||
"@typescript-eslint/prefer-promise-reject-errors": 13, | ||
"@typescript-eslint/prefer-readonly": 152, | ||
"@typescript-eslint/switch-exhaustiveness-check": 10, | ||
"import-x/namespace": 189, | ||
"import-x/no-named-as-default": 1, | ||
"import-x/no-named-as-default-member": 8, | ||
"import-x/order": 209, | ||
"jest/no-conditional-in-test": 104, | ||
"jsdoc/check-tag-names": 372, | ||
"jsdoc/require-returns": 22, | ||
"jsdoc/tag-lines": 329, | ||
"n/no-unsupported-features/node-builtins": 18, | ||
"n/prefer-global/text-encoder": 4, | ||
"n/prefer-global/text-decoder": 4, | ||
"prettier/prettier": 116, | ||
"promise/always-return": 3, | ||
"promise/catch-or-return": 2, | ||
"promise/param-names": 8, | ||
"no-empty-function": 2, | ||
"no-shadow": 8, | ||
"no-unused-private-class-members": 6 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
import base, { createConfig } from '@metamask/eslint-config'; | ||
import nodejs from '@metamask/eslint-config-nodejs'; | ||
import jest from '@metamask/eslint-config-jest'; | ||
import nodejs from '@metamask/eslint-config-nodejs'; | ||
import typescript from '@metamask/eslint-config-typescript'; | ||
|
||
const config = createConfig( | ||
const config = createConfig([ | ||
...base, | ||
{ | ||
ignores: [ | ||
'yarn.lock', | ||
'**/**.map', | ||
'**/**.tsbuildinfo', | ||
'**/*.json', | ||
'**/*.md', | ||
'**/LICENSE', | ||
'**/*.sh', | ||
'**/.DS_Store', | ||
'**/dist/**', | ||
'**/docs/**', | ||
'**/coverage/**', | ||
|
@@ -22,7 +15,6 @@ const config = createConfig( | |
'scripts/create-package/package-template/**', | ||
], | ||
}, | ||
...base, | ||
{ | ||
rules: { | ||
// Left disabled because various properties throughough this repo are snake_case because the | ||
|
@@ -32,14 +24,12 @@ const config = createConfig( | |
'id-length': 'off', | ||
|
||
// TODO: re-enble most of these rules | ||
'@typescript-eslint/naming-convention': 'off', | ||
'function-paren-newline': 'off', | ||
'id-denylist': 'off', | ||
'implicit-arrow-linebreak': 'off', | ||
'import/no-anonymous-default-export': 'off', | ||
'import/no-unassigned-import': 'off', | ||
'import-x/no-anonymous-default-export': 'off', | ||
'import-x/no-unassigned-import': 'off', | ||
'lines-around-comment': 'off', | ||
'n/no-sync': 'off', | ||
'no-async-promise-executor': 'off', | ||
'no-case-declarations': 'off', | ||
'no-invalid-this': 'off', | ||
|
@@ -53,6 +43,12 @@ const config = createConfig( | |
'off', | ||
{ matchDescription: '^[A-Z`\\d_][\\s\\S]*[.?!`>)}]$' }, | ||
], | ||
|
||
// TODO: These rules created more errors after the upgrade to ESLint 9. | ||
// Re-enable these rules and address any lint violations. | ||
'import-x/no-named-as-default-member': 'warn', | ||
'prettier/prettier': 'warn', | ||
'no-empty-function': 'warn', | ||
}, | ||
settings: { | ||
jsdoc: { | ||
|
@@ -62,54 +58,76 @@ const config = createConfig( | |
}, | ||
{ | ||
files: [ | ||
'**/jest.config.js', | ||
'**/jest.environment.js', | ||
'**/tests/**/*.{ts,js}', | ||
'*.js', | ||
'*.test.{ts,js}', | ||
'**/*.{js,cjs,mjs}', | ||
'**/*.test.{js,ts}', | ||
'**/tests/**/*.{js,ts}', | ||
'scripts/*.ts', | ||
'scripts/create-package/*.ts', | ||
'yarn.config.cjs', | ||
'scripts/create-package/**/*.ts', | ||
], | ||
extends: [nodejs], | ||
rules: { | ||
// TODO: Re-enable this | ||
'n/no-sync': 'off', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
// TODO: These rules created more errors after the upgrade to ESLint 9. | ||
// Re-enable these rules and address any lint violations. | ||
'n/no-unsupported-features/node-builtins': 'warn', | ||
}, | ||
}, | ||
{ | ||
files: ['*.test.{ts,js}', '**/tests/**/*.{ts,js}'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Globs changed in ESLint 9. You need to prepend the glob with |
||
files: ['**/*.test.{js,ts}', '**/tests/**/*.{js,ts}'], | ||
extends: [jest], | ||
rules: { | ||
// TODO: These rules created more errors after the upgrade to ESLint 9. | ||
// Re-enable these rules and address any lint violations. | ||
'jest/no-conditional-in-test': 'warn', | ||
}, | ||
}, | ||
{ | ||
// These files are test helpers, not tests. We still use the Jest ESLint | ||
// config here to ensure that ESLint expects a test-like environment, but | ||
// various rules meant just to apply to tests have been disabled. | ||
files: ['**/tests/**/*.{ts,js}', '!*.test.{ts,js}'], | ||
files: ['**/tests/**/*.{js,ts}'], | ||
ignores: ['**/*.test.{js,ts}'], | ||
rules: { | ||
'jest/no-export': 'off', | ||
'jest/require-top-level-describe': 'off', | ||
'jest/no-if': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['*.js', '*.cjs'], | ||
parserOptions: { | ||
files: ['**/*.{js,cjs}'], | ||
languageOptions: { | ||
sourceType: 'script', | ||
ecmaVersion: '2020', | ||
ecmaVersion: 2020, | ||
}, | ||
}, | ||
{ | ||
files: ['*.ts'], | ||
files: ['**/*.ts'], | ||
extends: [typescript], | ||
parserOptions: { | ||
tsconfigRootDir: import.meta.dirname, | ||
project: ['./tsconfig.packages.json'], | ||
languageOptions: { | ||
parserOptions: { | ||
tsconfigRootDir: import.meta.dirname, | ||
project: './tsconfig.packages.json', | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Disabling |
||
}, | ||
}, | ||
rules: { | ||
// This rule does not detect multiple imports of the same file where types | ||
// are being imported in one case and runtime values are being imported in | ||
// another | ||
'import-x/no-duplicates': 'off', | ||
|
||
// Enable rules that are disabled in `@metamask/eslint-config-typescript` | ||
'@typescript-eslint/no-explicit-any': 'error', | ||
|
||
// TODO: auto-fix breaks stuff | ||
'@typescript-eslint/promise-function-async': 'off', | ||
|
||
// TODO: re-enable most of these rules | ||
'@typescript-eslint/naming-convention': 'off', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
'@typescript-eslint/no-unnecessary-type-assertion': 'off', | ||
'@typescript-eslint/unbound-method': 'off', | ||
'@typescript-eslint/prefer-enum-initializers': 'off', | ||
|
@@ -118,35 +136,72 @@ const config = createConfig( | |
'@typescript-eslint/prefer-reduce-type-parameter': 'off', | ||
'no-restricted-syntax': 'off', | ||
'no-restricted-globals': 'off', | ||
|
||
// TODO: These rules created more errors after the upgrade to ESLint 9. | ||
// Re-enable these rules and address any lint violations. | ||
'@typescript-eslint/consistent-type-exports': 'warn', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-base-to-string': 'warn', | ||
'@typescript-eslint/no-duplicate-enum-values': 'warn', | ||
'@typescript-eslint/no-misused-promises': 'warn', | ||
'@typescript-eslint/no-unsafe-enum-comparison': 'warn', | ||
'@typescript-eslint/no-unused-vars': 'warn', | ||
'@typescript-eslint/only-throw-error': 'warn', | ||
'@typescript-eslint/prefer-promise-reject-errors': 'warn', | ||
'@typescript-eslint/prefer-readonly': 'warn', | ||
'@typescript-eslint/switch-exhaustiveness-check': 'warn', | ||
'import-x/namespace': 'warn', | ||
'import-x/no-named-as-default': 'warn', | ||
'import-x/order': 'warn', | ||
'jsdoc/check-tag-names': 'warn', | ||
'jsdoc/require-returns': 'warn', | ||
'jsdoc/tag-lines': 'warn', | ||
'no-unused-private-class-members': 'warn', | ||
'promise/always-return': 'warn', | ||
'promise/catch-or-return': 'warn', | ||
'promise/param-names': 'warn', | ||
}, | ||
}, | ||
{ | ||
files: ['tests/setupAfterEnv/matchers.ts'], | ||
parserOptions: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
languageOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
// This should really be in `@metamask/eslint-config-typescript` | ||
{ | ||
files: ['*.d.ts'], | ||
files: ['**/*.d.ts'], | ||
rules: { | ||
'@typescript-eslint/naming-convention': 'warn', | ||
'import/unambiguous': 'off', | ||
'import-x/unambiguous': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['scripts/*.ts'], | ||
rules: { | ||
// All scripts will have shebangs. | ||
'n/shebang': 'off', | ||
// Scripts may be self-executable and thus have hashbangs. | ||
'n/hashbang': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['**/jest.environment.js'], | ||
rules: { | ||
// These files run under Node, and thus `require(...)` is expected. | ||
'n/global-require': 'off', | ||
|
||
// TODO: These rules created more errors after the upgrade to ESLint 9. | ||
// Re-enable these rules and address any lint violations. | ||
'n/prefer-global/text-encoder': 'warn', | ||
'n/prefer-global/text-decoder': 'warn', | ||
'no-shadow': 'warn', | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.mjs'], | ||
languageOptions: { | ||
sourceType: 'module', | ||
}, | ||
}, | ||
); | ||
]); | ||
|
||
export default config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -618,7 +618,7 @@ function logOrRethrowError(error: unknown, codesToCatch: number[] = []) { | |
throw error; | ||
} | ||
} else { | ||
// eslint-disable-next-line @typescript-eslint/no-throw-literal | ||
// eslint-disable-next-line @typescript-eslint/only-throw-error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
throw error; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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.) |
||
(await this.getOrAddQRKeyring()).cancelSync(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We are now using |
||
import { EventEmitter } from 'events'; | ||
import { v1 as random } from 'uuid'; | ||
|
||
|
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.