aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts4
-rw-r--r--packages/0x.js/src/utils/order_state_utils.ts2
-rw-r--r--packages/0x.js/test/exchange_transfer_simulator_test.ts4
-rw-r--r--packages/0x.js/test/utils/token_utils.ts2
-rw-r--r--packages/contracts/deploy/src/utils/contract.ts32
-rw-r--r--packages/tslint-config/CHANGELOG.md1
-rw-r--r--packages/tslint-config/rules/underscorePrivatesRule.ts17
7 files changed, 28 insertions, 34 deletions
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index b093ba52c..9d5c96b0e 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -127,7 +127,7 @@ export class OrderStateWatcher {
}
delete this._orderByOrderHash[orderHash];
delete this._orderStateByOrderHashCache[orderHash];
- const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
this._removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
this._removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
@@ -351,7 +351,7 @@ export class OrderStateWatcher {
}
}
private _getZRXTokenAddress(): string {
- const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
return zrxTokenAddress;
}
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index 9849b073a..981f9e96c 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -81,7 +81,7 @@ export class OrderStateUtils {
// If we pass it from the instantiator - there is no opportunity to get it there
// because JS doesn't support async constructors.
// Moreover - it's cached under the hood so it's equivalent to an async constructor.
- const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
+ const exchange = (this._orderFilledCancelledLazyStore as any)._exchange as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
const makerBalance = await this._balanceAndProxyAllowanceLazyStore.getBalanceAsync(
diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts
index dbd1e99bd..c7e3cde06 100644
--- a/packages/0x.js/test/exchange_transfer_simulator_test.ts
+++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts
@@ -65,7 +65,7 @@ describe('ExchangeTransferSimulator', () => {
await exchangeTransferSimulator.transferFromAsync(
exampleTokenAddress, sender, recipient, transferAmount, TradeSide.Taker, TransferType.Trade,
);
- const store = (exchangeTransferSimulator as any).store;
+ const store = (exchangeTransferSimulator as any)._store;
const senderBalance = await store.getBalanceAsync(exampleTokenAddress, sender);
const recipientBalance = await store.getBalanceAsync(exampleTokenAddress, recipient);
const senderProxyAllowance = await store.getProxyAllowanceAsync(exampleTokenAddress, sender);
@@ -81,7 +81,7 @@ describe('ExchangeTransferSimulator', () => {
await exchangeTransferSimulator.transferFromAsync(
exampleTokenAddress, sender, recipient, transferAmount, TradeSide.Taker, TransferType.Trade,
);
- const store = (exchangeTransferSimulator as any).store;
+ const store = (exchangeTransferSimulator as any)._store;
const senderBalance = await store.getBalanceAsync(exampleTokenAddress, sender);
const recipientBalance = await store.getBalanceAsync(exampleTokenAddress, recipient);
const senderProxyAllowance = await store.getProxyAllowanceAsync(exampleTokenAddress, sender);
diff --git a/packages/0x.js/test/utils/token_utils.ts b/packages/0x.js/test/utils/token_utils.ts
index e9a10d036..48b5e1798 100644
--- a/packages/0x.js/test/utils/token_utils.ts
+++ b/packages/0x.js/test/utils/token_utils.ts
@@ -18,7 +18,7 @@ export class TokenUtils {
return zrxToken;
}
public getWethTokenOrThrow(): Token {
- const wethToken = _.find(this.tokens, {symbol: WETH_TOKEN_SYMBOL});
+ const wethToken = _.find(this._tokens, {symbol: WETH_TOKEN_SYMBOL});
if (_.isUndefined(wethToken)) {
throw new Error(InternalZeroExError.WethNotInTokenRegistry);
}
diff --git a/packages/contracts/deploy/src/utils/contract.ts b/packages/contracts/deploy/src/utils/contract.ts
index c386e7d1a..ffad9ed70 100644
--- a/packages/contracts/deploy/src/utils/contract.ts
+++ b/packages/contracts/deploy/src/utils/contract.ts
@@ -15,28 +15,28 @@ export class Contract implements Web3.ContractInstance {
// and we don't know their types in advance
[name: string]: any;
constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<Web3.TxData>) {
- this.contract = web3ContractInstance;
+ this._contract = web3ContractInstance;
this.address = web3ContractInstance.address;
this.abi = web3ContractInstance.abi;
- this.defaults = defaults;
- this.populateEvents();
- this.populateFunctions();
- this.validator = new SchemaValidator();
+ this._defaults = defaults;
+ this._populateEvents();
+ this._populateFunctions();
+ this._validator = new SchemaValidator();
}
private _populateFunctions(): void {
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function);
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
if (functionAbi.constant) {
- const cbStyleCallFunction = this.contract[functionAbi.name].call;
+ const cbStyleCallFunction = this._contract[functionAbi.name].call;
this[functionAbi.name] = {
- callAsync: promisify(cbStyleCallFunction, this.contract),
+ callAsync: promisify(cbStyleCallFunction, this._contract),
};
} else {
- const cbStyleFunction = this.contract[functionAbi.name];
- const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
+ const cbStyleFunction = this._contract[functionAbi.name];
+ const cbStyleEstimateGasFunction = this._contract[functionAbi.name].estimateGas;
this[functionAbi.name] = {
- estimateGasAsync: promisify(cbStyleEstimateGasFunction, this.contract),
- sendTransactionAsync: this.promisifyWithDefaultParams(cbStyleFunction),
+ estimateGasAsync: promisify(cbStyleEstimateGasFunction, this._contract),
+ sendTransactionAsync: this._promisifyWithDefaultParams(cbStyleFunction),
};
}
});
@@ -44,7 +44,7 @@ export class Contract implements Web3.ContractInstance {
private _populateEvents(): void {
const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event);
_.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => {
- this[eventAbi.name] = this.contract[eventAbi.name];
+ this[eventAbi.name] = this._contract[eventAbi.name];
});
}
private _promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise<any> {
@@ -52,11 +52,11 @@ export class Contract implements Web3.ContractInstance {
const promise = new Promise((resolve, reject) => {
const lastArg = args[args.length - 1];
let txData: Partial<Web3.TxData> = {};
- if (this.isTxData(lastArg)) {
+ if (this._isTxData(lastArg)) {
txData = args.pop();
}
txData = {
- ...this.defaults,
+ ...this._defaults,
...txData,
};
const callback = (err: Error, data: any) => {
@@ -68,14 +68,14 @@ export class Contract implements Web3.ContractInstance {
};
args.push(txData);
args.push(callback);
- fn.apply(this.contract, args);
+ fn.apply(this._contract, args);
});
return promise;
};
return promisifiedWithDefaultParams;
}
private _isTxData(lastArg: any): boolean {
- const isValid = this.validator.isValid(lastArg, schemas.txDataSchema);
+ const isValid = this._validator.isValid(lastArg, schemas.txDataSchema);
return isValid;
}
}
diff --git a/packages/tslint-config/CHANGELOG.md b/packages/tslint-config/CHANGELOG.md
index 5364ae0ee..31f49eef6 100644
--- a/packages/tslint-config/CHANGELOG.md
+++ b/packages/tslint-config/CHANGELOG.md
@@ -3,6 +3,7 @@
v0.x.x - TBD
------------------------
* Added custom 'underscore-privates' rule, requiring underscores to be prepended to private variable names
+ * Because our tools can be used in both a TS and JS environment, we want to make the private methods of any public facing interface show up at the bottom of auto-complete lists. Additionally, we wanted to remain consistent with respect to our usage of underscores in order to enforce this rule with a linter rule, rather then manual code reviews.
v0.3.0 - _December 20, 2017_
------------------------
diff --git a/packages/tslint-config/rules/underscorePrivatesRule.ts b/packages/tslint-config/rules/underscorePrivatesRule.ts
index d00f9696c..472ea09ff 100644
--- a/packages/tslint-config/rules/underscorePrivatesRule.ts
+++ b/packages/tslint-config/rules/underscorePrivatesRule.ts
@@ -1,7 +1,7 @@
import * as Lint from 'tslint';
import * as ts from 'typescript';
-const UNDERSCORE = '_'.charCodeAt(0);
+const UNDERSCORE = '_';
type RelevantClassMember =
| ts.MethodDeclaration
@@ -9,15 +9,15 @@ type RelevantClassMember =
| ts.GetAccessorDeclaration
| ts.SetAccessorDeclaration;
-// Based on: https://github.com/DanielRosenwasser/underscore-privates-tslint-rule
+// Copied from: https://github.com/DanielRosenwasser/underscore-privates-tslint-rule
+// The version on github is not published on npm
export class Rule extends Lint.Rules.AbstractRule {
- public static FAILURE_STRING = 'private members name must be prefixed with an underscore';
+ public static FAILURE_STRING = 'private members must be prefixed with an underscore';
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithFunction(sourceFile, walk);
}
}
-
function walk(ctx: Lint.WalkContext<void>): void {
traverse(ctx.sourceFile);
@@ -26,23 +26,19 @@ function walk(ctx: Lint.WalkContext<void>): void {
return ts.forEachChild(node, traverse);
}
}
-
function checkNodeForViolations(ctx: Lint.WalkContext<void>, node: ts.Node): void {
if (!isRelevantClassMember(node)) {
return;
}
-
// The declaration might have a computed property name or a numeric name.
const name = node.name;
if (!nameIsIdentifier(name)) {
return;
}
-
if (!nameStartsWithUnderscore(name.text) && memberIsPrivate(node)) {
ctx.addFailureAtNode(name, Rule.FAILURE_STRING);
}
}
-
function isRelevantClassMember(node: ts.Node): node is RelevantClassMember {
switch (node.kind) {
case ts.SyntaxKind.MethodDeclaration:
@@ -54,15 +50,12 @@ function isRelevantClassMember(node: ts.Node): node is RelevantClassMember {
return false;
}
}
-
function nameStartsWithUnderscore(text: string) {
- return text.charCodeAt(0) === UNDERSCORE;
+ return text.charCodeAt(0) === UNDERSCORE.charCodeAt(0);
}
-
function memberIsPrivate(node: ts.Declaration) {
return Lint.hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword);
}
-
function nameIsIdentifier(node: ts.Node): node is ts.Identifier {
return node.kind === ts.SyntaxKind.Identifier;
}