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

@metamask/eslint-config*@6.0.0, yarn lint:fix #102

Merged
merged 5 commits into from
Apr 26, 2021
Merged
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -42,9 +42,9 @@ jobs:
- persist_to_workspace:
root: .
paths:
- node_modules
- build-artifacts
- examples/*/node_modules
- node_modules
- build-artifacts
- examples/*/node_modules

test-build:
docker:
@@ -59,7 +59,7 @@ jobs:
- persist_to_workspace:
root: .
paths:
- dist
- dist

test-lint:
docker:
55 changes: 20 additions & 35 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,41 @@
module.exports = {
extends: [
'@metamask/eslint-config',
'@metamask/eslint-config/config/nodejs',
'@metamask/eslint-config/config/jest',
],
plugins: [
'json',
],
parserOptions: {
ecmaVersion: 2018,
},
extends: ['@metamask/eslint-config', '@metamask/eslint-config-nodejs'],

overrides: [
{
files: [
'src/**/*.ts',
'development/*.ts',
],
extends: [
'@metamask/eslint-config/config/typescript',
],
files: ['**/*.ts'],
extends: ['@metamask/eslint-config-typescript'],
env: {
node: true,
},
globals: {
snaps: true,
},
},

{
files: ['src/**/*', 'development/**/*'],
rules: {
'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.
@@ -57,10 +46,9 @@ module.exports = {
'node/no-sync': 'off',
},
},

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

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

ignorePatterns: ['!.eslintrc.js', 'dist/', 'node_modules/'],
};
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.DS_Store
temp
examples/*/dist
package-lock.json
dist/
dist
test/fs-sandbox

# Logs
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@

- Fix `undefined` `port` in `package.json` on build
- The `populate` option for `mm-plugin manifest` (and `mm-plugin build`, which calls
`manifest` by default) no longer has the alias `p`
`manifest` by default) no longer has the alias `p`
- `p` is now in every case reserved as an alias for `port`.

## 0.3.8
@@ -50,7 +50,7 @@
- It applies: `bundle.url = 'http://localhost:${port}/${bundlePath}'`
- Basic handling of HTML comment syntax in bundle
- `<!--` and `-->` can be valid JavaScript, but are always forbidden by SES.
They are now destructed into `<! --` and `-- >`. This may break code in some edge cases.
They are now destructed into `<! --` and `-- >`. This may break code in some edge cases.

## 0.3.6

@@ -88,7 +88,7 @@
## 0.2.1

- Specifying `web3Wallet.bundle.local` or `dist` in `.mm-plugin.json` no longer
overwrites the default for the `serve` command's `root` directory argument
overwrites the default for the `serve` command's `root` directory argument

## 0.2.0

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -51,9 +51,9 @@ In addition, we use the following, required custom fields:
- `url` (`string`; absolute URL to bundle)
- Set to e.g. `localhost:8081/dist/bundle.js` for local development.
- `initialPermissions` (`{ string: object }`; permissions to be requested on
Snap installation)
Snap installation)
- See [this interface](https://github.com/MetaMask/rpc-cap#requestpermissions-irequestedpermissions)
and examples in this repo for details.
and examples in this repo for details.

If you exclude any required fields from `package.json`, your Snap may not
work properly or install at all.
@@ -144,7 +144,7 @@ Examples:

- Commands
- `watch --src ... --dist ...` rebuilds on all changes in the parent directory
of `src` and its children except:
of `src` and its children except:
- `node_modules/`
- `test/` and `tests/`
- The specified `dist` directory
12 changes: 9 additions & 3 deletions development/buildExamples.ts
Original file line number Diff line number Diff line change
@@ -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;
}

@@ -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.`,
);
}
}
});
15 changes: 11 additions & 4 deletions development/generateInitTemplate.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -4,9 +4,7 @@ const pingListeners = [];
let pingCount = 0;

wallet.registerApiRequestHandler(async (origin) => {

return {

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

});

function trackPings(origin) {
@@ -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);
});
});
}
2 changes: 1 addition & 1 deletion examples/async-inpage-api/snap.config.json
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@
"dist": "dist",
"outfileName": "bundle.js",
"src": "index.js"
}
}
16 changes: 12 additions & 4 deletions examples/bls-signer/index.js
Original file line number Diff line number Diff line change
@@ -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;
}

@@ -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
@@ -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;
@@ -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 });
}
@@ -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
@@ -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:
@@ -43,4 +43,3 @@ function updateUi() {

created = true;
}

2 changes: 1 addition & 1 deletion examples/ethers-js/snap.config.json
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@
"dist": "dist",
"outfileName": "bundle.js",
"src": "index.js"
}
}
Loading