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 (originally #1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Chen committed Nov 19, 2016
1 parent 104bba2 commit 1ab2f2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils";
* Linter that can lint multiple files in consecutive runs.
*/
class Linter {
public static VERSION = "4.0.0-dev.2";
public static VERSION = "4.0.0";

public static findConfiguration = findConfiguration;
public static findConfigurationPath = findConfigurationPath;
Expand Down
12 changes: 11 additions & 1 deletion src/rules/noNullKeywordRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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 1ab2f2b

Please sign in to comment.