diff --git a/eslint.config.mjs b/eslint.config.mjs index 28fa8118a..da976a22b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,30 +1,22 @@ // @ts-check -import metamaskConfig from '@metamask/eslint-config'; +import metamaskConfig, { createConfig } from '@metamask/eslint-config'; import metamaskNodeConfig from '@metamask/eslint-config-nodejs'; import metamaskTypescriptConfig from '@metamask/eslint-config-typescript'; import metamaskVitestConfig from '@metamask/eslint-config-vitest'; import globals from 'globals'; -/** @type {import('eslint').Linter.Config[]} */ -const config = [ - ...metamaskConfig, - ...metamaskNodeConfig, - ...metamaskTypescriptConfig.map((options) => ({ - ...options, - files: ['**/*.{ts,mts,cts}'], - })), - ...metamaskVitestConfig.map((options) => ({ - ...options, - files: ['**/*.test.{ts,js}'], - })), +const config = createConfig([ + { + extends: [metamaskConfig, metamaskNodeConfig], + }, { ignores: ['node_modules', '**/dist', '**/docs', '**/coverage'], }, { - files: ['**/*.{js,mjs}'], + files: ['**/*.js', '**/*.mjs'], languageOptions: { sourceType: 'module', }, @@ -40,41 +32,15 @@ const config = [ { languageOptions: { parserOptions: { - tsconfigRootDir: new URL('.', import.meta.url).pathname, - }, - globals: { - ...globals['shared-node-browser'], + projectService: true, + tsconfigRootDir: import.meta.dirname, }, }, - rules: { - 'import-x/no-useless-path-segments': [ - 'error', - { - // Enabling this causes false errors in ESM files. - noUselessIndex: false, - }, - ], - - // We have been hoisted by our own petard in the past. - 'import-x/no-cycle': ['error', { ignoreExternal: true, maxDepth: 3 }], - - // This is not compatible with ESM. - 'import-x/extensions': 'off', - - // We use unassigned imports for e.g. `import '@ocap/shims/endoify'`. - 'import-x/no-unassigned-import': 'off', - - // This prevents pretty formatting of comments with multi-line lists entries. - 'jsdoc/check-indentation': 'off', - - // This prevents using Node.js and/or browser specific globals. We - // currently use both in our codebase, so this rule is disabled. - 'no-restricted-globals': 'off', - }, }, { - files: ['**/*.{ts,mts,cts}'], + files: ['**/*.ts', '**/*.mts', '**/*.cts'], + extends: [metamaskTypescriptConfig], rules: { '@typescript-eslint/explicit-function-return-type': [ 'error', @@ -96,6 +62,7 @@ const config = [ { files: ['**/*.test.ts'], + extends: [metamaskVitestConfig], rules: { // This causes false positives in tests especially. '@typescript-eslint/unbound-method': 'off', @@ -115,6 +82,39 @@ const config = [ }, }, + { + languageOptions: { + globals: { + ...globals['shared-node-browser'], + }, + }, + rules: { + 'import-x/no-useless-path-segments': [ + 'error', + { + // Enabling this causes false errors in ESM files. + noUselessIndex: false, + }, + ], + + // We have been hoisted by our own petard in the past. + 'import-x/no-cycle': ['error', { ignoreExternal: true, maxDepth: 3 }], + + // This is not compatible with ESM. + 'import-x/extensions': 'off', + + // We use unassigned imports for e.g. `import '@ocap/shims/endoify'`. + 'import-x/no-unassigned-import': 'off', + + // This prevents pretty formatting of comments with multi-line lists entries. + 'jsdoc/check-indentation': 'off', + + // This prevents using Node.js and/or browser specific globals. We + // currently use both in our codebase, so this rule is disabled. + 'no-restricted-globals': 'off', + }, + }, + // ////////////////////////// // // Package-specific overrides // // ////////////////////////// // @@ -125,6 +125,6 @@ const config = [ globals: { lockdown: 'readonly' }, }, }, -]; +]); export default config; diff --git a/package.json b/package.json index 644642021..43b21e7fb 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,13 @@ "postinstall": "simple-git-hooks", "prepack": "./scripts/prepack.sh", "test": "yarn workspaces foreach --all --parallel --verbose run test", + "test:ts": "yarn workspaces foreach --all --parallel --verbose run test:ts", "test:clean": "yarn workspaces foreach --all --parallel --verbose run test:clean && yarn test", "test:verbose": "yarn workspaces foreach --all --parallel --verbose run test:verbose", "why:batch": "./scripts/why-batch.sh" }, "simple-git-hooks": { - "pre-commit": "yarn lint-staged && yarn dedupe --check" + "pre-commit": "yarn lint-staged && yarn test:ts && yarn dedupe --check" }, "lint-staged": { "*.{js,mjs,cjs,ts,mts,cts}": [ diff --git a/packages/errors/package.json b/packages/errors/package.json index bb358bcf2..da92c1d64 100644 --- a/packages/errors/package.json +++ b/packages/errors/package.json @@ -36,6 +36,7 @@ "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path ../../.gitignore", "publish:preview": "yarn npm publish --tag preview", "test": "vitest run --config vitest.config.ts", + "test:ts": "tsc --project tsconfig.test.json --noEmit", "test:clean": "yarn test --no-cache --coverage.clean", "test:dev": "yarn test --coverage false", "test:verbose": "yarn test --reporter verbose", diff --git a/packages/errors/src/BaseError.test.ts b/packages/errors/src/BaseError.test.ts index 29f1c75dc..dcc98f343 100644 --- a/packages/errors/src/BaseError.test.ts +++ b/packages/errors/src/BaseError.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest'; import { BaseError } from './BaseError.js'; import { ErrorCode } from './constants.js'; +import { unmarshalErrorOptions } from './marshal/unmarshalError.js'; import type { MarshaledOcapError } from './types.js'; describe('BaseError', () => { @@ -57,9 +58,9 @@ describe('BaseError', () => { }); it('throws an error when unmarshal is called', () => { - expect(() => BaseError.unmarshal({} as MarshaledOcapError)).toThrow( - 'Unmarshal method not implemented', - ); + expect(() => + BaseError.unmarshal({} as MarshaledOcapError, unmarshalErrorOptions), + ).toThrow('Unmarshal method not implemented'); }); it('initializes the stack property automatically if not provided', () => { diff --git a/packages/errors/tsconfig.test.json b/packages/errors/tsconfig.test.json new file mode 100644 index 000000000..0715ce811 --- /dev/null +++ b/packages/errors/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["./src"], + "exclude": ["./vite.config.ts", "./vitest.config.ts"] +} diff --git a/packages/errors/vitest.config.ts b/packages/errors/vitest.config.ts index de9febbf4..fd90b7b79 100644 --- a/packages/errors/vitest.config.ts +++ b/packages/errors/vitest.config.ts @@ -4,6 +4,7 @@ import path from 'path'; import { defineConfig, mergeConfig } from 'vite'; +// @ts-expect-error - no declaration for module import { getDefaultConfig } from '../../vitest.config.packages.js'; const defaultConfig = getDefaultConfig(); diff --git a/packages/extension/package.json b/packages/extension/package.json index 8347bf599..f221296bb 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -26,6 +26,7 @@ "publish:preview": "yarn npm publish --tag preview", "start": "yarn build:vite:dev --watch", "test": "vitest run --config vitest.config.ts", + "test:ts": "tsc --project tsconfig.test.json --noEmit", "test:build": "node ./test/build-tests.mjs", "test:clean": "yarn test --no-cache --coverage.clean", "test:dev": "yarn test --coverage false", diff --git a/packages/extension/tsconfig.json b/packages/extension/tsconfig.json index 8b114952a..02f4dbb59 100644 --- a/packages/extension/tsconfig.json +++ b/packages/extension/tsconfig.json @@ -22,6 +22,7 @@ "./vite-plugins/*.ts", "./test/**/*.ts", "./vite.config.ts", - "./vitest.config.ts" + "./vitest.config.ts", + "./scripts/build-constants.mjs" ] } diff --git a/packages/extension/tsconfig.test.json b/packages/extension/tsconfig.test.json new file mode 100644 index 000000000..86c6aa360 --- /dev/null +++ b/packages/extension/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["./src", "./test", "./scripts"], + "exclude": ["./vite.config.ts", "./vitest.config.ts"] +} diff --git a/packages/extension/vite.config.ts b/packages/extension/vite.config.ts index bd911ee9a..06ef1af18 100644 --- a/packages/extension/vite.config.ts +++ b/packages/extension/vite.config.ts @@ -11,8 +11,8 @@ import { buildDir, jsTrustedPreludes, } from './scripts/build-constants.mjs'; -import { htmlTrustedPrelude } from './vite-plugins/html-trusted-prelude'; -import { jsTrustedPrelude } from './vite-plugins/js-trusted-prelude'; +import { htmlTrustedPrelude } from './vite-plugins/html-trusted-prelude.js'; +import { jsTrustedPrelude } from './vite-plugins/js-trusted-prelude.js'; /** * Files that need to be statically copied to the destination directory. diff --git a/packages/kernel/package.json b/packages/kernel/package.json index 862f25257..2c3ba8cc1 100644 --- a/packages/kernel/package.json +++ b/packages/kernel/package.json @@ -36,6 +36,7 @@ "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path ../../.gitignore", "publish:preview": "yarn npm publish --tag preview", "test": "vitest run --config vitest.config.ts", + "test:ts": "tsc --project tsconfig.test.json --noEmit", "test:clean": "yarn test --no-cache --coverage.clean", "test:dev": "yarn test --coverage false", "test:verbose": "yarn test --reporter verbose", diff --git a/packages/kernel/tsconfig.test.json b/packages/kernel/tsconfig.test.json new file mode 100644 index 000000000..4bfedb895 --- /dev/null +++ b/packages/kernel/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["./src", "./test"], + "exclude": ["./vite.config.ts", "./vitest.config.ts"] +} diff --git a/packages/shims/package.json b/packages/shims/package.json index e14fd93aa..538f4f175 100644 --- a/packages/shims/package.json +++ b/packages/shims/package.json @@ -30,6 +30,7 @@ "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path ../../.gitignore", "publish:preview": "yarn npm publish --tag preview", "test": "vitest run --config vitest.config.ts", + "test:ts": "tsc --project tsconfig.test.json --noEmit", "test:clean": "yarn test --no-cache --coverage.clean", "test:dev": "yarn test --coverage false", "test:verbose": "yarn test --reporter verbose", diff --git a/packages/shims/tsconfig.test.json b/packages/shims/tsconfig.test.json new file mode 100644 index 000000000..0715ce811 --- /dev/null +++ b/packages/shims/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["./src"], + "exclude": ["./vite.config.ts", "./vitest.config.ts"] +} diff --git a/packages/streams/package.json b/packages/streams/package.json index cc5000eca..ecf070e3d 100644 --- a/packages/streams/package.json +++ b/packages/streams/package.json @@ -40,6 +40,7 @@ "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path ../../.gitignore", "publish:preview": "yarn npm publish --tag preview", "test": "vitest run --config vitest.config.ts", + "test:ts": "tsc --project tsconfig.test.json --noEmit", "test:clean": "yarn test --no-cache --coverage.clean", "test:dev": "yarn test --coverage false", "test:verbose": "yarn test --reporter verbose", diff --git a/packages/streams/tsconfig.test.json b/packages/streams/tsconfig.test.json new file mode 100644 index 000000000..4bfedb895 --- /dev/null +++ b/packages/streams/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["./src", "./test"], + "exclude": ["./vite.config.ts", "./vitest.config.ts"] +} diff --git a/packages/utils/package.json b/packages/utils/package.json index fb3a34a70..30dd0f373 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -36,6 +36,7 @@ "lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.html' '!**/CHANGELOG.old.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path ../../.gitignore", "publish:preview": "yarn npm publish --tag preview", "test": "vitest run --config vitest.config.ts", + "test:ts": "tsc --project tsconfig.test.json --noEmit", "test:clean": "yarn test --no-cache --coverage.clean", "test:dev": "yarn test --coverage false", "test:verbose": "yarn test --reporter verbose", diff --git a/packages/utils/tsconfig.test.json b/packages/utils/tsconfig.test.json new file mode 100644 index 000000000..0715ce811 --- /dev/null +++ b/packages/utils/tsconfig.test.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true + }, + "include": ["./src"], + "exclude": ["./vite.config.ts", "./vitest.config.ts"] +} diff --git a/yarn.config.cjs b/yarn.config.cjs index 5baf49ce6..06e1a0523 100644 --- a/yarn.config.cjs +++ b/yarn.config.cjs @@ -233,8 +233,8 @@ module.exports = defineConfig({ ); expectWorkspaceField( workspace, - 'scripts.test', - 'vitest run --config vitest.config.ts', + 'scripts.test:ts', + 'tsc --project tsconfig.test.json --noEmit', ); expectWorkspaceField( workspace,