Skip to content

Commit

Permalink
Bump ESLint configs to latest version (#963)
Browse files Browse the repository at this point in the history
* Bump ESLint configs and use experimental new TypeScript rules

* Run eslint --fix

* Enable allowAny for restrict-template-expressions

* Bump all configs

* Suppress Yarn messages

* Fix some configs

* Disable rules for all files

* Fix examples

* Fix multichain-provider

* Fix rpc-methods

* Fix snaps-browserify-plugin

* Fix snaps-cli

* snaps-utils

* Fix snaps-controllers

* Fix snaps-rollup-plugin

* Fix some type errors

* Fix linting in `execution-environment` (#977)

* Update example manifests

* Fix a few more lint errors

* Fix most tests

* Fix snaps-controllers tests

* Fix more tests

Co-authored-by: Olaf Tomalka <[email protected]>
Co-authored-by: Guillaume Roux <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2022
1 parent c12b7f8 commit 1df275d
Show file tree
Hide file tree
Showing 232 changed files with 2,842 additions and 2,321 deletions.
47 changes: 46 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,61 @@ module.exports = {

extends: ['@metamask/eslint-config'],

parserOptions: {
tsconfigRootDir: __dirname,
},

env: {
'shared-node-browser': true,
},

rules: {
// This prevents importing Node.js builtins. We currently use them in
// our codebase, so this rule is disabled. This rule should be disabled
// in `@metamask/eslint-config-nodejs` in the future.
'import/no-nodejs-modules': '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',

// This rule disallows the `private` modifier on class fields, but we
// use it in some places. It also disables function expressions, but this
// triggers for class methods as well.
'no-restricted-syntax': 'off',
},

overrides: [
{
files: ['**/*.js'],
extends: ['@metamask/eslint-config-nodejs'],

rules: {
// 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'],
extends: ['@metamask/eslint-config-typescript'],
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
// This rule disallows the `private` modifier on class fields, but we
// use it in some places. It also disables function expressions, but this
// triggers for class methods as well.
'no-restricted-syntax': 'off',

// Without the `allowAny` option, this rule causes a lot of false
// positives.
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowAny: true,
allowBoolean: true,
allowNumber: true,
},
],
},
},

Expand All @@ -25,6 +69,7 @@ module.exports = {
'error',
{ allow: ['describe', 'expect', 'it'] },
],
'@typescript-eslint/unbound-method': 'off',
},
},
],
Expand Down
6 changes: 6 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
enableScripts: false

enableTelemetry: 0

logFilters:
- code: YN0004
level: discard

nodeLinker: node-modules

plugins:
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^2.6.0",
"@metamask/eslint-config": "^9.0.0",
"@metamask/eslint-config-jest": "^9.0.0",
"@metamask/eslint-config-nodejs": "^9.0.0",
"@metamask/eslint-config-typescript": "^9.0.1",
"@metamask/eslint-config": "^11.0.0",
"@metamask/eslint-config-jest": "^11.0.0",
"@metamask/eslint-config-nodejs": "^11.0.0",
"@metamask/eslint-config-typescript": "^11.0.0",
"@types/jest": "^27.5.1",
"@types/node": "^14.14.25",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-jsdoc": "^36.1.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.0.2",
"lint-staged": "^12.4.1",
"prettier": "^2.3.2",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"simple-git-hooks": "^2.7.0",
"ts-jest": "^29.0.0",
"typescript": "^4.4.0"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/examples/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = {
extends: ['../../.eslintrc.js'],

parserOptions: {
tsconfigRootDir: __dirname,
},

overrides: [
{
files: ['examples/**/*.js', 'examples/**/*.ts'],
Expand Down
18 changes: 10 additions & 8 deletions packages/examples/examples/bls-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@
"@metamask/eslint-config-nodejs": "^9.0.0",
"@metamask/eslint-config-typescript": "^9.0.1",
"@metamask/snaps-cli": "^0.24.1",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-jsdoc": "^36.1.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/examples/examples/browserify/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['../../.eslintrc.js'],

parserOptions: {
tsconfigRootDir: __dirname,
},
};
3 changes: 2 additions & 1 deletion packages/examples/examples/browserify/gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { series, dest } from 'gulp';
import browserify from 'browserify';
import { series, dest } from 'gulp';
import source from 'vinyl-source-stream';
import watchify from 'watchify';

import babelConfig from './babel.config.json';

const ENTRY_POINT = './src/snap.ts';
Expand Down
18 changes: 10 additions & 8 deletions packages/examples/examples/browserify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@
"@types/node": "^17.0.33",
"@types/vinyl-source-stream": "^0.0.30",
"@types/watchify": "^3.11.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"concurrently": "^7.1.0",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-jsdoc": "^36.1.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-prettier": "^4.2.1",
"gulp": "^4.0.2",
"prettier": "^2.3.2",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"ts-node": "^10.7.0",
"typescript": "^4.6.4",
"typescript": "~4.8.4",
"vinyl-source-stream": "^2.0.0",
"watchify": "^4.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "NOiOxPyR8Iu9y+I/6ziTImUC223pg/bLd6z9hRVrPtc=",
"shasum": "KmjRmbTSQE1JUeckfcordstsQ9eFtmYWQlPZ7Cw33oI=",
"location": {
"npm": {
"filePath": "dist/snap.js",
Expand Down
5 changes: 4 additions & 1 deletion packages/examples/examples/browserify/src/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { OnRpcRequestHandler } from '@metamask/snaps-types';
* @throws If the request method is not valid for this snap.
* @throws If the `snap_notify` call failed.
*/
export const onRpcRequest: OnRpcRequestHandler = ({ origin, request }) => {
export const onRpcRequest: OnRpcRequestHandler = async ({
origin,
request,
}) => {
switch (request.method) {
case 'inApp':
return snap.request({
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/browserify/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"resolveJsonModule": true
},
"files": ["../../../types/global.d.ts"],
"files": ["../../../snaps-types/global.d.ts"],
"include": ["src", "gulpfile.ts", "babel.config.json"]
}
18 changes: 10 additions & 8 deletions packages/examples/examples/ethers-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@
"@metamask/eslint-config-nodejs": "^9.0.0",
"@metamask/eslint-config-typescript": "^9.0.1",
"@metamask/snaps-cli": "^0.24.1",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-jsdoc": "^36.1.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/examples/examples/insights/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['../../.eslintrc.js'],

parserOptions: {
tsconfigRootDir: __dirname,
},
};
18 changes: 10 additions & 8 deletions packages/examples/examples/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@
"@metamask/eslint-config-typescript": "^9.0.1",
"@metamask/snaps-cli": "^0.24.1",
"@metamask/snaps-types": "^0.24.1",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-jsdoc": "^36.1.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/insights/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps-monorepo.git"
},
"source": {
"shasum": "ZGhrs3HV9UT/d8A77+jBM4JtjojE1RGqCEk1HFg4xIk=",
"shasum": "Dz8/6HTlyiX7rO8w45hGMfnsbuqRvt20iKZoNbTD1jc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
1 change: 1 addition & 0 deletions packages/examples/examples/insights/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OnTransactionHandler } from '@metamask/snaps-types';

import { getInsights } from './insights';

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/examples/examples/insights/src/insights.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { decode } from '@metamask/abi-utils';
import {
add0x,
bytesToHex,
hasProperty,
isObject,
remove0x,
} from '@metamask/utils';
import { decode } from '@metamask/abi-utils';

// The API endpoint to get a list of functions by 4 byte signature.
const API_ENDPOINT =
'https://www.4byte.directory/api/v1/signatures/?hex_signature=';

/* eslint-disable camelcase */
// These fields come from an API.
/* eslint-disable @typescript-eslint/naming-convention */
type FourByteSignature = {
id: number;
created_at: string;
text_signature: string;
hex_signature: string;
bytes_signature: string;
};
/* eslint-enable camelcase */
/* eslint-enable @typescript-eslint/naming-convention */

/**
* Gets the function name(s) for the given 4 byte signature.
Expand All @@ -35,6 +36,7 @@ export const getFunctionsBySignature = async (
const response = await fetch(`${API_ENDPOINT}${signature}`, {
method: 'get',
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'Content-Type': 'application/json',
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/examples/insights/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"typeRoots": ["../../../../node_modules/@types"]
},
"files": ["../../../types/global.d.ts"],
"files": ["../../../snaps-types/global.d.ts"],
"include": ["src"]
}
18 changes: 10 additions & 8 deletions packages/examples/examples/ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@
"@metamask/eslint-config-nodejs": "^9.0.0",
"@metamask/eslint-config-typescript": "^9.0.1",
"@metamask/snaps-cli": "^0.24.1",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-jsdoc": "^36.1.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"prettier": "^2.3.2",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.11",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "~4.8.4"
},
"engines": {
"node": ">=16.0.0"
Expand Down
Loading

0 comments on commit 1df275d

Please sign in to comment.