Skip to content

Commit 8e00507

Browse files
authored
chore: update typescript to ~v5.3.3 (#22530)
This PR updates our typescript version to 5.3.3 (currently the latest version). It also updates some eslint and babel dependencies as the older versions didn't work with the newer version of typescript. There were some rule changes: 1. `jsdoc/check-line-alignment` now requires consistent line wrap indentation. This is a large change that I don't want to make in this PR (it should be separate and the commit added to a `.git-blame-ignore-revs` file). 2. `Object<...>` type syntax in jsdoc is not allowed; I fixes the breakages in this PR, as they were minimal 3. JS files that were checked using `typescript-eslint` aren't anymore. It is no longer permitted to apply `typescript-eslint` to files that are not also included in our `tsconfig.json`, and since our JS does not pass the typechecker I had to remove `typescript-eslint` from some JS rules. 4. We previously had a rule `jest/no-large-snapshots`, but it wasn't actually enforced. This eslint package updates fix the rule, but we don't even come close to passing it, so I turned it off 5. ui/store/actions.ts was beyond repair. I've enabled `@ts-nocheck` for the entire file. I do NOT volunteer as tribute to fix this. :-) I have also simplified and updated our `tsconfig.json` to remove redundant options and align it with the features and files that we use. I've also added compilation caching, which makes successive typescript linting much faster. See comments in `tsconfig.json`. I've merged our `.prettierignore` and `eslint` ignore lists together, as the two lists seem to have diverged over time. Our `eslintrc.js` now imports `.prettierignore` so they won't diverge again in the future. Our eslint config now fully parses our `tsconfig.json` and only applies `typescript-eslint` to `.ts` and `.tsx` files that our tsconfig.json lists (the `.js` files don't typecheck sucessfully, so they aren't included).
1 parent 80d0822 commit 8e00507

File tree

17 files changed

+384
-394
lines changed

17 files changed

+384
-394
lines changed

.depcheckrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ignores:
2424
- '@metamask/phishing-warning' # statically hosted as part of some e2e tests
2525
- '@metamask/test-dapp'
2626
- '@metamask/design-tokens' # Only imported in index.css
27-
- '@tsconfig/node16' # required dynamically by TS, used in tsconfig.json
27+
- '@tsconfig/node20' # required dynamically by TS, used in tsconfig.json
2828
- '@sentry/cli' # invoked as `sentry-cli`
2929
- 'chromedriver'
3030
- 'depcheck' # ooo meta

.eslintrc.base.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ module.exports = {
1212
},
1313

1414
rules: {
15+
// TODO: re-enable once the proposed feature at https://github.com/gajus/eslint-plugin-jsdoc/pull/964#issuecomment-1936470252 is available
16+
'jsdoc/check-line-alignment': 'off',
17+
1518
'default-param-last': 'off',
1619
'prefer-object-spread': 'error',
1720
'require-atomic-updates': 'off',

.eslintrc.js

+47-26
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
const path = require('path');
2-
1+
const { readFileSync } = require('node:fs');
2+
const path = require('node:path');
3+
const ts = require('typescript');
34
const { version: reactVersion } = require('react/package.json');
45

6+
const tsconfigPath = ts.findConfigFile('./', ts.sys.fileExists);
7+
const { config } = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
8+
const tsconfig = ts.parseJsonConfigFileContent(config, ts.sys, './');
9+
10+
/**
11+
* @type {import('eslint').Linter.Config }
12+
*/
513
module.exports = {
614
root: true,
715
// Suggested addition from the storybook 6.5 update
816
extends: ['plugin:storybook/recommended'],
917
// Ignore files which are also in .prettierignore
10-
ignorePatterns: [
11-
'app/vendor/**',
12-
'builds/**/*',
13-
'development/chromereload.js',
14-
'development/charts/**',
15-
'development/ts-migration-dashboard/build/**',
16-
'dist/**/*',
17-
'node_modules/**/*',
18-
'storybook-build/**/*',
19-
'jest-coverage/**/*',
20-
'coverage/**/*',
21-
'public/**/*',
22-
],
18+
ignorePatterns: readFileSync('.prettierignore', 'utf8').trim().split('\n'),
19+
// eslint's parser, esprima, is not compatible with ESM, so use the babel parser instead
20+
parser: '@babel/eslint-parser',
2321
overrides: [
2422
/**
2523
* == Modules ==
@@ -125,13 +123,39 @@ module.exports = {
125123
* TypeScript files
126124
*/
127125
{
128-
files: ['*.{ts,tsx}'],
126+
files: tsconfig.fileNames.filter((f) => /\.tsx?$/u.test(f)),
127+
parserOptions: {
128+
project: tsconfigPath,
129+
// https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250
130+
tsconfigRootDir: path.dirname(tsconfigPath),
131+
},
129132
extends: [
130133
path.resolve(__dirname, '.eslintrc.base.js'),
131134
'@metamask/eslint-config-typescript',
132135
path.resolve(__dirname, '.eslintrc.typescript-compat.js'),
133136
],
134137
rules: {
138+
// this rule is new, but we didn't use it before, so it's off now
139+
'@typescript-eslint/no-duplicate-enum-values': 'off',
140+
'@typescript-eslint/no-shadow': [
141+
'error',
142+
{
143+
builtinGlobals: true,
144+
allow: [
145+
'ErrorOptions',
146+
'Text',
147+
'Screen',
148+
'KeyboardEvent',
149+
'Lock',
150+
'Notification',
151+
'CSS',
152+
],
153+
},
154+
],
155+
// `no-parameter-properties` was removed in favor of `parameter-properties`
156+
// Yeah, they have opposite names but do the same thing?!
157+
'@typescript-eslint/no-parameter-properties': 'off',
158+
'@typescript-eslint/parameter-properties': 'error',
135159
// Turn these off, as it's recommended by typescript-eslint.
136160
// See: <https://typescript-eslint.io/docs/linting/troubleshooting#eslint-plugin-import>
137161
'import/named': 'off',
@@ -298,13 +322,12 @@ module.exports = {
298322
rules: {
299323
'import/unambiguous': 'off',
300324
'import/named': 'off',
301-
'jest/no-large-snapshots': [
302-
'error',
303-
{
304-
maxSize: 50,
305-
inlineMaxSize: 50,
306-
},
307-
],
325+
// *.snap files weren't parsed by previous versions of this eslint
326+
// config section, but something got fixed somewhere, and now this rule
327+
// causes failures. We need to turn it off instead of fix them because
328+
// we aren't even remotely close to being in alignment. If it bothers
329+
// you open a PR to fix it yourself.
330+
'jest/no-large-snapshots': 'off',
308331
'jest/no-restricted-matchers': 'off',
309332

310333
/**
@@ -398,13 +421,11 @@ module.exports = {
398421
},
399422
},
400423
{
401-
files: ['ui/components/multichain/**/*.{js,ts,tsx}'],
424+
files: ['ui/components/multichain/**/*.{js}'],
402425
extends: [
403426
path.resolve(__dirname, '.eslintrc.base.js'),
404427
path.resolve(__dirname, '.eslintrc.node.js'),
405428
path.resolve(__dirname, '.eslintrc.babel.js'),
406-
path.resolve(__dirname, '.eslintrc.typescript-compat.js'),
407-
'@metamask/eslint-config-typescript',
408429
],
409430
rules: {
410431
'sort-imports': [

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ notes.txt
4949
.metamaskrc
5050
.metamaskprodrc
5151

52-
# TypeScript
53-
tsout/
54-
5552
# Test results
5653
test-results/
5754

.prettierignore

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
node_modules/**
1+
node_modules/**/*
22
lavamoat/**/policy.json
3-
dist/**
4-
builds/**
5-
test-*/**
6-
coverage/
7-
jest-coverage/
8-
storybook-build/
3+
dist/**/*
4+
builds/**/*
5+
test-*/**/*
96
app/vendor/**
10-
.nyc_output/**
11-
test/e2e/send-eth-with-private-key-test/**
7+
.nyc_output/**/*
8+
test/e2e/send-eth-with-private-key-test/**/*
129
*.scss
1310
development/chromereload.js
1411
development/ts-migration-dashboard/filesToConvert.json
15-
public
12+
development/ts-migration-dashboard/build/**
13+
public/**/*
14+
development/charts/**
15+
node_modules/**/*
16+
storybook-build/**/*
17+
jest-coverage/**/*
18+
coverage/**/*

app/scripts/lib/SnapsNameProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
AddressLookupResult,
1313
Snap as TruncatedSnap,
1414
} from '@metamask/snaps-sdk';
15+
// @ts-expect-error see: https://github.com/MetaMask/snaps/pull/2174
1516
import { HandlerType } from '@metamask/snaps-utils';
1617
import log from 'loglevel';
1718
import {

app/scripts/lib/snap-keyring/metrics.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { RestrictedControllerMessenger } from '@metamask/base-controller';
22
import { KeyringControllerGetKeyringForAccountAction } from '@metamask/keyring-controller';
33
import { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';
44
import { GetSnap } from '@metamask/snaps-controllers';
5+
// @ts-expect-error see: https://github.com/MetaMask/snaps/pull/2174
56
import { Snap } from '@metamask/snaps-utils';
67

78
type AllowedActions =

development/build/index.js

+32-24
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,38 @@ const createEtcTasks = require('./etc');
2929
const { getBrowserVersionMap, getEnvironment } = require('./utils');
3030
const { getConfig } = require('./config');
3131

32-
// Packages required dynamically via browserify configuration in dependencies
33-
// Required for LavaMoat policy generation
34-
require('loose-envify');
35-
require('@babel/preset-env');
36-
require('@babel/preset-react');
37-
require('@babel/preset-typescript');
38-
require('@babel/core');
39-
// ESLint-related
40-
require('@babel/eslint-parser');
41-
require('@babel/eslint-plugin');
42-
require('@metamask/eslint-config');
43-
require('@metamask/eslint-config-nodejs');
44-
require('@typescript-eslint/parser');
45-
require('eslint');
46-
require('eslint-config-prettier');
47-
require('eslint-import-resolver-node');
48-
require('eslint-import-resolver-typescript');
49-
require('eslint-plugin-import');
50-
require('eslint-plugin-jsdoc');
51-
require('eslint-plugin-node');
52-
require('eslint-plugin-prettier');
53-
require('eslint-plugin-react');
54-
require('eslint-plugin-react-hooks');
55-
require('eslint-plugin-jest');
32+
/* eslint-disable no-constant-condition, node/global-require */
33+
if (false) {
34+
// Packages required dynamically via browserify/eslint configuration in
35+
// dependencies. This is a workaround for LavaMoat's static analyzer used in
36+
// policy generation. To avoid the case where we need to write policy
37+
// overrides for these packages we can plop them here and they will be
38+
// included in the policy. Neat!
39+
require('loose-envify');
40+
require('@babel/preset-env');
41+
require('@babel/preset-react');
42+
require('@babel/preset-typescript');
43+
require('@babel/core');
44+
// ESLint-related
45+
require('@babel/eslint-parser');
46+
require('@babel/eslint-plugin');
47+
require('@metamask/eslint-config');
48+
require('@metamask/eslint-config-nodejs');
49+
// eslint-disable-next-line import/no-unresolved
50+
require('@typescript-eslint/parser');
51+
require('eslint');
52+
require('eslint-config-prettier');
53+
require('eslint-import-resolver-node');
54+
require('eslint-import-resolver-typescript');
55+
require('eslint-plugin-import');
56+
require('eslint-plugin-jsdoc');
57+
require('eslint-plugin-node');
58+
require('eslint-plugin-prettier');
59+
require('eslint-plugin-react');
60+
require('eslint-plugin-react-hooks');
61+
require('eslint-plugin-jest');
62+
}
63+
/* eslint-enable no-constant-condition, node/global-require */
5664

5765
defineAndRunBuildTasks().catch((error) => {
5866
console.error(error.stack || error);

0 commit comments

Comments
 (0)