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

no-console: fix #3207 #4041

Merged
merged 1 commit into from
Jul 16, 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
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.