Skip to content

Commit 115abb5

Browse files
committed
added new rules for and updated eslint
Summary: ticket BG-3493 Reviewers: tyler, taylor, bigly, arik Reviewed By: arik Subscribers: ben Differential Revision: https://phabricator.bitgo.com/D7875
1 parent 8d410f1 commit 115abb5

33 files changed

+415
-411
lines changed

.eslintrc.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"ecmaVersion": 6
1616
},
1717
"rules": {
18-
"indent": ["error", 2, {"SwitchCase": 1, "MemberExpression": "off"}],
18+
"indent": ["error", 2, {"SwitchCase": 1, "MemberExpression": 0}],
1919
"linebreak-style": ["error", "unix"],
2020
"semi": ["error", "always"],
2121
"eqeqeq": ["warn", "always"],
22-
"curly": "error",
22+
"curly": ["error", "multi-line"],
2323
"no-extra-boolean-cast": "off",
2424
"no-unused-vars": ["error", {"vars": "all", "args": "none"}],
2525
"object-curly-spacing": ["error", "always", {"objectsInObjects": true, "arraysInObjects": true}],
@@ -62,6 +62,12 @@
6262
"space-before-blocks": ["error"],
6363
"space-infix-ops": ["error"],
6464
"spaced-comment": ["error", "always"],
65-
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }]
65+
"no-fallthrough": "error",
66+
"no-octal": "error",
67+
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1 }],
68+
"space-before-function-paren": ["error", "never"],
69+
"no-mixed-spaces-and-tabs": "error",
70+
"no-dupe-keys": "error",
71+
"no-redeclare": ["error", { "builtinGlobals": true }]
6672
}
6773
}

example/addressLabels.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const collectInputs = function() {
6868
const deferred = Q.defer();
6969
if (inputs.action === 'set') {
7070
return getVariable('address', 'On which address are we setting the label: ')()
71-
.then(getVariable('label', 'What label do you want to set on the address: '));
71+
.then(getVariable('label', 'What label do you want to set on the address: '));
7272
} else if (inputs.action === 'delete') {
7373
return getVariable('address', 'From which address are we removing the label: ')();
7474
} else {
@@ -79,12 +79,12 @@ const collectInputs = function() {
7979
};
8080

8181
return getVariable('walletId', 'Enter the wallet ID: ')()
82-
.then(getVariable('action', 'Which label action do you wish to perform? [list, set, delete]: '))
83-
.then(getCreateOrDeleteVariables());
82+
.then(getVariable('action', 'Which label action do you wish to perform? [list, set, delete]: '))
83+
.then(getCreateOrDeleteVariables());
8484
};
8585

8686
const authenticate = function() {
87-
bitgo.authenticate({ username: inputs.user, password: inputs.password, otp: inputs.otp }, function (err, result) {
87+
bitgo.authenticate({ username: inputs.user, password: inputs.password, otp: inputs.otp }, function(err, result) {
8888
if (err) {
8989
console.dir(err);
9090
throw new Error('Authentication failure!');
@@ -94,7 +94,7 @@ const authenticate = function() {
9494

9595
const runCommands = function() {
9696
// Now get the wallet
97-
bitgo.wallets().get({ type: 'bitcoin', id: inputs.walletId }, function (err, wallet) {
97+
bitgo.wallets().get({ type: 'bitcoin', id: inputs.walletId }, function(err, wallet) {
9898
if (err) {
9999
console.log(err);
100100
process.exit(-1);
@@ -103,22 +103,22 @@ const runCommands = function() {
103103
switch (inputs.action) {
104104
case 'list':
105105
// Get the labels for the addresses in this wallet
106-
wallet.labels({}, function (err, result) {
106+
wallet.labels({}, function(err, result) {
107107
if (err) {
108108
console.log(err);
109109
process.exit(-1);
110110
}
111111
if (result) {
112112
const sortedLabels = _.sortBy(result, function(label) { return label.label + label.address; });
113-
sortedLabels.forEach(function (label) {
113+
sortedLabels.forEach(function(label) {
114114
const line = ' ' + _.string.rpad(label.address, 38) + _.string.prune(label.label, 60);
115115
console.log(line);
116116
});
117117
}
118118
});
119119
break;
120120
case 'set':
121-
wallet.setLabel({ label: inputs.label, address: inputs.address }, function (err, result) {
121+
wallet.setLabel({ label: inputs.label, address: inputs.address }, function(err, result) {
122122
if (err) {
123123
console.log(err);
124124
process.exit(-1);
@@ -127,7 +127,7 @@ const runCommands = function() {
127127
});
128128
break;
129129
case 'delete':
130-
wallet.deleteLabel({ address: inputs.address }, function (err, result) {
130+
wallet.deleteLabel({ address: inputs.address }, function(err, result) {
131131
if (err) {
132132
console.log(err);
133133
process.exit(-1);
@@ -143,8 +143,8 @@ const runCommands = function() {
143143

144144
authenticate();
145145
collectInputs()
146-
.then(runCommands)
147-
.catch(function(e) {
148-
console.log(e);
149-
console.log(e.stack);
150-
});
146+
.then(runCommands)
147+
.catch(function(e) {
148+
console.log(e);
149+
console.log(e.stack);
150+
});

example/approveTransactionSend.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ const pendingApprovalId = process.argv[6];
3131

3232
const bitgo = new BitGoJS.BitGo({ env: 'test' });
3333

34-
const approveTransaction = function () {
34+
const approveTransaction = function() {
3535

3636
return bitgo.authenticate({ username: user, password: password, otp: otp })
37-
.then(function () {
37+
.then(function() {
3838
return bitgo.unlock({ otp: otp });
3939
})
4040
.then(function() {
4141
// Fetch the specified pending approval
4242
return bitgo.pendingApprovals().get({ id: pendingApprovalId });
4343
})
44-
.then(function (pendingApproval) {
44+
.then(function(pendingApproval) {
4545

4646
// we need the wallet password to create the half-signed transaction locally
4747
return pendingApproval.approve({ walletPassphrase: walletPassphrase });
48-
}).then(function (res) {
48+
}).then(function(res) {
4949
console.dir(res);
5050
process.exit(-1);
5151
})
52-
.catch(function (err) {
52+
.catch(function(err) {
5353
console.log(err);
5454
process.exit(-1);
5555
});

example/createWalletAdvanced.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const createWallet = function() {
7272
{ xpub: backupKey.xpub },
7373
{ xpub: keychain.xpub }]
7474
};
75-
bitgo.wallets().add(options, function (err, result) {
75+
bitgo.wallets().add(options, function(err, result) {
7676
if (err) {
7777
console.dir(err);
7878
throw new Error('Could not add wallet on BitGo');

example/estimateTransaction.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ if (!!process.argv[8]) {
3939

4040
const bitgo = new BitGoJS.BitGo({ env: 'test' });
4141

42-
const getTransactionInfo = function () {
42+
const getTransactionInfo = function() {
4343

4444
return bitgo.authenticate({ username: user, password: password, otp: otp })
45-
.then(function () {
45+
.then(function() {
4646
return bitgo.unlock({ otp: otp });
4747
})
48-
.then(function () {
48+
.then(function() {
4949

5050
// Fetch the specified wallet
5151
return bitgo.wallets().get({ id: walletId });
5252
})
53-
.then(function (wallet) {
53+
.then(function(wallet) {
5454

5555
// Set recipients
5656
const recipients = {};
5757
recipients[destinationAddress] = amountSatoshis;
5858

5959
// Create the transaction
6060
return wallet.createTransaction({ recipients: recipients, feeRate: feeRate });
61-
}).then(function (transaction) {
61+
}).then(function(transaction) {
6262
console.log('\nEstimated Transaction Info:\n');
6363
console.log('\tSending from: ' + walletId);
6464
console.log('\tSending to: ' + destinationAddress);
@@ -71,7 +71,7 @@ const getTransactionInfo = function () {
7171
console.log('\tBitGo fee: ' + (transaction.bitgoFee && transaction.bitgoFee.amount || 0) + ' satoshis');
7272
process.exit(-1);
7373
})
74-
.catch(function (err) {
74+
.catch(function(err) {
7575
console.log(err);
7676
process.exit(-1);
7777
});

example/oauthCreateWalletInEnterprise.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const createWallet = function() {
6969
{ xpub: backupKey.xpub },
7070
{ xpub: keychain.xpub }]
7171
};
72-
bitgo.wallets().add(options, function (err, result) {
72+
bitgo.wallets().add(options, function(err, result) {
7373
if (err) {
7474
console.dir(err);
7575
throw new Error('Could not add wallet on BitGo');

example/rejectTransactionSend.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ const pendingApprovalId = process.argv[5];
2727

2828
const bitgo = new BitGoJS.BitGo({ env: 'test' });
2929

30-
const approveTransaction = function () {
30+
const approveTransaction = function() {
3131

3232
return bitgo.authenticate({ username: user, password: password, otp: otp })
33-
.then(function () {
33+
.then(function() {
3434

3535
// Fetch the specified pending approval
3636
return bitgo.pendingApprovals().get({ id: pendingApprovalId });
3737
})
38-
.then(function (pendingApproval) {
38+
.then(function(pendingApproval) {
3939
return pendingApproval.reject();
40-
}).then(function (res) {
40+
}).then(function(res) {
4141
console.dir(res);
4242
process.exit(-1);
4343
})
44-
.catch(function (err) {
44+
.catch(function(err) {
4545
console.log(err);
4646
process.exit(-1);
4747
});

example/sendBitcoinAdvanced.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const sendBitcoin = function() {
9292
unspents: transaction.unspents,
9393
keychain: keychain
9494
},
95-
function (err, transaction) {
95+
function(err, transaction) {
9696
if (err) {
9797
console.log('Failed to sign transaction!');
9898
console.dir(err);
@@ -101,7 +101,7 @@ const sendBitcoin = function() {
101101

102102
console.dir(transaction);
103103
console.log('Sending transaction');
104-
wallet.sendTransaction({ tx: transaction.tx }, function (err, callback) {
104+
wallet.sendTransaction({ tx: transaction.tx }, function(err, callback) {
105105
console.log('Transaction sent: ' + callback.tx);
106106
});
107107
});

example/sendToManyAlt/sendToMany.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const amountSatoshis = config.amountSatoshis;
2323
const setInterval = config.setInterval;
2424
let count = 0;
2525

26-
function setDestinationAddress () {
26+
function setDestinationAddress() {
2727
console.log('\n-------- Queuing Transaction --------\n');
2828
const destinationAddress = addresses[count];
2929
if (destinationAddress === undefined) {

example/transactionOPReturn.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ const sendBitcoin = function() {
7777
unspents: transaction.unspents,
7878
keychain: keychain
7979
},
80-
function (err, transaction) {
80+
function(err, transaction) {
8181
if (err) {
8282
console.log('Failed to sign transaction!');
8383
console.dir(err);
8484
return process.exit(-1);
8585
}
8686
console.dir(transaction);
8787
console.log('Sending transaction');
88-
wallet.sendTransaction({ tx: transaction.tx }, function (err, callback) {
88+
wallet.sendTransaction({ tx: transaction.tx }, function(err, callback) {
8989
if (err) {
9090
console.log('Failed to send transaction to BitGo!');
9191
console.dir(err);

example/transactionOPReturnTokenAuth.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ const sendBitcoin = function() {
7373
unspents: transaction.unspents,
7474
keychain: keychain
7575
},
76-
function (err, transaction) {
76+
function(err, transaction) {
7777
if (err) {
7878
console.log('Failed to sign transaction!');
7979
console.dir(err);
8080
return process.exit(-1);
8181
}
8282
console.dir(transaction);
8383
console.log('Sending transaction');
84-
wallet.sendTransaction({ tx: transaction.tx }, function (err, callback) {
84+
wallet.sendTransaction({ tx: transaction.tx }, function(err, callback) {
8585
if (err) {
8686
console.log('Failed to send transaction to BitGo!');
8787
console.dir(err);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"babel-preset-env": "^1.6.1",
2323
"bufferutil": "~3.0.2",
2424
"coveralls": "~3.0.0",
25-
"eslint": "^4.12.0",
25+
"eslint": "^4.17.0",
2626
"mocha-jenkins-reporter": "~0.3.9",
2727
"glob": "^7.1.2",
2828
"html-webpack-plugin": "^2.30.1",

src/bitcoin.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ HDNode.prototype.getKey = function(network) {
4949
* @param {Number} index child index
5050
* @returns {HDNode} derived HDNode
5151
*/
52-
const deriveFast = function (hdnode, index) {
52+
const deriveFast = function(hdnode, index) {
5353
// no fast path for private key derivations -- delegate to standard method
5454
if (!secp256k1 || hdnode.keyPair.d) {
5555
return hdnode.derive(index);
@@ -104,15 +104,15 @@ const deriveFast = function (hdnode, index) {
104104
};
105105

106106
if (secp256k1) {
107-
bitcoin.ECPair.prototype.sign = function (hash) {
107+
bitcoin.ECPair.prototype.sign = function(hash) {
108108
if (!this.d) {
109109
throw new Error('Missing private key');
110110
}
111111
const sig = secp256k1.sign(hash, this.d.toBuffer(32)).signature;
112112
return bitcoin.ECSignature.fromDER(secp256k1.signatureExport(sig));
113113
};
114114

115-
bitcoin.ECPair.prototype.verify = function (hash, signature) {
115+
bitcoin.ECPair.prototype.verify = function(hash, signature) {
116116
signature = new bitcoin.ECSignature(signature.r, signature.s);
117117
signature = secp256k1.signatureNormalize(secp256k1.signatureImport(signature.toDER()));
118118
return secp256k1.verify(hash, signature, this.getPublicKeyBuffer());
@@ -128,8 +128,8 @@ if (secp256k1) {
128128
*/
129129
bitcoin.hdPath = function(rootKey) {
130130
const cache = {};
131-
const derive = function (path) {
132-
const components = path.split('/').filter(function (c) {
131+
const derive = function(path) {
132+
const components = path.split('/').filter(function(c) {
133133
return c !== '';
134134
});
135135
// strip any extraneous / characters

src/expressApp.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ module.exports = function(args) {
5656

5757
const proxy = httpProxy.createProxyServer(options);
5858

59-
proxy.on('proxyReq', function (proxyReq, req, res, options) {
59+
proxy.on('proxyReq', function(proxyReq, req, res, options) {
6060
// Need to rewrite the host, otherwise cross-site protection kicks in
6161
proxyReq.setHeader('host', url.parse(common.Environments[args.env].uri).hostname);
6262

6363
const userAgent = req.headers['user-agent'] ? BITGOEXPRESS_USER_AGENT + ' ' + req.headers['user-agent'] : BITGOEXPRESS_USER_AGENT;
6464
proxyReq.setHeader('User-Agent', userAgent);
6565
});
6666

67-
app.use(function (req, res) {
67+
app.use(function(req, res) {
6868
req.isProxy = true;
6969
proxy.web(req, res, { target: common.Environments[args.env].uri, changeOrigin: true });
7070
});

src/pendingapproval.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ PendingApproval.prototype.recreateAndSignTransaction = function(params, callback
182182
return;
183183
}
184184
if (transaction.outs.length <= 2) {
185-
transaction.outs.forEach(function (out) {
185+
transaction.outs.forEach(function(out) {
186186
const outAddress = bitcoin.address.fromOutputScript(out.script, network).toBase58Check();
187187
if (self.info().transactionRequest.destinationAddress === outAddress) {
188188
// If this is the destination, then spend to it
@@ -197,7 +197,7 @@ PendingApproval.prototype.recreateAndSignTransaction = function(params, callback
197197
return self.wallet.addresses({ chain: 1, sort: -1, limit: 500 })
198198
.then(function(result) {
199199
const changeAddresses = _.keyBy(result.addresses, 'address');
200-
transaction.outs.forEach(function (out) {
200+
transaction.outs.forEach(function(out) {
201201
const outAddress = bitcoin.address.fromOutputScript(out.script, network).toBase58Check();
202202
if (!changeAddresses[outAddress]) {
203203
// If this is not a change address, then spend to it

src/travelRule.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ TravelRule.prototype.sendMany = function(params, callback) {
233233

234234
const self = this;
235235
const travelInfoMap = _(travelInfos)
236-
.keyBy('outputIndex')
237-
.mapValues(function(travelInfo) {
238-
return self.validateTravelInfo(travelInfo);
239-
})
240-
.value();
236+
.keyBy('outputIndex')
237+
.mapValues(function(travelInfo) {
238+
return self.validateTravelInfo(travelInfo);
239+
})
240+
.value();
241241

242242
return self.getRecipients({ txid: params.txid })
243243
.then(function(recipients) {

0 commit comments

Comments
 (0)