-
-
Notifications
You must be signed in to change notification settings - Fork 5
Upgrade to MM eslint-config-* v15 + ESLint 9 #168
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| #!/usr/bin/env node | ||
| /* eslint-disable import/extensions */ | ||
|
|
||
| // eslint-disable-next-line import/no-unassigned-import, import/no-unresolved | ||
| // Three things: | ||
| // - This file doesn't export anything, as it's a script. | ||
| // - We are using a `.js` extension because that's what appears in `dist/`. | ||
| // - This file will only exist after running `yarn build`. We don't want | ||
| // developers or CI to receive a lint error if the script has not been run. | ||
| // (A warning will appear if the script *has* been run, but that is okay.) | ||
| // eslint-disable-next-line import-x/no-unassigned-import, import-x/extensions, import-x/no-unresolved | ||
| import '../dist/cli.js'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import base, { createConfig } from '@metamask/eslint-config'; | ||
| import jest from '@metamask/eslint-config-jest'; | ||
| import nodejs from '@metamask/eslint-config-nodejs'; | ||
| import typescript from '@metamask/eslint-config-typescript'; | ||
|
|
||
| const config = createConfig([ | ||
| { | ||
| ignores: ['dist/', 'docs/', '.yarn/'], | ||
| }, | ||
|
|
||
| { | ||
| extends: base, | ||
|
|
||
| languageOptions: { | ||
| sourceType: 'module', | ||
| parserOptions: { | ||
| tsconfigRootDir: import.meta.dirname, | ||
| }, | ||
| }, | ||
|
|
||
| rules: { | ||
| // Consider copying this to @metamask/eslint-config | ||
| 'jsdoc/require-jsdoc': [ | ||
| 'error', | ||
| { | ||
| require: { | ||
| // Classes | ||
| ClassDeclaration: true, | ||
| // Function declarations | ||
| FunctionDeclaration: true, | ||
| // Methods | ||
| MethodDefinition: true, | ||
| }, | ||
| contexts: [ | ||
| // Type interfaces that are not defined within `declare` blocks | ||
| ':not(TSModuleBlock) > TSInterfaceDeclaration', | ||
| // Type aliases | ||
| 'TSTypeAliasDeclaration', | ||
| // Enums | ||
| 'TSEnumDeclaration', | ||
| // Arrow functions that are not contained within plain objects or | ||
| // are not arguments to functions or methods | ||
| ':not(Property, NewExpression, CallExpression) > ArrowFunctionExpression', | ||
| // Function expressions that are not contained within plain objects | ||
| // or are not arguments to functions or methods | ||
| ':not(Property, NewExpression, CallExpression) > FunctionExpression', | ||
| // Exported variables at the root | ||
| 'ExportNamedDeclaration:has(> VariableDeclaration)', | ||
| ], | ||
| }, | ||
| ], | ||
| // Consider copying this to @metamask/eslint-config | ||
| 'jsdoc/no-blank-blocks': 'error', | ||
|
Contributor
Author
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 realized that this existed and I found this to be a helpful rule. It seemed that with the new JSDoc rules, running |
||
| }, | ||
|
|
||
| settings: { | ||
| 'import-x/extensions': ['.js', '.mjs'], | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| files: ['**/*.ts'], | ||
| extends: typescript, | ||
| rules: { | ||
| // Consider copying this to @metamask/eslint-config | ||
| '@typescript-eslint/explicit-function-return-type': [ | ||
| 'error', | ||
| { | ||
| allowExpressions: true, | ||
|
Contributor
Author
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. Again, I found that this new rule was too strict. For instance: return {
// A return type is now required for this function
message: () => 'foo',
pass: false,
} |
||
| }, | ||
| ], | ||
| // Consider copying this to @metamask/eslint-config | ||
| 'jsdoc/require-jsdoc': [ | ||
| 'error', | ||
| { | ||
| require: { | ||
| // Classes | ||
| ClassDeclaration: true, | ||
| // Function declarations | ||
| FunctionDeclaration: true, | ||
| // Methods | ||
| MethodDefinition: true, | ||
| }, | ||
| contexts: [ | ||
| // Type interfaces that are not defined within `declare` blocks | ||
| ':not(TSModuleBlock) > TSInterfaceDeclaration', | ||
| // Type aliases | ||
| 'TSTypeAliasDeclaration', | ||
| // Enums | ||
| 'TSEnumDeclaration', | ||
| // Arrow functions that are not contained within plain objects or | ||
| // are not arguments to functions or methods | ||
| ':not(Property, NewExpression, CallExpression) > ArrowFunctionExpression', | ||
| // Function expressions that are not contained within plain objects | ||
| // or are not arguments to functions or methods | ||
| ':not(Property, NewExpression, CallExpression) > FunctionExpression', | ||
| // Exported variables at the root | ||
| 'ExportNamedDeclaration:has(> VariableDeclaration)', | ||
| ], | ||
| }, | ||
| ], | ||
| // Consider copying this to @metamask/eslint-config | ||
| 'jsdoc/no-blank-blocks': 'error', | ||
| }, | ||
| }, | ||
|
|
||
| { | ||
| files: ['**/*.js', '**/*.cjs', '**/*.ts', '**/*.test.ts', '**/*.test.js'], | ||
| ignores: ['src/ui/**'], | ||
| extends: nodejs, | ||
| }, | ||
|
|
||
| { | ||
| files: ['**/*.test.ts'], | ||
| extends: jest, | ||
| }, | ||
|
|
||
| // List this last to override any settings inherited from plugins, | ||
| // especially `eslint-config-n`, which mistakenly assumes that all `.cjs` | ||
| // files are modules (since we specified `type: module` in `package.json`) | ||
| { | ||
| files: ['**/*.js', '**/*.cjs'], | ||
| // This *is* a script, but is written using ESM. | ||
| ignores: ['bin/create-release-branch.js'], | ||
| languageOptions: { | ||
| sourceType: 'script', | ||
| }, | ||
| }, | ||
| ]); | ||
|
|
||
| export default config; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,11 @@ | ||
| import { fileURLToPath } from 'url'; | ||
| import { dirname } from 'path'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| /** | ||
| * Get the current directory path. | ||
| * | ||
| * @returns The current directory path. | ||
| */ | ||
| export function getCurrentDirectoryPath() { | ||
| return __dirname; | ||
| export function getCurrentDirectoryPath(): string { | ||
| return dirname(fileURLToPath(import.meta.url)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| import { getErrorMessage } from '@metamask/utils'; | ||
|
|
||
| import { getEnvironmentVariables } from './env.js'; | ||
| import { debug, resolveExecutable } from './misc-utils.js'; | ||
|
|
||
| /** | ||
| * Information about the editor present on the user's computer. | ||
| * | ||
| * @property path - The path to the executable representing the editor. | ||
| * @property args - Command-line arguments to pass to the executable when | ||
| * calling it. | ||
| * Properties: | ||
|
Contributor
Author
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.
|
||
| * | ||
| * - `path` - The path to the executable representing the editor. | ||
| * - `args` - Command-line arguments to pass to the executable when calling it. | ||
| */ | ||
| export type Editor = { | ||
| path: string; | ||
|
|
@@ -31,7 +34,7 @@ export async function determineEditor(): Promise<Editor | null> { | |
| executablePath = await resolveExecutable(EDITOR); | ||
| } catch (error) { | ||
| debug( | ||
| `Could not resolve executable ${EDITOR} (${error}), falling back to VSCode`, | ||
| `Could not resolve executable ${EDITOR} (${getErrorMessage(error)}), falling back to VSCode`, | ||
| ); | ||
| } | ||
| } | ||
|
|
@@ -43,7 +46,7 @@ export async function determineEditor(): Promise<Editor | null> { | |
| executableArgs.push('--wait'); | ||
| } catch (error) { | ||
| debug( | ||
| `Could not resolve path to VSCode: ${error}, continuing regardless`, | ||
| `Could not resolve path to VSCode: ${getErrorMessage(error)}, continuing regardless`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
As stated in the PR description, I found the new changes to this rule in MetaMask/eslint-config#394 rather strict. I removed
TSPropertySignatureas it began asking that properties in adhoc object types were documented. For instance:I also found a similar thing for arrow functions:
So, I amended what this rule is looking for, which is explained in the comments below. I feel like this makes more sense, but happy to know y'all's thoughts.
Uh oh!
There was an error while loading. Please reload this page.
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.
For future reference, I used https://astexplorer.net/ to test out the selectors (make sure to select
@typescript-eslint/parserand Transform > ESLint v8).