forked from palantir/tslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fedbb59
commit 74d827c
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
• Enforce minimum tab width | ||
• Enforce filtering within for...in (forin) | ||
• Disallow variables referenced outside of their scope definition (funcscope) | ||
• Disallow usage of [''] notation when the dot notation can be used (sub) | ||
• Disallow unused variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/// <reference path='rule.ts'/> | ||
/// <reference path='baseRule.ts'/> | ||
|
||
module Lint.Rules { | ||
|
||
export class SubRule extends BaseRule { | ||
constructor() { | ||
super("sub"); | ||
} | ||
|
||
public isEnabled() : boolean { | ||
return this.getValue() === true; | ||
} | ||
|
||
public apply(syntaxTree: TypeScript.SyntaxTree): RuleFailure[] { | ||
var sourceUnit = syntaxTree.sourceUnit(); | ||
var comparisonWalker = new SubWalker(syntaxTree.fileName()); | ||
|
||
sourceUnit.accept(comparisonWalker); | ||
|
||
return comparisonWalker.getFailures(); | ||
} | ||
} | ||
|
||
class SubWalker extends Lint.RuleWalker { | ||
static SUB_FAILURE = "dictionary access via string literals is disallowed"; | ||
|
||
public visitElementAccessExpression(node: TypeScript.ElementAccessExpressionSyntax): void { | ||
super.visitElementAccessExpression(node); | ||
this.handleElementAccessExpression(node); | ||
} | ||
|
||
private handleElementAccessExpression(operatorToken: TypeScript.ElementAccessExpressionSyntax) { | ||
var failure = null; | ||
var argumentExpressionKind = operatorToken.argumentExpression.kind() | ||
|
||
if (argumentExpressionKind === TypeScript.SyntaxKind.StringLiteral) { | ||
failure = new Lint.RuleFailure(this.getFileName(), this.position(), SubWalker.SUB_FAILURE); | ||
} | ||
|
||
if(failure) { | ||
this.addFailure(failure); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters