Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
@metamask/eslint-config*@6.0.0, yarn lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed Apr 8, 2021
1 parent bfdc42d commit 6626fe2
Show file tree
Hide file tree
Showing 41 changed files with 1,000 additions and 611 deletions.
48 changes: 16 additions & 32 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
module.exports = {
extends: [
'@metamask/eslint-config',
'@metamask/eslint-config/config/nodejs',
'@metamask/eslint-config/config/jest',
'@metamask/eslint-config-nodejs',
'@metamask/eslint-config-jest',
],
plugins: [
'json',
],
parserOptions: {
ecmaVersion: 2018,
},

overrides: [
{
files: [
'src/**/*.ts',
'development/*.ts',
],
extends: [
'@metamask/eslint-config/config/typescript',
],
files: ['src/**/*.ts', 'development/*.ts'],
extends: ['@metamask/eslint-config-typescript'],
env: {
node: true,
},
Expand All @@ -29,24 +19,23 @@ module.exports = {
'node/no-process-exit': 'off',
},
},

{
files: [
'src/cmds/eval/evalWorker.ts',
],
files: ['src/cmds/eval/evalWorker.ts'],
globals: {
lockdown: true,
Compartment: true,
BigInt: true,
},
},

{
files: [
'src/main.ts',
],
files: ['src/main.ts'],
rules: {
'node/shebang': 'off',
},
},

{
files: [
// Exports a yargs middleware function, which must be synchronous.
Expand All @@ -57,10 +46,9 @@ module.exports = {
'node/no-sync': 'off',
},
},

{
files: [
'examples/**/*.js',
],
files: ['examples/**/*.js'],
env: {
browser: true,
},
Expand All @@ -72,18 +60,14 @@ module.exports = {
'import/no-unresolved': 'off',
},
},

{
files: [
'test/**/*.js',
],
files: ['test/**/*.js'],
rules: {
'node/no-callback-literal': 'off',
},
},
],
ignorePatterns: [
'!.eslintrc.js',
'dist/',
'node_modules/',
],

ignorePatterns: ['!.eslintrc.js', 'dist/', 'node_modules/'],
};
12 changes: 9 additions & 3 deletions development/buildExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ async function buildExamples() {
cwd: exampleFilePath,
});
} catch (depsInstallError) {
console.log(`Unexpected error when installing dependences in "${exampleFilePath}.`);
console.log(
`Unexpected error when installing dependences in "${exampleFilePath}.`,
);
throw depsInstallError;
}

Expand All @@ -57,11 +59,15 @@ async function buildExamples() {
port: 8000,
});
} catch (bundleError) {
console.log(`Unexpected error while creating bundle in "${exampleFilePath}.`);
console.log(
`Unexpected error while creating bundle in "${exampleFilePath}.`,
);
throw bundleError;
}
} else {
throw new Error(`Invalid example directory "${exampleFile}". Ensure it has valid 'package.json' and 'index.js' files.`);
throw new Error(
`Invalid example directory "${exampleFile}". Ensure it has valid 'package.json' and 'index.js' files.`,
);
}
}
});
Expand Down
15 changes: 11 additions & 4 deletions development/generateInitTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ async function generateInitTemplate() {
const html = fs.readFile(path.join(EXAMPLE_PATH, 'index.html')).toString();
const js = fs.readFile(path.join(EXAMPLE_PATH, 'index.js')).toString();

await fs.writeFile(TEMPLATE_PATH, JSON.stringify({
html,
js,
}, null, 2));
await fs.writeFile(
TEMPLATE_PATH,
JSON.stringify(
{
html,
js,
},
null,
2,
),
);

console.log('success: wrote src/initTemplate.json');
}
10 changes: 3 additions & 7 deletions examples/async-inpage-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ const pingListeners = [];
let pingCount = 0;

wallet.registerApiRequestHandler(async (origin) => {

return {

ping: () => {
trackPings(origin);
return 'pong';
Expand All @@ -24,7 +22,6 @@ wallet.registerApiRequestHandler(async (origin) => {
}
},
};

});

function trackPings(origin) {
Expand All @@ -34,9 +31,8 @@ function trackPings(origin) {
pingCount,
};
pingListeners.forEach((listener) => {
listener(notice)
.catch((err) => {
console.error('Unable to deliver ping notice', err);
});
listener(notice).catch((err) => {
console.error('Unable to deliver ping notice', err);
});
});
}
16 changes: 12 additions & 4 deletions examples/bls-signer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ console.log('Hello from bls-snap!');

wallet.registerRpcMessageHandler(async (_originString, requestObject) => {
switch (requestObject.method) {

case 'getAccount':
return getPubKey();

case 'signMessage': {
const pubKey = await getPubKey();
const data = requestObject.params[0];
const approved = await promptUser(`Do you want to BLS sign ${data} with ${pubKey}?`);
const approved = await promptUser(
`Do you want to BLS sign ${data} with ${pubKey}?`,
);
if (!approved) {
throw rpcErrors.eth.unauthorized();
}
const PRIVATE_KEY = await wallet.getAppKey();
const signature = await bls.sign(requestObject.params[0], PRIVATE_KEY, DOMAIN);
const signature = await bls.sign(
requestObject.params[0],
PRIVATE_KEY,
DOMAIN,
);
return signature;
}

Expand All @@ -34,6 +39,9 @@ async function getPubKey() {
}

async function promptUser(message) {
const response = await wallet.request({ method: 'confirm', params: [message] });
const response = await wallet.request({
method: 'confirm',
params: [message],
});
return response;
}
23 changes: 15 additions & 8 deletions examples/custom-account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ wallet.registerAccountMessageHandler(async (origin, req) => {
case 'wallet_signTypedData_v4': {
const result = await prompt({
html: `<div style="width: 100%;overflow-wrap: break-word;">
The site from <span style="font-weight: 900;color: #037DD6;"><a href="${origin}">${origin}</a></span> requests you sign this with your offline strategy:\n${JSON.stringify(req)}
The site from <span style="font-weight: 900;color: #037DD6;"><a href="${origin}">${origin}</a></span> requests you sign this with your offline strategy:\n${JSON.stringify(
req,
)}
</div>`,
});
return result;
Expand All @@ -50,7 +52,9 @@ wallet.registerAccountMessageHandler(async (origin, req) => {
async function addAccount(params) {
validate(params);
const account = params[0];
const approved = await confirm(`Do you want to add read-only account ${account} to your wallet?`);
const approved = await confirm(
`Do you want to add read-only account ${account} to your wallet?`,
);
if (!approved) {
throw ethErrors.provider.userRejectedRequest({ data: params });
}
Expand All @@ -70,22 +74,25 @@ async function confirm(message) {
}

async function prompt(message) {
const result = await wallet.request({ method: 'customPrompt', params: [message] });
const result = await wallet.request({
method: 'customPrompt',
params: [message],
});
return result;
}

function updateUi() {
console.log('updating UI with accounts', accounts);
accounts.forEach(async (account) => {
console.log('issuing add for ', account);
wallet.request({
method: 'wallet_manageIdentities',
params: ['add', { address: account }],
})
wallet
.request({
method: 'wallet_manageIdentities',
params: ['add', { address: account }],
})
.catch((err) => console.log('Problem updating identity', err))
.then(() => {
console.log('adding identity seems to have succeeded!');
});
});
}

5 changes: 2 additions & 3 deletions examples/custom-token/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ wallet.registerRpcMessageHandler(async (_originString, requestObject) => {
case 'getBalance':
return userBalance;
case 'mint':
userBalance += (requestObject.params[0] || 1);
userBalance += requestObject.params[0] || 1;
updateUi();
return userBalance;
case 'burn':
userBalance -= (requestObject.params[0] || userBalance);
userBalance -= requestObject.params[0] || userBalance;
updateUi();
return userBalance;
default:
Expand All @@ -43,4 +43,3 @@ function updateUi() {

created = true;
}

7 changes: 5 additions & 2 deletions examples/ipfs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { errors: rpcErrors } = require('eth-json-rpc-errors');
const IPFS = require('ipfs-mini');

const ipfs = new IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });
const ipfs = new IPFS({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
});

wallet.registerRpcMessageHandler(async (_originString, requestObject) => {
switch (requestObject.method) {
Expand All @@ -17,4 +21,3 @@ wallet.registerRpcMessageHandler(async (_originString, requestObject) => {
throw rpcErrors.eth.methodNotFound(requestObject);
}
});

6 changes: 4 additions & 2 deletions examples/submitted-tx-hash-tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ wallet.onMetaMaskEvent('tx:status-update', (id, status) => {
const txMeta = wallet.getTxById(id);
wallet.updatePluginState({
...currentPluginState,
successfulTxHashes: [...currentPluginState.successfulTxHashes, txMeta.hash],
successfulTxHashes: [
...currentPluginState.successfulTxHashes,
txMeta.hash,
],
});
}
});
Expand All @@ -23,4 +26,3 @@ wallet.registerRpcMessageHandler(async (_originString, requestObject) => {
throw rpcErrors.eth.methodNotFound(requestObject);
}
});

6 changes: 1 addition & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module.exports = {
testEnvironment: 'node',
verbose: false,
coverageReporters: [
'json',
'text',
'html',
],
coverageReporters: ['json', 'text', 'html'],
};
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"test:nobuild": "jest",
"dev:gen-init-template": "node ./dist/development/generateInitTemplate.js",
"dev:build-examples": "node ./dist/development/buildExamples.js",
"lint": "eslint . --ext js,json,d.ts,ts",
"lint:fix": "yarn lint --fix"
"lint:tsjs": "eslint . --ext js,ts",
"lint:json": "prettier *.json",
"lint": "yarn lint:tsjs && yarn lint:json",
"lint:fix": "yarn lint:tsjs --fix && yarn lint:json --write"
},
"author": "Erik Marks <[email protected]>",
"contributors": [
Expand All @@ -32,7 +34,10 @@
"url": "git+https://github.com/MetaMask/snaps-cli.git"
},
"devDependencies": {
"@metamask/eslint-config": "^5.0.0",
"@metamask/eslint-config": "^6.0.0",
"@metamask/eslint-config-jest": "^6.0.0",
"@metamask/eslint-config-nodejs": "^6.0.0",
"@metamask/eslint-config-typescript": "^6.0.0",
"@types/browserify": "^12.0.36",
"@types/init-package-json": "^1.10.0",
"@types/is-url": "^1.2.28",
Expand All @@ -42,15 +47,17 @@
"@types/serve-handler": "^6.1.0",
"@types/strip-comments": "^2.0.0",
"@types/yargs": "^15.0.12",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"eslint": "^7.18.0",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-json": "^2.1.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"execa": "^5.0.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
Expand Down
Loading

0 comments on commit 6626fe2

Please sign in to comment.