Skip to content

chore: Migrate to ESLint v9 #243

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .eslintrc.js

This file was deleted.

47 changes: 47 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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,
project: ['./tsconfig.json'],
},
},

settings: {
'import-x/extensions': ['.js', '.mjs'],
},
},

{
files: ['**/*.ts'],
extends: typescript,
},

{
files: ['**/*.js', '**/*.cjs'],
extends: nodejs,

languageOptions: {
sourceType: 'script',
},
},

{
files: ['**/*.test.ts', '**/*.test.js'],
extends: [jest, nodejs],
},
]);

export default config;
39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"build": "ts-bridge --project tsconfig.build.json --clean",
"build:docs": "typedoc",
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
"lint:changelog": "auto-changelog validate --prettier",
"lint:changelog": "auto-changelog validate",
"lint:constraints": "yarn constraints",
"lint:dependencies": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,ts",
Expand Down Expand Up @@ -74,39 +74,42 @@
"devDependencies": {
"@lavamoat/allow-scripts": "^3.0.4",
"@lavamoat/preinstall-always-fail": "^1.0.0",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^12.0.0",
"@metamask/eslint-config-jest": "^12.0.0",
"@metamask/eslint-config-nodejs": "^12.0.0",
"@metamask/eslint-config-typescript": "^12.0.0",
"@metamask/auto-changelog": "^4.1.0",
"@metamask/eslint-config": "^14.0.0",
"@metamask/eslint-config-jest": "^14.0.0",
"@metamask/eslint-config-nodejs": "^14.0.0",
"@metamask/eslint-config-typescript": "^14.0.0",
"@ts-bridge/cli": "^0.1.2",
"@ts-bridge/shims": "^0.1.1",
"@types/jest": "^28.1.7",
"@types/jest-when": "^3.5.3",
"@types/node": "~18.18.14",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@typescript-eslint/eslint-plugin": "^8.26.1",
"@typescript-eslint/parser": "^8.26.1",
"@typescript-eslint/utils": "^8.26.1",
"depcheck": "^1.4.7",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import-x": "^4.3.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-jsdoc": "^50.2.4",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.1.0",
"jest": "^29.2.2",
"jest-it-up": "^2.0.2",
"jest-when": "^3.6.0",
"prettier": "^2.7.1",
"prettier": "^3.3.3",
"prettier-plugin-packagejson": "^2.3.0",
"stdio-mock": "^1.2.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.7.0",
"tsd": "^0.29.0",
"typedoc": "^0.23.15",
"typescript": "~5.0.4"
"typescript": "~5.8.2",
"typescript-eslint": "^8.26.1"
},
"packageManager": "yarn@3.8.5",
"engines": {
Expand Down
2 changes: 0 additions & 2 deletions src/__fixtures__/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
['a', 2, null],
[{ a: null, b: 2, c: [{ foo: 'bar' }] }],
],
invalid: [undefined, Symbol('bar'), () => 'foo', [{ a: undefined }]],

Check failure on line 8 in src/__fixtures__/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing return type on function
};

export const JSON_RPC_NOTIFICATION_FIXTURES = {
Expand Down Expand Up @@ -1054,7 +1054,6 @@
],
};

/* eslint-disable @typescript-eslint/naming-convention */
export const CHARACTER_MAP = {
'"': '\\"',
'\\': '\\\\',
Expand Down Expand Up @@ -1091,7 +1090,6 @@
'\x1E': '\\u001e',
'\x1F': '\\u001f',
};
/* eslint-enable @typescript-eslint/naming-convention */

const DIRECT_CIRCULAR_REFERENCE_ARRAY: unknown[] = [];
DIRECT_CIRCULAR_REFERENCE_ARRAY.push(DIRECT_CIRCULAR_REFERENCE_ARRAY);
Expand All @@ -1113,13 +1111,13 @@
};

const TO_JSON_CIRCULAR_REFERENCE = {
toJSON() {

Check failure on line 1114 in src/__fixtures__/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing return type on function
return {};
},
};

const CIRCULAR_REFERENCE = { prop: TO_JSON_CIRCULAR_REFERENCE };
TO_JSON_CIRCULAR_REFERENCE.toJSON = function () {

Check failure on line 1120 in src/__fixtures__/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing return type on function
return CIRCULAR_REFERENCE;
};

Expand Down Expand Up @@ -1339,7 +1337,7 @@
levelTwo: {
levelThree: {
levelFour: {
levelFive: () => {

Check failure on line 1340 in src/__fixtures__/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing return type on function
return 'anything';
},
},
Expand All @@ -1359,7 +1357,7 @@
},
{
value: [
function () {

Check failure on line 1360 in src/__fixtures__/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing return type on function
return 'whatever';
},
],
Expand Down Expand Up @@ -1476,7 +1474,7 @@
},
{
value: {
get key() {

Check failure on line 1477 in src/__fixtures__/json.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing return type on function
throw new Error();
},
},
Expand Down
11 changes: 8 additions & 3 deletions src/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
* @param message - The error message.
* @returns The error object.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention

/**

Check failure on line 47 in src/assert.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (22.x)

Missing JSDoc @returns declaration
*
* @param ErrorWrapper
* @param message
*/
function getError(ErrorWrapper: AssertionErrorConstructor, message: string) {
if (isConstructable(ErrorWrapper)) {
return new ErrorWrapper({
Expand Down Expand Up @@ -81,7 +86,7 @@
export function assert(
value: any,
message: string | Error = 'Assertion failed.',
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper: AssertionErrorConstructor = AssertionError,
): asserts value {
if (!value) {
Expand All @@ -108,7 +113,7 @@
value: unknown,
struct: Struct<Type, Schema>,
errorPrefix = 'Assertion failed',
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper: AssertionErrorConstructor = AssertionError,
): asserts value is Type {
try {
Expand Down
8 changes: 4 additions & 4 deletions src/collections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('FrozenMap', () => {
const frozenMap = new FrozenMap([['a', 1]]);
frozenMap.forEach(function () {
// @ts-expect-error: We have to shadow `this` here.
expect(this).toBeUndefined(); // eslint-disable-line no-invalid-this
expect(this).toBeUndefined();
});
});

Expand All @@ -113,7 +113,7 @@ describe('FrozenMap', () => {
const thisArg = {};
frozenMap.forEach(function () {
// @ts-expect-error: We have to shadow `this` here.
expect(this).toBe(thisArg); // eslint-disable-line no-invalid-this
expect(this).toBe(thisArg);
}, thisArg);
});

Expand Down Expand Up @@ -317,7 +317,7 @@ describe('FrozenSet', () => {
const frozenSet = new FrozenSet(['a']);
frozenSet.forEach(function () {
// @ts-expect-error: We have to shadow `this` here.
expect(this).toBeUndefined(); // eslint-disable-line no-invalid-this
expect(this).toBeUndefined();
});
});

Expand All @@ -327,7 +327,7 @@ describe('FrozenSet', () => {
const thisArg = {};
frozenSet.forEach(function () {
// @ts-expect-error: We have to shadow `this` here.
expect(this).toBe(thisArg); // eslint-disable-line no-invalid-this
expect(this).toBe(thisArg);
}, thisArg);
});

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ export * from './caip-types';
export * from './checksum';
export * from './coercers';
export * from './collections';
export * from './encryption-types';
export type * from './encryption-types';
export * from './errors';
export * from './hex';
export * from './json';
export * from './keyring';
export type * from './keyring';
export * from './logging';
export * from './misc';
export * from './number';
export * from './opaque';
export type * from './opaque';
export * from './promise';
export * from './superstruct';
export * from './time';
export * from './transaction-types';
export type * from './transaction-types';
export * from './versions';
16 changes: 8 additions & 8 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export function getJsonSize(value: unknown): number {
/**
* The string '2.0'.
*/
export const jsonrpc2 = '2.0' as const;
export const jsonrpc2 = '2.0';
export const JsonRpcVersionStruct = literal(jsonrpc2);

/**
Expand Down Expand Up @@ -385,7 +385,7 @@ export function isJsonRpcNotification(
*/
export function assertIsJsonRpcNotification(
value: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts value is JsonRpcNotification {
assertStruct(
Expand Down Expand Up @@ -416,7 +416,7 @@ export function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {
*/
export function assertIsJsonRpcRequest(
value: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts value is JsonRpcRequest {
assertStruct(
Expand Down Expand Up @@ -510,7 +510,7 @@ export function isPendingJsonRpcResponse(
*/
export function assertIsPendingJsonRpcResponse(
response: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts response is PendingJsonRpcResponse {
assertStruct(
Expand Down Expand Up @@ -543,7 +543,7 @@ export function isJsonRpcResponse(
*/
export function assertIsJsonRpcResponse(
value: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts value is JsonRpcResponse {
assertStruct(
Expand Down Expand Up @@ -574,7 +574,7 @@ export function isJsonRpcSuccess(value: unknown): value is JsonRpcSuccess {
*/
export function assertIsJsonRpcSuccess(
value: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts value is JsonRpcSuccess {
assertStruct(
Expand Down Expand Up @@ -605,7 +605,7 @@ export function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {
*/
export function assertIsJsonRpcFailure(
value: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts value is JsonRpcFailure {
assertStruct(
Expand Down Expand Up @@ -636,7 +636,7 @@ export function isJsonRpcError(value: unknown): value is JsonRpcError {
*/
export function assertIsJsonRpcError(
value: unknown,
// eslint-disable-next-line @typescript-eslint/naming-convention

ErrorWrapper?: AssertionErrorConstructor,
): asserts value is JsonRpcError {
assertStruct(
Expand Down
5 changes: 2 additions & 3 deletions src/misc.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isObject, hasProperty, getKnownPropertyNames } from './misc';
//=============================================================================

class ClassWithPrivateProperties {
#foo: string;
readonly #foo: string;

bar: string;

Expand Down Expand Up @@ -47,7 +47,7 @@ if (hasProperty(constObjectType, 'foo')) {
//=============================================================================

// eslint-disable-next-line @typescript-eslint/ban-types
const unknownObject = {} as Object;
const unknownObject = {} as object;

// Establish that `Object` is not accepted when a specific property is needed.
expectNotAssignable<Record<'foo', unknown>>(unknownObject);
Expand Down Expand Up @@ -143,7 +143,6 @@ expectAssignable<RuntimeObject>({});

expectAssignable<RuntimeObject>({ foo: 'foo' });

// eslint-disable-next-line @typescript-eslint/naming-convention
expectAssignable<RuntimeObject>({ 0: 'foo' });

expectAssignable<RuntimeObject>({ [Symbol('foo')]: 'foo' });
Expand Down
2 changes: 1 addition & 1 deletion src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function isObject(value: unknown): value is RuntimeObject {
*/
export const hasProperty = <
// eslint-disable-next-line @typescript-eslint/ban-types
ObjectToCheck extends Object,
ObjectToCheck extends object,
Property extends PropertyKey,
>(
objectToCheck: ObjectToCheck,
Expand Down
1 change: 1 addition & 0 deletions src/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* A deferred Promise is one that can be resolved or rejected independently of
* the Promise construction.
*
* @template Result - The result type of the Promise.
*/
export type DeferredPromise<Result = void> = {
Expand Down
Loading
Loading