Skip to content

Commit

Permalink
Bump eslint to ^9.11.1 and migrate to flat config (#4727)
Browse files Browse the repository at this point in the history
We recently released new versions of our ESLint packages to rely on
ESLint 9. This PR bumps all of the ESLint-related packages in this repo
to match, and migrates the current ESLint config into the new flat
format. It also upgrades Prettier to v3.

---------

Co-authored-by: Elliot Winkler <[email protected]>
  • Loading branch information
MajorLift and mcmire authored Jan 9, 2025
1 parent 70ecb88 commit 3535d58
Show file tree
Hide file tree
Showing 10 changed files with 1,041 additions and 1,905 deletions.
11 changes: 8 additions & 3 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ ignores:
- 'simple-git-hooks'
- 'ts-node'
- 'typedoc'
# Ignore plugins implicitly imported by tools
# Ignore plugins for tools
- '@typescript-eslint/*'
- 'babel-jest'
- 'eslint-config-*'
- 'eslint-plugin-*'
- 'jest-silent-reporter'
- 'prettier-plugin-packagejson'
# Ignore plugins we explicitly use with tools
- 'babel-jest'
- 'typescript-eslint'
# Ignore dependencies imported implicitly by tools
- 'eslint-import-resolver-typescript'
# Ignore dependencies which plug into the NPM lifecycle
- '@lavamoat/preinstall-always-fail'
141 changes: 0 additions & 141 deletions .eslintrc.js

This file was deleted.

152 changes: 152 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import base, { createConfig } from '@metamask/eslint-config';
import nodejs from '@metamask/eslint-config-nodejs';
import jest from '@metamask/eslint-config-jest';
import typescript from '@metamask/eslint-config-typescript';

const config = createConfig(
{
ignores: [
'yarn.lock',
'**/**.map',
'**/**.tsbuildinfo',
'**/*.json',
'**/*.md',
'**/LICENSE',
'**/*.sh',
'**/.DS_Store',
'**/dist/**',
'**/docs/**',
'**/coverage/**',
'merged-packages/**',
'.yarn/**',
'scripts/create-package/package-template/**',
],
},
...base,
{
rules: {
// Left disabled because various properties throughough this repo are snake_case because the
// names come from external sources or must comply with standards
// e.g. `txreceipt_status`, `signTypedData_v4`, `token_id`
camelcase: 'off',
'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',
'lines-around-comment': 'off',
'n/no-sync': 'off',
'no-async-promise-executor': 'off',
'no-case-declarations': 'off',
'no-invalid-this': 'off',
'no-negated-condition': 'off',
'no-new': 'off',
'no-param-reassign': 'off',
'no-restricted-syntax': 'off',
radix: 'off',
'require-atomic-updates': 'off',
'jsdoc/match-description': [
'off',
{ matchDescription: '^[A-Z`\\d_][\\s\\S]*[.?!`>)}]$' },
],
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
},
{
files: [
'**/jest.config.js',
'**/jest.environment.js',
'**/tests/**/*.{ts,js}',
'*.js',
'*.test.{ts,js}',
'scripts/*.ts',
'scripts/create-package/*.ts',
'yarn.config.cjs',
],
extends: [nodejs],
},
{
files: ['*.test.{ts,js}', '**/tests/**/*.{ts,js}'],
extends: [jest],
},
{
// 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}'],
rules: {
'jest/no-export': 'off',
'jest/require-top-level-describe': 'off',
'jest/no-if': 'off',
},
},
{
files: ['*.js', '*.cjs'],
parserOptions: {
sourceType: 'script',
ecmaVersion: '2020',
},
},
{
files: ['*.ts'],
extends: [typescript],
parserOptions: {
tsconfigRootDir: import.meta.dirname,
project: ['./tsconfig.packages.json'],
},
rules: {
// 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/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/prefer-enum-initializers': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-reduce-type-parameter': 'off',
'no-restricted-syntax': 'off',
'no-restricted-globals': 'off',
},
},
{
files: ['tests/setupAfterEnv/matchers.ts'],
parserOptions: {
sourceType: 'script',
},
},
{
files: ['*.d.ts'],
rules: {
'@typescript-eslint/naming-convention': 'warn',
'import/unambiguous': 'off',
},
},
{
files: ['scripts/*.ts'],
rules: {
// All scripts will have shebangs.
'n/shebang': 'off',
},
},
{
files: ['**/jest.environment.js'],
rules: {
// These files run under Node, and thus `require(...)` is expected.
'n/global-require': 'off',
},
},
);

export default config;
Loading

0 comments on commit 3535d58

Please sign in to comment.