Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tslint rules for #3994 #4458

Merged
merged 6 commits into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compile vs tslints services dts, null check lint
  • Loading branch information
weswigham committed Aug 26, 2015
commit 7813121c4d77e50aad0eed3152ef1f1156c7b574
3 changes: 2 additions & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion scripts/tslint/nextLineRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../lib/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/typings/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/lib/tslint.d.ts" />

const OPTION_CATCH = "check-catch";
Expand Down
2 changes: 1 addition & 1 deletion scripts/tslint/noInferrableTypesRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../lib/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/typings/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/lib/tslint.d.ts" />


Expand Down
20 changes: 20 additions & 0 deletions scripts/tslint/noNullRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="../../node_modules/tslint/typings/typescriptServices.d.ts" />
/// <reference path="../../node_modules/tslint/lib/tslint.d.ts" />


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));
}
}
}
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
],
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-inferrable-types": true
"no-inferrable-types": true,
"no-null": true
}
}