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

Commit

Permalink
no-console: fix #3207 (#4041)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalomdotnet authored and johnwiseheart committed Jul 16, 2018
1 parent 29fbace commit 1eb6640
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/rules/noConsoleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { isCallExpression, isIdentifier, isPropertyAccessExpression } from "tsutils";
import { isIdentifier, isPropertyAccessExpression } from "tsutils";
import * as ts from "typescript";

import * as Lint from "../index";
Expand Down Expand Up @@ -48,13 +48,12 @@ export class Rule extends Lint.Rules.AbstractRule {

function walk(ctx: Lint.WalkContext<string[]>) {
return ts.forEachChild(ctx.sourceFile, function cb(node): void {
if (isCallExpression(node) &&
isPropertyAccessExpression(node.expression) &&
isIdentifier(node.expression.expression) &&
node.expression.expression.text === "console" &&
(ctx.options.length === 0 || ctx.options.indexOf(node.expression.name.text) !== -1)) {
if (isPropertyAccessExpression(node) &&
isIdentifier(node.expression) &&
node.expression.text === "console" &&
(ctx.options.length === 0 || ctx.options.indexOf(node.name.text) !== -1)) {

ctx.addFailureAtNode(node.expression, Rule.FAILURE_STRING_FACTORY(node.expression.name.text));
ctx.addFailureAtNode(node, Rule.FAILURE_STRING_FACTORY(node.name.text));
}
return ts.forEachChild(node, cb);
});
Expand Down
2 changes: 2 additions & 0 deletions test/rules/no-console/all/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ console.something();
~~~~~~~~~~~~~~~~~ [err % ('something')]
console.timeEnd();
~~~~~~~~~~~~~~~ [err % ('timeEnd')]
[].forEach(console.log);
~~~~~~~~~~~ [err % ('log')]

[err]: Calls to 'console.%s' are not allowed.

0 comments on commit 1eb6640

Please sign in to comment.