Skip to content
Merged
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
1 change: 0 additions & 1 deletion packages/create-snap/src/cmds/init/initHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import cliPackageJson from '@metamask/create-snap/package.json';

Check failure on line 1 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

There should be at least one empty line between import groups

Check failure on line 1 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

`@metamask/create-snap/package.json` import should occur after import of `./initUtils`
import type { NpmSnapPackageJson } from '@metamask/snaps-utils';
import {
NpmSnapFileNames,
Expand All @@ -12,7 +11,7 @@
import type { SemVer } from 'semver';
import semver from 'semver';

import type { YargsArgs } from '../../types/yargs';

Check failure on line 14 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

`../../types/yargs` type import should occur after import of `./initUtils`
import {
buildSnap,
cloneTemplate,
Expand All @@ -38,9 +37,9 @@
const { directory } = argv;

const versionRange = cliPackageJson.engines.node;
const minimumVersion = (semver.minVersion(versionRange) as SemVer).format();

Check failure on line 40 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Caution: `semver` also has a named export `minVersion`. Check if you meant to write `import {minVersion} from 'semver'` instead

const isVersionSupported = semver.satisfies(process.version, versionRange);

Check failure on line 42 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Caution: `semver` also has a named export `satisfies`. Check if you meant to write `import {satisfies} from 'semver'` instead

if (!isVersionSupported) {
throw new Error(
Expand Down Expand Up @@ -71,7 +70,7 @@
force: true,
recursive: true,
});
} catch (error) {

Check failure on line 73 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

'error' is defined but never used
throw new Error('Init Error: Failed to create template.');
}

Expand Down Expand Up @@ -106,7 +105,7 @@
...argv,
dist: distPath[0],
outfileName: distPath[1],
src: packageJson.main || 'src/index.js',

Check failure on line 108 in packages/create-snap/src/cmds/init/initHandler.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
snapLocation,
};
}
2 changes: 1 addition & 1 deletion packages/create-snap/src/types/yargs.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Options } from 'yargs';

// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type OptionalArguments<Type = {}> = Type & {
/** Non-option arguments */
_?: (string | number)[];
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"sideEffects": false,
"files": [],
"scripts": {
"build": "yarn workspaces foreach --worktree --parallel --verbose --no-private run build",
"build": "yarn workspaces filter --include 'packages/examples/packages/**' --parallel --no-private run build",
"build:clean": "yarn clean && yarn build",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/example-snaps",
"changelog:validates": "yarn workspaces foreach --worktree --parallel --verbose run changelog:validate",
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/packages/bip32/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
const { message, curve, ...params } = request.params as SignMessageParams;

if (!message || typeof message !== 'string') {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new InvalidParamsError(`Invalid signature data: "${message}".`);
}

Expand Down Expand Up @@ -74,7 +73,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -100,7 +98,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
2 changes: 0 additions & 2 deletions packages/examples/packages/bip44/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -68,7 +67,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {

// For this example we use Babel to transpile the TypeScript code to
// JavaScript.
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports, n/global-require
bundler.transform(require('babelify'), {
...babelConfig,
extensions: ['.js', '.ts'],
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/browserify-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return 'Hello from Browserify!';

default: {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/browserify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return 'Hello from the MetaMask Snaps CLI using Browserify!';

default: {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/client-status/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
2 changes: 0 additions & 2 deletions packages/examples/packages/cronjobs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {
},
});
default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Expand Down Expand Up @@ -105,7 +104,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
method: 'snap_getBackgroundEvents',
});
default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/dialogs/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/ethereum-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
2 changes: 0 additions & 2 deletions packages/examples/packages/ethers-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!result) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

return wallet.signMessage(params.message);
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/file-upload/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({
method: request.method,
});
Expand Down
2 changes: 0 additions & 2 deletions packages/examples/packages/get-entropy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -58,7 +57,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/get-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/images/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/interactive-ui/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({
method: request.method,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

if (!approved) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new UserRejectedRequestError();
}

Expand All @@ -84,7 +83,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
9 changes: 8 additions & 1 deletion packages/examples/packages/invoke-snap/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"composite": false
"composite": false,
"module": "CommonJS",
"moduleResolution": "Node10",
"paths": {
"@metamask/snaps-sdk/jsx-dev-runtime": ["../../../../../snaps-sdk/src/jsx/jsx-dev-runtime.ts", "../../../snaps-sdk/src/jsx/jsx-dev-runtime.ts", "../snaps-sdk/src/jsx/jsx-dev-runtime.ts"],
"@metamask/snaps-sdk/jsx": ["../../../../../snaps-sdk/src/jsx", "../../../snaps-sdk/src/jsx", "../snaps-sdk/src/jsx"],
"@metamask/snaps-sdk": ["../../../../../snaps-sdk/src", "../../../snaps-sdk/src", "../snaps-sdk/src"]
}
}
}
1 change: 0 additions & 1 deletion packages/examples/packages/json-rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/localization/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return await getMessage('hello');

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/manage-state/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
11 changes: 2 additions & 9 deletions packages/examples/packages/network-access/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { expect } from '@jest/globals';
import { NodeProcessExecutionService } from '@metamask/snaps-controllers/node';
import { installSnap } from '@metamask/snaps-jest';

describe('onRpcRequest', () => {
// This test is disabled as it does not currently work
// TODO(ritave): Fix this test
it('throws an error if the requested method does not exist', async () => {
const { request } = await installSnap({
executionService: NodeProcessExecutionService,
});
const { request } = await installSnap();

const response = await request({
method: 'foo',
Expand All @@ -27,10 +22,8 @@

describe('fetch', () => {
// This test is disabled as it is flaky.
it.skip('fetches a URL and returns the JSON response', async () => {

Check warning on line 25 in packages/examples/packages/network-access/src/index.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint

Disabled test
const { request } = await installSnap({
executionService: NodeProcessExecutionService,
});
const { request } = await installSnap();

const url = 'https://dummyjson.com/http/200';
const response = await request({
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/network-access/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/notifications/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import createSpinner from 'yocto-spinner';

// ESLint doesn't understand the JSON import type.
// eslint-disable-next-line
import packageFile from '../package.json' with { type: 'json' };

const CURRENT_PATH = dirname(fileURLToPath(import.meta.url));
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/preinstalled/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const onProtocolRequest: OnProtocolRequestHandler = async ({
}

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
1 change: 0 additions & 1 deletion packages/examples/packages/rollup-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return 'Hello from Rollup!';

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
4 changes: 1 addition & 3 deletions packages/examples/packages/wasm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import {
} from '@metamask/snaps-sdk';

// This is only imported for its type. It is not used at runtime.
// eslint-disable-next-line import/order
// eslint-disable-next-line import-x/order
import type { instantiate } from '../build/program';

// This is the WASM module, generated by AssemblyScript, inlined as an object
// containing the functions exported by the WASM module.
// eslint-disable-next-line import/extensions
import * as program from '../build/program.wasm';

/**
Expand Down Expand Up @@ -50,6 +49,5 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return program[method](...params);
}

// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
};
2 changes: 1 addition & 1 deletion packages/examples/packages/wasm/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* so we need to declare a type for them here. This allows us to import them
* in our code, and have TypeScript understand that they are valid modules.
*/
// eslint-disable-next-line import/unambiguous
// eslint-disable-next-line import-x/unambiguous
declare module '*.wasm' {
import type { instantiate } from '@metamask/wasm-example-snap/build/program';

Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return 'Hello from Webpack!';

default:
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw new MethodNotFoundError({ method: request.method });
}
};
10 changes: 9 additions & 1 deletion packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"baseUrl": "./"
"baseUrl": "./",
"composite": false,
"module": "CommonJS",
"moduleResolution": "Node10",
"paths": {
"@metamask/snaps-sdk/jsx-dev-runtime": ["../../../snaps-sdk/src/jsx/jsx-dev-runtime.ts", "../snaps-sdk/src/jsx/jsx-dev-runtime.ts"],
"@metamask/snaps-sdk/jsx": ["../../../snaps-sdk/src/jsx", "../snaps-sdk/src/jsx"],
"@metamask/snaps-sdk": ["../../../snaps-sdk/src", "../snaps-sdk/src"],
}
Comment on lines +5 to +12
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes make the // eslint-disable-next-line @typescript-eslint/no-throw-literal comments in the examples unnecessary. Before, it would depend on build output whether these comments were necessary or not.

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/unambiguous
declare module 'readable-stream' {
export type {
DuplexOptions,
Expand Down
1 change: 0 additions & 1 deletion packages/snaps-cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import packageJson from '@metamask/snaps-cli/package.json';
import type { SemVer } from 'semver';
import semver from 'semver';
Expand Down
1 change: 0 additions & 1 deletion packages/snaps-cli/src/commands/build/__test__/snap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports.onRpcRequest = ({ request }) => {
// eslint-disable-next-line no-console
console.log('Hello, world!');

const { method, id } = request;
Expand Down
Loading
Loading