Skip to content

Commit

Permalink
debug tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinr committed Aug 8, 2013
1 parent 363bde5 commit 0639ff8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
12 changes: 5 additions & 7 deletions bin/tslint-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26771,6 +26771,7 @@ var Lint;
DebugRule.prototype.apply = function (syntaxTree) {
return this.applyWithWalker(new DebugWalker(syntaxTree));
};
DebugRule.FAILURE_STRING = "use of debugger statements is disallowed";
return DebugRule;
})(Rules.AbstractRule);
Rules.DebugRule = DebugRule;
Expand All @@ -26785,15 +26786,12 @@ var Lint;
_super.prototype.visitToken.call(this, token);
};

DebugWalker.prototype.handleToken = function (operatorToken) {
var failure = null;
var operatorKind = operatorToken.kind();

if (operatorKind === TypeScript.SyntaxKind.DebuggerKeyword) {
this.addFailure(this.createFailure(this.position(), operatorToken.width(), DebugWalker.DEBUG_FAILURE));
DebugWalker.prototype.handleToken = function (token) {
if (token.kind() === TypeScript.SyntaxKind.DebuggerKeyword) {
var position = this.position() + token.leadingTriviaWidth();
this.addFailure(this.createFailure(position, token.width(), DebugRule.FAILURE_STRING));
}
};
DebugWalker.DEBUG_FAILURE = "use of debugger statements is disallowed";
return DebugWalker;
})(Lint.RuleWalker);
})(Lint.Rules || (Lint.Rules = {}));
Expand Down
14 changes: 6 additions & 8 deletions src/rules/debugRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
module Lint.Rules {

export class DebugRule extends AbstractRule {
public static FAILURE_STRING = "use of debugger statements is disallowed";

public isEnabled() : boolean {
return this.getValue() === true;
}
Expand All @@ -30,19 +32,15 @@ module Lint.Rules {
}

class DebugWalker extends Lint.RuleWalker {
static DEBUG_FAILURE = "use of debugger statements is disallowed";

public visitToken(token : TypeScript.ISyntaxToken): void {
this.handleToken(token);
super.visitToken(token);
}

private handleToken(operatorToken: TypeScript.ISyntaxToken) {
var failure = null;
var operatorKind = operatorToken.kind();

if (operatorKind === TypeScript.SyntaxKind.DebuggerKeyword) {
this.addFailure(this.createFailure(this.position(), operatorToken.width(), DebugWalker.DEBUG_FAILURE));
private handleToken(token: TypeScript.ISyntaxToken) {
if (token.kind() === TypeScript.SyntaxKind.DebuggerKeyword) {
var position = this.position() + token.leadingTriviaWidth();
this.addFailure(this.createFailure(position, token.width(), DebugRule.FAILURE_STRING));
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/files/rules/debug.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var testVariable = "debugger";

function testFunction(): number {
if (testVariable === "debugger") {
debugger;
}
}
13 changes: 13 additions & 0 deletions test/rules/debugger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference path='../references.ts' />

describe("<debug>", () => {
it("forbids debugger statements", () => {
var fileName = "rules/debug.test.ts"
var failureString = Lint.Rules.DebugRule.FAILURE_STRING;

var actualFailures = Lint.Test.applyRuleOnFile(fileName, "debug");
var expectedFailure = Lint.Test.createFailure(fileName, [5, 9], [5, 17], failureString);

Lint.Test.assertContainsFailure(actualFailures, expectedFailure);
});
});

0 comments on commit 0639ff8

Please sign in to comment.