Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Allow null keyword in a type position (#1277)
Browse files Browse the repository at this point in the history
Fixes #1265
  • Loading branch information
jkillian committed May 27, 2016
1 parent 962a238 commit c781f2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/rules/noNullKeywordRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ export class Rule extends Lint.Rules.AbstractRule {
class NullWalker extends Lint.RuleWalker {
public visitNode(node: ts.Node) {
super.visitNode(node);
if (node.kind === ts.SyntaxKind.NullKeyword) {
if (node.kind === ts.SyntaxKind.NullKeyword && !isPartOfType(node)) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
}
}
}

function isPartOfType({ parent }: ts.Node) {
while (parent != null) {
if (ts.SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= ts.SyntaxKind.LastTypeNode) {
return true;
}
parent = parent.parent;
}
return false;
}
5 changes: 5 additions & 0 deletions test/rules/no-null-keyword/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ var x = null; // error
~~~~ [Use 'undefined' instead of 'null']
console.log(null, x); // error
~~~~ [Use 'undefined' instead of 'null']

let match(): string | null;
interface foo {
bar: [number, null, string];
}

0 comments on commit c781f2d

Please sign in to comment.