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

New tslint rules #883

Merged
merged 4 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/0x.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"shx": "^0.2.2",
"sinon": "^4.0.0",
"source-map-support": "^0.5.0",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typedoc": "0xProject/typedoc",
"typescript": "2.7.1",
"webpack": "^3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/0x.js/src/0x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class ZeroEx {
* ERC721 proxy smart contract.
*/
public erc721Proxy: ERC721ProxyWrapper;
private _contractWrappers: ContractWrappers;
private readonly _contractWrappers: ContractWrappers;
/**
* Generates a pseudo-random 256-bit salt.
* The salt can be included in a 0x order, ensuring that the order generates a unique orderHash
Expand Down
2 changes: 1 addition & 1 deletion packages/0x.js/test/global_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ before('migrate contracts', async function(): Promise<void> {
// HACK: Since the migrations take longer then our global mocha timeout limit
// we manually increase it for this before hook.
const mochaTestTimeoutMs = 20000;
this.timeout(mochaTestTimeoutMs);
this.timeout(mochaTestTimeoutMs); // tslint:disable-line:no-invalid-this
const txDefaults = {
gas: devConstants.GAS_LIMIT,
from: devConstants.TESTRPC_FIRST_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion packages/abi-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"mocha": "^5.2.0",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typescript": "2.7.1"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"npm-run-all": "^4.1.2",
"nyc": "^11.0.1",
"shx": "^0.2.2",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typescript": "2.7.1"
},
"dependencies": {
Expand Down
32 changes: 16 additions & 16 deletions packages/assert/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ const HEX_REGEX = /^0x[0-9A-F]*$/i;
export const assert = {
isBigNumber(variableName: string, value: BigNumber): void {
const isBigNumber = _.isObject(value) && (value as any).isBigNumber;
this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
assert.assert(isBigNumber, assert.typeAssertionMessage(variableName, 'BigNumber', value));
},
isValidBaseUnitAmount(variableName: string, value: BigNumber): void {
assert.isBigNumber(variableName, value);
const isNegative = value.lessThan(0);
this.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}`);
assert.assert(!isNegative, `${variableName} cannot be a negative number, found value: ${value.toNumber()}`);
const hasDecimals = value.decimalPlaces() !== 0;
this.assert(
assert.assert(
!hasDecimals,
`${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`,
);
},
isString(variableName: string, value: string): void {
this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value));
assert.assert(_.isString(value), assert.typeAssertionMessage(variableName, 'string', value));
},
isFunction(variableName: string, value: any): void {
this.assert(_.isFunction(value), this.typeAssertionMessage(variableName, 'function', value));
assert.assert(_.isFunction(value), assert.typeAssertionMessage(variableName, 'function', value));
},
isHexString(variableName: string, value: string): void {
this.assert(
assert.assert(
_.isString(value) && HEX_REGEX.test(value),
this.typeAssertionMessage(variableName, 'HexString', value),
assert.typeAssertionMessage(variableName, 'HexString', value),
);
},
isETHAddressHex(variableName: string, value: string): void {
this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value));
this.assert(addressUtils.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
assert.assert(_.isString(value), assert.typeAssertionMessage(variableName, 'string', value));
assert.assert(addressUtils.isAddress(value), assert.typeAssertionMessage(variableName, 'ETHAddressHex', value));
},
doesBelongToStringEnum(
variableName: string,
Expand All @@ -51,17 +51,17 @@ export const assert = {
);
},
hasAtMostOneUniqueValue(value: any[], errMsg: string): void {
this.assert(_.uniq(value).length <= 1, errMsg);
assert.assert(_.uniq(value).length <= 1, errMsg);
},
isNumber(variableName: string, value: number): void {
this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
assert.assert(_.isFinite(value), assert.typeAssertionMessage(variableName, 'number', value));
},
isBoolean(variableName: string, value: boolean): void {
this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value));
assert.assert(_.isBoolean(value), assert.typeAssertionMessage(variableName, 'boolean', value));
},
isWeb3Provider(variableName: string, value: any): void {
const isWeb3Provider = _.isFunction(value.send) || _.isFunction(value.sendAsync);
this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Provider', value));
assert.assert(isWeb3Provider, assert.typeAssertionMessage(variableName, 'Provider', value));
},
doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void {
if (_.isUndefined(value)) {
Expand All @@ -76,15 +76,15 @@ export const assert = {
const msg = `Expected ${variableName} to conform to schema ${schema.id}
Encountered: ${JSON.stringify(value, null, '\t')}
Validation errors: ${validationResult.errors.join(', ')}`;
this.assert(!hasValidationErrors, msg);
assert.assert(!hasValidationErrors, msg);
},
isWebUri(variableName: string, value: any): void {
const isValidUrl = !_.isUndefined(validUrl.isWebUri(value));
this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'web uri', value));
assert.assert(isValidUrl, assert.typeAssertionMessage(variableName, 'web uri', value));
},
isUri(variableName: string, value: any): void {
const isValidUri = !_.isUndefined(validUrl.isUri(value));
this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value));
assert.assert(isValidUri, assert.typeAssertionMessage(variableName, 'uri', value));
},
assert(condition: boolean, message: string): void {
if (!condition) {
Expand Down
2 changes: 1 addition & 1 deletion packages/assert/test/assert_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Assertions', () => {
});
describe('#isFunction', () => {
it('should not throw for valid input', () => {
const validInputs = [BigNumber, assert.isString];
const validInputs = [BigNumber, assert.isString.bind(assert)];
validInputs.forEach(input => expect(assert.isFunction.bind(assert, variableName, input)).to.not.throw());
});
it('should throw for invalid input', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/base-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"mocha": "^4.0.1",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typescript": "2.7.1"
},
"dependencies": {
Expand Down
12 changes: 5 additions & 7 deletions packages/base-contract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ export class BaseContract {
// 1. Optional param passed in to public method call
// 2. Global config passed in at library instantiation
// 3. Gas estimate calculation + safety margin
const removeUndefinedProperties = _.pickBy;
const txDataWithDefaults: TxData = {
const removeUndefinedProperties = _.pickBy.bind(_);
const txDataWithDefaults = {
...removeUndefinedProperties(txDefaults),
...removeUndefinedProperties(txData as any),
// HACK: TS can't prove that T is spreadable.
// Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged
} as any;
...removeUndefinedProperties(txData),
};
if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) {
txDataWithDefaults.gas = await estimateGasAsync(txDataWithDefaults as any);
txDataWithDefaults.gas = await estimateGasAsync(txDataWithDefaults);
}
return txDataWithDefaults;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"npm-run-all": "^4.1.2",
"nyc": "^11.0.1",
"shx": "^0.2.2",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typedoc": "~0.8.0",
"typescript": "2.7.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/src/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const OPTS_TO_QUERY_FIELD_MAP = {
* that implement the standard relayer API v0
*/
export class HttpClient implements Client {
private _apiEndpointUrl: string;
private readonly _apiEndpointUrl: string;
/**
* Format parameters to be appended to http requests into query string form
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/connect/src/utils/type_converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export const typeConverters = {
const bids = _.get(orderbook, 'bids', []);
const asks = _.get(orderbook, 'asks', []);
return {
bids: bids.map((order: any) => this.convertOrderStringFieldsToBigNumber(order)),
asks: asks.map((order: any) => this.convertOrderStringFieldsToBigNumber(order)),
bids: bids.map((order: any) => typeConverters.convertOrderStringFieldsToBigNumber(order)),
asks: asks.map((order: any) => typeConverters.convertOrderStringFieldsToBigNumber(order)),
};
},
convertOrderStringFieldsToBigNumber(order: any): any {
return this.convertStringsFieldsToBigNumbers(order, [
return typeConverters.convertStringsFieldsToBigNumbers(order, [
'makerTokenAmount',
'takerTokenAmount',
'makerFee',
Expand Down
6 changes: 3 additions & 3 deletions packages/connect/src/ws_orderbook_channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { orderbookChannelMessageParser } from './utils/orderbook_channel_message
* that implements the standard relayer API v0
*/
export class WebSocketOrderbookChannel implements OrderbookChannel {
private _client: WebSocket.w3cwebsocket;
private _handler: OrderbookChannelHandler;
private _subscriptionOptsList: OrderbookChannelSubscriptionOpts[] = [];
private readonly _client: WebSocket.w3cwebsocket;
private readonly _handler: OrderbookChannelHandler;
private readonly _subscriptionOptsList: OrderbookChannelSubscriptionOpts[] = [];
/**
* Instantiates a new WebSocketOrderbookChannel instance
* @param client A WebSocket client
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/test/ws_orderbook_channel_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('WebSocketOrderbookChannel', () => {
const websocketUrl = 'ws://localhost:8080';
const openClient = new WebSocket.w3cwebsocket(websocketUrl);
Sinon.stub(openClient, 'readyState').get(() => WebSocket.w3cwebsocket.OPEN);
Sinon.stub(openClient, 'send').callsFake(_.noop);
Sinon.stub(openClient, 'send').callsFake(_.noop.bind(_));
const openOrderbookChannel = new WebSocketOrderbookChannel(openClient, emptyOrderbookChannelHandler);
const subscriptionOpts = {
baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
Expand Down
2 changes: 1 addition & 1 deletion packages/contract-wrappers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"shx": "^0.2.2",
"sinon": "^4.0.0",
"source-map-support": "^0.5.0",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typescript": "2.7.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contract-wrappers/test/global_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ before('migrate contracts', async function(): Promise<void> {
// HACK: Since the migrations take longer then our global mocha timeout limit
// we manually increase it for this before hook.
const mochaTestTimeoutMs = 50000;
this.timeout(mochaTestTimeoutMs);
this.timeout(mochaTestTimeoutMs); // tslint:disable-line:no-invalid-this
const txDefaults = {
gas: devConstants.GAS_LIMIT,
from: devConstants.TESTRPC_FIRST_ADDRESS,
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"shx": "^0.2.2",
"solc": "^0.4.24",
"solhint": "^1.2.1",
"tslint": "5.8.0",
"tslint": "5.11.0",
"typescript": "2.7.1",
"yargs": "^10.0.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/utils/asset_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ProxyIdToAssetWrappers {
* the logic that uses it does not need to care what standard a token belongs to.
*/
export class AssetWrapper {
private _proxyIdToAssetWrappers: ProxyIdToAssetWrappers;
private readonly _proxyIdToAssetWrappers: ProxyIdToAssetWrappers;
constructor(assetWrappers: AbstractAssetWrapper[]) {
this._proxyIdToAssetWrappers = {};
_.each(assetWrappers, assetWrapper => {
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/test/utils/erc20_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { ERC20BalancesByOwner } from './types';
import { txDefaults } from './web3_wrapper';

export class ERC20Wrapper {
private _tokenOwnerAddresses: string[];
private _contractOwnerAddress: string;
private _web3Wrapper: Web3Wrapper;
private _provider: Provider;
private _dummyTokenContracts: DummyERC20TokenContract[];
private readonly _tokenOwnerAddresses: string[];
private readonly _contractOwnerAddress: string;
private readonly _web3Wrapper: Web3Wrapper;
private readonly _provider: Provider;
private readonly _dummyTokenContracts: DummyERC20TokenContract[];
private _proxyContract?: ERC20ProxyContract;
private _proxyIdIfExists?: string;
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/test/utils/erc721_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { ERC721TokenIdsByOwner } from './types';
import { txDefaults } from './web3_wrapper';

export class ERC721Wrapper {
private _tokenOwnerAddresses: string[];
private _contractOwnerAddress: string;
private _web3Wrapper: Web3Wrapper;
private _provider: Provider;
private _dummyTokenContracts: DummyERC721TokenContract[];
private readonly _tokenOwnerAddresses: string[];
private readonly _contractOwnerAddress: string;
private readonly _web3Wrapper: Web3Wrapper;
private readonly _provider: Provider;
private readonly _dummyTokenContracts: DummyERC721TokenContract[];
private _proxyContract?: ERC721ProxyContract;
private _proxyIdIfExists?: string;
private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {};
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/test/utils/exchange_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { orderUtils } from './order_utils';
import { OrderInfo, SignedTransaction } from './types';

export class ExchangeWrapper {
private _exchange: ExchangeContract;
private _web3Wrapper: Web3Wrapper;
private _logDecoder: LogDecoder;
private readonly _exchange: ExchangeContract;
private readonly _web3Wrapper: Web3Wrapper;
private readonly _logDecoder: LogDecoder;
constructor(exchangeContract: ExchangeContract, provider: Provider) {
this._exchange = exchangeContract;
this._web3Wrapper = new Web3Wrapper(provider);
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/test/utils/forwarder_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const ZERO_AMOUNT = new BigNumber(0);
const INSUFFICENT_ORDERS_FOR_MAKER_AMOUNT = 'Unable to satisfy makerAssetFillAmount with provided orders';

export class ForwarderWrapper {
private _web3Wrapper: Web3Wrapper;
private _forwarderContract: ForwarderContract;
private _logDecoder: LogDecoder;
private _zrxAddress: string;
private readonly _web3Wrapper: Web3Wrapper;
private readonly _forwarderContract: ForwarderContract;
private readonly _logDecoder: LogDecoder;
private readonly _zrxAddress: string;
private static _createOptimizedSellOrders(signedOrders: SignedOrder[]): MarketSellOrders {
const marketSellOrders = formatters.createMarketSellOrders(signedOrders, ZERO_AMOUNT);
const assetDataId = assetProxyUtils.decodeAssetDataId(signedOrders[0].makerAssetData);
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/test/utils/log_decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { artifacts } from './artifacts';
import { constants } from './constants';

export class LogDecoder {
private _web3Wrapper: Web3Wrapper;
private _contractAddress: string;
private _abiDecoder: AbiDecoder;
private readonly _web3Wrapper: Web3Wrapper;
private readonly _contractAddress: string;
private readonly _abiDecoder: AbiDecoder;
public static wrapLogBigNumbers(log: any): any {
const argNames = _.keys(log.args);
for (const argName of argNames) {
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/test/utils/match_order_tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ chaiSetup.configure();
const expect = chai.expect;

export class MatchOrderTester {
private _exchangeWrapper: ExchangeWrapper;
private _erc20Wrapper: ERC20Wrapper;
private _erc721Wrapper: ERC721Wrapper;
private _feeTokenAddress: string;
private readonly _exchangeWrapper: ExchangeWrapper;
private readonly _erc20Wrapper: ERC20Wrapper;
private readonly _erc721Wrapper: ERC721Wrapper;
private readonly _feeTokenAddress: string;

/// @dev Compares a pair of ERC20 balances and a pair of ERC721 token owners.
/// @param expectedNewERC20BalancesByOwner Expected ERC20 balances.
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/test/utils/multi_sig_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { constants } from './constants';
import { LogDecoder } from './log_decoder';

export class MultiSigWrapper {
private _multiSig: MultiSigWalletContract;
private _web3Wrapper: Web3Wrapper;
private _logDecoder: LogDecoder;
private readonly _multiSig: MultiSigWalletContract;
private readonly _web3Wrapper: Web3Wrapper;
private readonly _logDecoder: LogDecoder;
constructor(multiSigContract: MultiSigWalletContract, provider: Provider) {
this._multiSig = multiSigContract;
this._web3Wrapper = new Web3Wrapper(provider);
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/test/utils/order_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { constants } from './constants';
import { signingUtils } from './signing_utils';

export class OrderFactory {
private _defaultOrderParams: Partial<Order>;
private _privateKey: Buffer;
private readonly _defaultOrderParams: Partial<Order>;
private readonly _privateKey: Buffer;
constructor(privateKey: Buffer, defaultOrderParams: Partial<Order>) {
this._defaultOrderParams = defaultOrderParams;
this._privateKey = privateKey;
Expand Down
14 changes: 7 additions & 7 deletions packages/contracts/test/utils/order_factory_from_scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const FIVE_UNITS_FIVE_DECIMALS = new BigNumber(500_000);
const ONE_NFT_UNIT = new BigNumber(1);

export class OrderFactoryFromScenario {
private _userAddresses: string[];
private _zrxAddress: string;
private _nonZrxERC20EighteenDecimalTokenAddresses: string[];
private _erc20FiveDecimalTokenAddresses: string[];
private _erc721Token: DummyERC721TokenContract;
private _erc721Balances: ERC721TokenIdsByOwner;
private _exchangeAddress: string;
private readonly _userAddresses: string[];
private readonly _zrxAddress: string;
private readonly _nonZrxERC20EighteenDecimalTokenAddresses: string[];
private readonly _erc20FiveDecimalTokenAddresses: string[];
private readonly _erc721Token: DummyERC721TokenContract;
private readonly _erc721Balances: ERC721TokenIdsByOwner;
private readonly _exchangeAddress: string;
constructor(
userAddresses: string[],
zrxAddress: string,
Expand Down
Loading