diff --git a/Jakefile.js b/Jakefile.js index b30af95201a..d8f2355abb7 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -773,7 +773,8 @@ task("update-sublime", ["local", serverFile], function() { var tslintRuleDir = "scripts/tslint"; var tslintRules = ([ "nextLineRule", - "noInferrableTypesRule" + "noInferrableTypesRule", + "noNullRule" ]); var tslintRulesFiles = tslintRules.map(function(p) { return path.join(tslintRuleDir, p + ".ts"); diff --git a/scripts/tslint/nextLineRule.ts b/scripts/tslint/nextLineRule.ts index f1288e8e2f0..8e24aea45e5 100644 --- a/scripts/tslint/nextLineRule.ts +++ b/scripts/tslint/nextLineRule.ts @@ -1,4 +1,4 @@ -/// +/// /// const OPTION_CATCH = "check-catch"; diff --git a/scripts/tslint/noInferrableTypesRule.ts b/scripts/tslint/noInferrableTypesRule.ts index 806426dc9f9..16e0633c872 100644 --- a/scripts/tslint/noInferrableTypesRule.ts +++ b/scripts/tslint/noInferrableTypesRule.ts @@ -1,4 +1,4 @@ -/// +/// /// diff --git a/scripts/tslint/noNullRule.ts b/scripts/tslint/noNullRule.ts new file mode 100644 index 00000000000..2a2c5bc3717 --- /dev/null +++ b/scripts/tslint/noNullRule.ts @@ -0,0 +1,20 @@ +/// +/// + + +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)); + } + } +} diff --git a/tslint.json b/tslint.json index 2cc6cf80c92..4791e7c937c 100644 --- a/tslint.json +++ b/tslint.json @@ -38,6 +38,7 @@ ], "no-internal-module": true, "no-trailing-whitespace": true, - "no-inferrable-types": true + "no-inferrable-types": true, + "no-null": true } }