https://github.com/Microsoft/TypeScript
Raw File
Tip revision: 496e7ab55937c699ffd449960876a1285a7b5cbf authored by Mohamed Hegazy on 08 February 2017, 02:27:06 UTC
Merge pull request #13945 from Microsoft/upateLKGrelease-2.1
Tip revision: 496e7ab
noInOperatorRule.ts
import * as Lint from "tslint/lib";
import * as ts from "typescript";


export class Rule extends Lint.Rules.AbstractRule {
    public static FAILURE_STRING = "Don't use the 'in' keyword - use 'hasProperty' to check for key presence instead";

    public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
        return this.applyWithWalker(new InWalker(sourceFile, this.getOptions()));
    }
}

class InWalker extends Lint.RuleWalker {
    visitNode(node: ts.Node) {
        super.visitNode(node);
        if (node.kind === ts.SyntaxKind.InKeyword && node.parent && node.parent.kind === ts.SyntaxKind.BinaryExpression) {
            this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
        }
    }
}
back to top