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

Commit

Permalink
Merge branch 'master' of github.com:palantir/tslint into no-unnecessa…
Browse files Browse the repository at this point in the history
…ry-else
  • Loading branch information
debsmita1 committed Feb 16, 2019
2 parents 89c814e + 9785477 commit 0f7d798
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/rules/banRule.ts
Expand Up @@ -94,6 +94,7 @@ export class Rule extends Lint.Rules.AbstractRule {
{ name: ["it", "only"], message: "don't focus tests" },
{ name: ["chai", "assert", "equal"], message: "Use 'strictEqual' instead." },
{ name: ["*", "forEach"], message: "Use a regular for loop instead." },
{ name: ["*", "_id", "toString"], message: "Use 'toHexString' instead." },
],
],
type: "functionality",
Expand Down Expand Up @@ -167,14 +168,14 @@ class BanFunctionWalker extends Lint.AbstractWalker<Options> {
}

private checkForObjectMethodBan(expression: ts.PropertyAccessExpression) {
for (const ban of this.options.methods) {
outer: for (const ban of this.options.methods) {
if (expression.name.text !== ban.name) {
continue;
}
let current = expression.expression;
for (let i = ban.object.length - 1; i > 0; --i) {
if (!isPropertyAccessExpression(current) || current.name.text !== ban.object[i]) {
continue;
continue outer;
}
current = current.expression;
}
Expand Down
4 changes: 4 additions & 0 deletions test/rules/ban/test.ts.lint
Expand Up @@ -24,6 +24,7 @@ fit("some text", () => {});
someObject.fit()
chai.assert.equal(1, "1");
~~~~~~~~~~~~~~~~~ [err % ('chai.assert.equal', "Use 'strictEqual' instead.")]
chai.equal(1, "1");
assert.equal(1, "1");
foo.assert.equal(1, "1");
someObject.chai.assert.equal(1, "1");
Expand All @@ -33,5 +34,8 @@ arr.forEach(() => {});
~~~~~~~~~~~ [err % ('*.forEach', 'Use a regular for loop instead.')]
someObject.someProperty.forEach(() => {});
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [err % ('*.forEach', 'Use a regular for loop instead.')]
someObject._id.toString();
~~~~~~~~~~~~~~~~~~~~~~~ [err % ('*._id.toString', "Use 'toHexString' instead.")]
someObject.toString();

[err]: Calls to '%s' are not allowed.
3 changes: 2 additions & 1 deletion test/rules/ban/tslint.json
Expand Up @@ -10,7 +10,8 @@
{"name": ["_", "map"]},
["_", "filter", "Use the native JavaScript 'myArray.filter' instead."],
{"name": ["*", "forEach"], "message": "Use a regular for loop instead."},
{"name": ["chai", "assert", "equal"], "message": "Use 'strictEqual' instead."}
{"name": ["chai", "assert", "equal"], "message": "Use 'strictEqual' instead."},
{"name": ["*", "_id", "toString"], "message": "Use 'toHexString' instead."}
]
}
}

0 comments on commit 0f7d798

Please sign in to comment.