lint: no implicit casting.

This commit is contained in:
Christopher Jeffrey 2017-07-31 12:05:34 -07:00
parent 6ba8eb9951
commit 88ef28d837
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
26 changed files with 62 additions and 54 deletions

View File

@ -52,7 +52,7 @@
"no-extra-semi": "off",
"no-fallthrough": "off",
"no-func-assign": "off",
"no-implicit-coercion": "off",
"no-implicit-coercion": "error",
"no-multi-assign": "error",
"no-multiple-empty-lines": ["error", {
"max": 1

View File

@ -173,7 +173,7 @@ CLI.prototype.getBlock = async function getBlock() {
let hash = this.config.str(0);
if (hash.length !== 64)
hash = +hash;
hash = parseInt(hash, 10);
const block = await this.client.getBlock(hash);
@ -386,7 +386,7 @@ CLI.prototype.reset = async function reset() {
let hash = this.config.str(0);
if (hash.length !== 64)
hash = +hash;
hash = parseInt(hash, 10);
await this.client.reset(hash);

View File

@ -49,7 +49,7 @@ const layout = {
vv: function vv(key) {
assert(typeof key === 'string');
assert(key.length === 36);
return [+key.slice(1, 4), key.slice(4, 36)];
return [parseInt(key.slice(1, 4), 10), key.slice(4, 36)];
},
T: function T(addr, hash) {
addr = hex(addr);
@ -80,10 +80,10 @@ const layout = {
let hash, index;
if (key.length === 139) {
hash = key.slice(65, 129);
index = +key.slice(129);
index = parseInt(key.slice(129), 10);
} else if (key.length === 115) {
hash = key.slice(41, 105);
index = +key.slice(105);
index = parseInt(key.slice(105), 10);
} else {
assert(false);
}

View File

@ -365,7 +365,7 @@ Amount.serialize = function serialize(value, exp, num) {
result = '-' + result;
if (num)
return +result;
return Number(result);
return result;
};
@ -385,7 +385,7 @@ Amount.serializeUnsafe = function serializeUnsafe(value, exp, num) {
value = value.toFixed(exp);
if (num)
return +value;
return Number(value);
if (exp !== 0) {
value = value.replace(/0+$/, '');

View File

@ -8,7 +8,7 @@
let native;
if (+process.env.BCOIN_NO_SECP256K1 !== 1) {
if (Number(process.env.BCOIN_NO_SECP256K1) !== 1) {
try {
native = require('secp256k1/bindings');
} catch (e) {

View File

@ -1495,7 +1495,7 @@ Response.prototype.send = function send(code, msg, type) {
if (typeof msg === 'string') {
const len = Buffer.byteLength(msg, 'utf8');
this.setHeader('Content-Length', len + '');
this.setHeader('Content-Length', len.toString(10));
try {
this.write(msg, 'utf8');
this.end();
@ -1506,7 +1506,7 @@ Response.prototype.send = function send(code, msg, type) {
}
if (Buffer.isBuffer(msg)) {
this.setHeader('Content-Length', msg.length + '');
this.setHeader('Content-Length', msg.length.toString(10));
try {
this.write(msg);
this.end();

View File

@ -234,7 +234,7 @@ RequestOptions.prototype.getHeaders = function getHeaders() {
headers['Content-Type'] = getType(this.type);
if (this.body)
headers['Content-Length'] = this.body.length + '';
headers['Content-Length'] = this.body.length.toString(10);
if (this.auth) {
const auth = `${this.auth.username}:${this.auth.password}`;

View File

@ -2184,7 +2184,7 @@ RPC.prototype.handleLongpoll = async function handleLongpoll(lpid) {
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid longpoll ID.');
const watched = lpid.slice(0, 64);
const lastTX = +lpid.slice(64, 74);
const lastTX = parseInt(lpid.slice(64, 74), 10);
if (!util.isHex(watched) || !util.isUInt32(lastTX))
throw new RPCError(errs.INVALID_PARAMETER, 'Invalid longpoll ID.');
@ -2450,7 +2450,7 @@ RPC.prototype.getHashRate = async function getHashRate(lookup, height) {
const workDiff = tip.chainwork.sub(entry.chainwork);
const timeDiff = maxTime - minTime;
const ps = +workDiff.toString(10) / timeDiff;
const ps = parseInt(workDiff.toString(10), 10) / timeDiff;
return ps;
};

View File

@ -86,7 +86,7 @@ function RPCError(msg, code) {
Error.call(this);
this.type = 'RPCError';
this.message = msg + '';
this.message = String(msg);
this.code = code >>> 0;
if (Error.captureStackTrace)

View File

@ -262,7 +262,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
if (hash.length === 64)
hash = util.revHex(hash);
else
hash = +hash;
hash = parseInt(hash, 10);
const block = await this.chain.db.getBlock(hash);

View File

@ -8,7 +8,7 @@
exports.binding = null;
if (+process.env.BCOIN_NO_NATIVE !== 1) {
if (Number(process.env.BCOIN_NO_NATIVE) !== 1) {
try {
exports.binding = require('bcoin-native');
} catch (e) {

View File

@ -1536,7 +1536,7 @@ RejectPacket.prototype.getCode = function getCode() {
const code = RejectPacket.codesByVal[this.code];
if (!code)
return this.code + '';
return this.code.toString(10);
return code.toLowerCase();
};

View File

@ -374,7 +374,7 @@ UPNPService.prototype.soapRequest = async function soapRequest(action, args) {
expect: 'xml',
headers: {
'Content-Type': 'text/xml; charset="utf-8"',
'Content-Length': Buffer.byteLength(req, 'utf8') + '',
'Content-Length': Buffer.byteLength(req, 'utf8').toString(10),
'Connection': 'close',
'SOAPAction': JSON.stringify(`${type}#${action}`)
},
@ -683,7 +683,7 @@ function findError(el) {
const ccode = child.find('errorCode');
if (ccode && /^\d+$/.test(ccode.text))
code = +ccode.text;
code = parseInt(ccode.text, 10);
let desc = 'Unknown';
const cdesc = child.find('errorDescription');

View File

@ -45,7 +45,7 @@ function Logger(options) {
* @const {Boolean}
*/
Logger.HAS_TTY = !!(process.stdout && process.stdout.isTTY);
Logger.HAS_TTY = Boolean(process.stdout && process.stdout.isTTY);
/**
* Maximum file size.
@ -625,7 +625,7 @@ Logger.prototype.logError = function logError(level, module, err) {
console.error(err);
}
let msg = (err.message + '').replace(/^ *Error: */, '');
let msg = String(err.message).replace(/^ *Error: */, '');
if (level !== Logger.levels.ERROR)
msg = `Error: ${msg}`;

View File

@ -72,7 +72,7 @@ AbstractBlock.prototype.parseOptions = function parseOptions(options) {
this.nonce = options.nonce;
if (options.mutable != null)
this.mutable = !!options.mutable;
this.mutable = Boolean(options.mutable);
return this;
};

View File

@ -163,7 +163,7 @@ Coin.prototype.toKey = function toKey() {
Coin.prototype.fromKey = function fromKey(key) {
assert(key.length > 64);
this.hash = key.slice(0, 64);
this.index = +key.slice(64);
this.index = parseInt(key.slice(64), 10);
return this;
};

View File

@ -110,7 +110,7 @@ Outpoint.prototype.toKey = function toKey() {
Outpoint.prototype.fromKey = function fromKey(key) {
assert(key.length > 64);
this.hash = key.slice(0, 64);
this.index = +key.slice(64);
this.index = parseInt(key.slice(64), 10);
return this;
};

View File

@ -100,7 +100,7 @@ Network.prototype._init = function _init() {
for (const key of Object.keys(this.checkpointMap)) {
const hash = this.checkpointMap[key];
const height = +key;
const height = Number(key);
this.checkpoints.push({ hash: hash, height: height });
}

View File

@ -115,7 +115,7 @@ LRU.prototype.set = function set(key, value) {
if (this.capacity === 0)
return;
key = key + '';
key = String(key);
let item = this.map.get(key);
@ -151,7 +151,7 @@ LRU.prototype.get = function get(key) {
if (this.capacity === 0)
return null;
key = key + '';
key = String(key);
const item = this.map.get(key);
@ -173,7 +173,7 @@ LRU.prototype.get = function get(key) {
LRU.prototype.has = function has(key) {
if (this.capacity === 0)
return false;
return this.map.has(key + '');
return this.map.has(String(key));
};
/**
@ -186,7 +186,7 @@ LRU.prototype.remove = function remove(key) {
if (this.capacity === 0)
return false;
key = key + '';
key = String(key);
const item = this.map.get(key);

View File

@ -315,7 +315,7 @@ util.fmt = nodeUtil.format;
util.format = function format(args, color) {
if (args.length > 0 && args[0] && typeof args[0] === 'object') {
if (color == null)
color = !!(process.stdout && process.stdout.isTTY);
color = Boolean(process.stdout && process.stdout.isTTY);
return util.inspectify(args[0], color);
}
return util.fmt(...args);
@ -540,7 +540,7 @@ util.pad8 = function pad8(num) {
assert(typeof num === 'number');
assert(num >= 0);
num = num + '';
num = num.toString(10);
switch (num.length) {
case 1:
@ -565,7 +565,7 @@ util.pad32 = function pad32(num) {
assert(typeof num === 'number');
assert(num >= 0);
num = num + '';
num = num.toString(10);
switch (num.length) {
case 1:

View File

@ -187,7 +187,7 @@ Account.prototype.fromOptions = function fromOptions(options) {
this.type = Account.types.MULTISIG;
if (!this.name)
this.name = this.accountIndex + '';
this.name = this.accountIndex.toString(10);
if (this.m < 1 || this.m > this.n)
throw new Error('m ranges between 1 and n');

View File

@ -42,7 +42,7 @@ layouts.walletdb = {
},
ww: function ww(key) {
assert(typeof key === 'string');
return +key.slice(1);
return parseInt(key.slice(1), 10);
},
l: function l(id) {
assert(typeof id === 'string');
@ -61,7 +61,7 @@ layouts.walletdb = {
},
ii: function ii(key) {
assert(typeof key === 'string');
return [+key.slice(1, 11), key.slice(11)];
return [parseInt(key.slice(1, 11), 10), key.slice(11)];
},
n: function n(wid, index) {
return 'n' + pad32(wid) + pad32(index);
@ -75,14 +75,14 @@ layouts.walletdb = {
},
bb: function bb(key) {
assert(typeof key === 'string');
return +key.slice(1);
return parseInt(key.slice(1), 10);
},
o: function o(hash, index) {
assert(typeof hash === 'string');
return 'o' + hash + pad32(index);
},
oo: function oo(key) {
return [key.slice(1, 65), +key.slice(65)];
return [key.slice(1, 65), parseInt(key.slice(65), 10)];
}
};
@ -94,7 +94,7 @@ layouts.txdb = {
},
pre: function pre(key) {
assert(typeof key === 'string');
return +key.slice(1, 11);
return parseInt(key.slice(1, 11), 10);
},
R: 'R',
hi: function hi(ch, hash, index) {
@ -104,7 +104,7 @@ layouts.txdb = {
hii: function hii(key) {
assert(typeof key === 'string');
key = key.slice(12);
return [key.slice(0, 64), +key.slice(64)];
return [key.slice(0, 64), parseInt(key.slice(64), 10)];
},
ih: function ih(ch, index, hash) {
assert(typeof hash === 'string');
@ -113,7 +113,7 @@ layouts.txdb = {
ihh: function ihh(key) {
assert(typeof key === 'string');
key = key.slice(12);
return [+key.slice(0, 10), key.slice(10)];
return [parseInt(key.slice(0, 10), 10), key.slice(10)];
},
iih: function iih(ch, index, num, hash) {
assert(typeof hash === 'string');
@ -122,7 +122,11 @@ layouts.txdb = {
iihh: function iihh(key) {
assert(typeof key === 'string');
key = key.slice(12);
return [+key.slice(0, 10), +key.slice(10, 20), key.slice(20)];
return [
parseInt(key.slice(0, 10), 10),
parseInt(key.slice(10, 20), 10),
key.slice(20)
];
},
ihi: function ihi(ch, index, hash, num) {
assert(typeof hash === 'string');
@ -131,7 +135,11 @@ layouts.txdb = {
ihii: function ihii(key) {
assert(typeof key === 'string');
key = key.slice(12);
return [+key.slice(0, 10), key.slice(10, 74), +key.slice(74)];
return [
parseInt(key.slice(0, 10), 10),
key.slice(10, 74),
parseInt(key.slice(74), 10)
];
},
ha: function ha(ch, hash) {
assert(typeof hash === 'string');
@ -229,6 +237,6 @@ layouts.txdb = {
bb: function bb(key) {
assert(typeof key === 'string');
key = key.slice(12);
return +key.slice(0);
return parseInt(key.slice(0), 10);
}
};

View File

@ -671,7 +671,7 @@ Wallet.prototype._createAccount = async function _createAccount(options, passphr
let name = options.name;
if (!name)
name = this.accountDepth + '';
name = this.accountDepth.toString(10);
if (await this.hasAccount(name))
throw new Error('Account already exists.');

View File

@ -149,9 +149,9 @@ function listenExit(handler) {
const onError = (err) => {
if (err && err.stack)
console.error(err.stack + '');
console.error(String(err.stack));
else
console.error(err + '');
console.error(String(err));
process.exit(1);
};

View File

@ -176,8 +176,8 @@ ErrorPacket.prototype.cmd = packetTypes.ERROR;
ErrorPacket.prototype.getSize = function getSize() {
let size = 0;
size += encoding.sizeVarString(this.error.message + '', 'utf8');
size += encoding.sizeVarString(this.error.stack + '', 'utf8');
size += encoding.sizeVarString(String(this.error.message), 'utf8');
size += encoding.sizeVarString(String(this.error.stack), 'utf8');
size += encoding.sizeVarString(this.error.type || '', 'utf8');
switch (typeof this.error.code) {
@ -198,8 +198,8 @@ ErrorPacket.prototype.getSize = function getSize() {
};
ErrorPacket.prototype.toWriter = function toWriter(bw) {
bw.writeVarString(this.error.message + '', 'utf8');
bw.writeVarString(this.error.stack + '', 'utf8');
bw.writeVarString(String(this.error.message), 'utf8');
bw.writeVarString(String(this.error.stack), 'utf8');
bw.writeVarString(this.error.type || '', 'utf8');
switch (typeof this.error.code) {
@ -319,7 +319,7 @@ CheckResultPacket.prototype.getSize = function getSize() {
size += 1;
size += encoding.sizeVarString(err.code, 'utf8');
size += encoding.sizeVarString(err.message, 'utf8');
size += encoding.sizeVarString(err.stack + '', 'utf8');
size += encoding.sizeVarString(String(err.stack), 'utf8');
size += 1;
size += 4;
@ -337,7 +337,7 @@ CheckResultPacket.prototype.toWriter = function toWriter(bw) {
bw.writeU8(1);
bw.writeVarString(err.code, 'utf8');
bw.writeVarString(err.message, 'utf8');
bw.writeVarString(err.stack + '', 'utf8');
bw.writeVarString(String(err.stack), 'utf8');
bw.writeU8(err.op === -1 ? 0xff : err.op);
bw.writeU32(err.ip === -1 ? 0xffffffff : err.ip);
};

View File

@ -73,7 +73,7 @@ async function updatePathMap() {
const keys = Object.keys(oldPaths);
for (let i = 0; i < keys.length; i++) {
keys[i] = +keys[i];
keys[i] = Number(keys[i]);
const key = keys[i];
const oldPath = oldPaths[key];
const path = new Path(oldPath);