Skip to content

Commit b0b135c

Browse files
Linter fixes (web3#3639)
* easy lint fixes - mostly semicolons * fix cyclomatic complexity in web3-eth-accounts Co-authored-by: Gregory Markou <[email protected]>
1 parent 9239f6b commit b0b135c

File tree

6 files changed

+55
-47
lines changed

6 files changed

+55
-47
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"bitwise": true,
44
"camelcase": true,
55
"eqeqeq": true,
6+
"esversion": 8,
67
"freeze": true,
78
"funcscope": false,
89
"maxcomplexity": 15,

packages/web3-core-method/src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
453453
gas: parsedTx.gasLimit.toHexString(),
454454
gasPrice: parsedTx.gasPrice.toHexString(),
455455
value: parsedTx.value.toHexString()
456-
})
456+
});
457457
}
458458

459459
// Get revert reason string with eth_call
@@ -549,19 +549,19 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {
549549
var startWatching = function (existingReceipt) {
550550
const startInterval = () => {
551551
intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, true), 1000);
552-
}
552+
};
553553

554554
if (!this.requestManager.provider.on) {
555-
startInterval()
555+
startInterval();
556556
} else {
557557
_ethereumCall.subscribe('newBlockHeaders', function (err, blockHeader, sub) {
558558
if (err || !blockHeader) {
559559
// fall back to polling
560-
startInterval()
560+
startInterval();
561561
} else {
562562
checkConfirmation(existingReceipt, false, err, blockHeader, sub);
563563
}
564-
})
564+
});
565565
}
566566
}.bind(this);
567567

packages/web3-core-subscriptions/src/subscription.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Subscription.prototype.subscribe = function() {
227227
// Re-subscription only: continue fetching from the last block we received.
228228
// a dropped connection may have resulted in gaps in the logs...
229229
if (this.lastBlock && _.isObject(this.options.params)){
230-
payload.params[1] = this.options.params
230+
payload.params[1] = this.options.params;
231231
payload.params[1].fromBlock = formatters.inputBlockNumberFormatter(this.lastBlock + 1);
232232
}
233233

packages/web3-eth-abi/src/index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ ABICoder.prototype.encodeParameter = function (type, param) {
100100
*/
101101
ABICoder.prototype.encodeParameters = function (types, params) {
102102
var self = this;
103-
types = self.mapTypes(types)
103+
types = self.mapTypes(types);
104104

105105
params = params.map(function (param, index) {
106-
let type = types[index]
106+
let type = types[index];
107107
if (typeof type === 'object' && type.type) {
108108
// We may get a named type of shape {name, type}
109-
type = type.type
109+
type = type.type;
110110
}
111111

112-
param = self.formatParam(type, param)
112+
param = self.formatParam(type, param);
113113

114114
// Format params for tuples
115115
if (typeof type === 'string' && type.includes('tuple')) {
@@ -121,21 +121,21 @@ ABICoder.prototype.encodeParameters = function (types, params) {
121121
ethersAbiCoder._getCoder(ParamType.from(coder.type.replace('[]', ''))),
122122
p
123123
)
124-
)
124+
);
125125
}
126126
coder.coders.forEach((c, i) => {
127127
if (c.name === 'tuple') {
128-
modifyParams(c, param[i])
128+
modifyParams(c, param[i]);
129129
} else {
130-
param[i] = self.formatParam(c.name, param[i])
130+
param[i] = self.formatParam(c.name, param[i]);
131131
}
132-
})
133-
}
134-
modifyParams(coder, param)
132+
});
133+
};
134+
modifyParams(coder, param);
135135
}
136136

137137
return param;
138-
})
138+
});
139139

140140
return ethersAbiCoder.encode(types, params);
141141
};
@@ -155,7 +155,7 @@ ABICoder.prototype.mapTypes = function (types) {
155155
// recognize former type. Solidity docs say `Function` is a bytes24
156156
// encoding the contract address followed by the function selector hash.
157157
if (typeof type === 'object' && type.type === 'function'){
158-
type.type = "bytes24"
158+
type.type = "bytes24";
159159
}
160160
if (self.isSimplifiedStructFormat(type)) {
161161
var structName = Object.keys(type)[0];
@@ -259,7 +259,7 @@ ABICoder.prototype.formatParam = function (type, param) {
259259
}
260260

261261
if (type.match(paramTypeBytesArray) || type.match(paramTypeNumberArray)) {
262-
return param.map(p => this.formatParam(type.replace('[]', ''), p))
262+
return param.map(p => this.formatParam(type.replace('[]', ''), p));
263263
}
264264

265265
// Format correct width for u?int[0-9]*
@@ -288,17 +288,17 @@ ABICoder.prototype.formatParam = function (type, param) {
288288
}
289289
if (param.length < maxSize) {
290290
// pad to correct length
291-
param = utils.rightPad(param, size * 2)
291+
param = utils.rightPad(param, size * 2);
292292
}
293293
}
294294

295295
// format odd-length bytes to even-length
296296
if (param.length % 2 === 1) {
297-
param = '0x0' + param.substring(2)
297+
param = '0x0' + param.substring(2);
298298
}
299299
}
300300

301-
return param
301+
return param;
302302
};
303303

304304
/**

packages/web3-eth-accounts/src/index.js

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,7 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
149149
}
150150

151151
function signed(tx) {
152-
if (tx.common && (tx.chain && tx.hardfork)) {
153-
error = new Error(
154-
'Please provide the ethereumjs-common object or the chain and hardfork property but not all together.'
155-
);
156-
}
157-
158-
if ((tx.chain && !tx.hardfork) || (tx.hardfork && !tx.chain)) {
159-
error = new Error(
160-
'When specifying chain and hardfork, both values must be defined. ' +
161-
'Received "chain": ' + tx.chain + ', "hardfork": ' + tx.hardfork
162-
);
163-
}
164-
165-
if (!tx.gas && !tx.gasLimit) {
166-
error = new Error('"gas" is missing');
167-
}
168-
169-
if (tx.nonce < 0 ||
170-
tx.gas < 0 ||
171-
tx.gasPrice < 0 ||
172-
tx.chainId < 0) {
173-
error = new Error('Gas, gasPrice, nonce or chainId is lower than 0');
174-
}
152+
const error = _validateTransactionForSigning(tx);
175153

176154
if (error) {
177155
callback(error);
@@ -280,6 +258,35 @@ Accounts.prototype.signTransaction = function signTransaction(tx, privateKey, ca
280258
});
281259
};
282260

261+
function _validateTransactionForSigning(tx) {
262+
if (tx.common && (tx.chain && tx.hardfork)) {
263+
return new Error(
264+
'Please provide the ethereumjs-common object or the chain and hardfork property but not all together.'
265+
);
266+
}
267+
268+
if ((tx.chain && !tx.hardfork) || (tx.hardfork && !tx.chain)) {
269+
return new Error(
270+
'When specifying chain and hardfork, both values must be defined. ' +
271+
'Received "chain": ' + tx.chain + ', "hardfork": ' + tx.hardfork
272+
);
273+
}
274+
275+
if (!tx.gas && !tx.gasLimit) {
276+
return new Error('"gas" is missing');
277+
}
278+
279+
if (tx.nonce < 0 ||
280+
tx.gas < 0 ||
281+
tx.gasPrice < 0 ||
282+
tx.chainId < 0) {
283+
return new Error('Gas, gasPrice, nonce or chainId is lower than 0');
284+
}
285+
286+
return;
287+
}
288+
289+
283290
/* jshint ignore:start */
284291
Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) {
285292
var values = RLP.decode(rawTx);
@@ -294,7 +301,7 @@ Accounts.prototype.recoverTransaction = function recoverTransaction(rawTx) {
294301

295302
Accounts.prototype.hashMessage = function hashMessage(data) {
296303
var messageHex = utils.isHexStrict(data) ? data : utils.utf8ToHex(data);
297-
var messageBytes = utils.hexToBytes(messageHex)
304+
var messageBytes = utils.hexToBytes(messageHex);
298305
var messageBuffer = Buffer.from(messageBytes);
299306
var preamble = '\x19Ethereum Signed Message:\n' + messageBytes.length;
300307
var preambleBuffer = Buffer.from(preamble);
@@ -630,5 +637,4 @@ function storageAvailable(type) {
630637
}
631638
}
632639

633-
634640
module.exports = Accounts;

packages/web3/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var Web3 = function Web3() {
5353
// overwrite package setProvider
5454
var setProvider = this.setProvider;
5555
this.setProvider = function (provider, net) {
56+
/*jshint unused: false */
5657
setProvider.apply(_this, arguments);
5758

5859
_this.eth.setRequestManager(_this._requestManager);

0 commit comments

Comments
 (0)