https://github.com/Microsoft/TypeScript
Raw File
Tip revision: c759b633d6e33754fb0cd4473759062ce920c4a2 authored by Ron Buckton on 20 February 2016, 01:01:02 UTC
Adds ES6 transformer
Tip revision: c759b63
noNullRule.ts
import * as Lint from "tslint/lib/lint";
import * as ts from "typescript";


export class Rule extends Lint.Rules.AbstractRule {
    public static FAILURE_STRING = "Don't use the 'null' keyword - use 'undefined' for missing values instead";

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

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