Skip to content

Commit

Permalink
arrow-parens rule shouldn't warn against generics (palantir#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuichiNukiyama authored and jkillian committed Aug 7, 2016
1 parent fc9a72d commit e23b188
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rules/arrowParensRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ class ArrowParensWalker extends Lint.RuleWalker {
const lastToken = node.getChildAt(2);
const width = text.length;
const position = parameter.getStart();
let isGenerics = false;

if (firstToken.kind !== ts.SyntaxKind.OpenParenToken || lastToken.kind !== ts.SyntaxKind.CloseParenToken) {
// If firstToken is LessThanToken, it would be Generics.
if (firstToken.kind === ts.SyntaxKind.LessThanToken) {
isGenerics = true;
}

if ((firstToken.kind !== ts.SyntaxKind.OpenParenToken || lastToken.kind !== ts.SyntaxKind.CloseParenToken) && !isGenerics) {
this.addFailure(this.createFailure(position, width, Rule.FAILURE_STRING));
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/rules/arrow-parens/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ var f = a: number => {}; // TSLint don't warn. But syntax is wrong.
class Foo {
a: (a) =>{}
}
var bar = <T>(method: () => T) => {
method();
};
var barbar = <T>(method: (a: any) => T) => {
method("");
};
var barbarbar = <T>(method: (a) => T) => {
method("");
};
var piyo = <T, U>(method: () => T) => {
method();
};

// invalid case
var e = (a => {})(1);
Expand Down

0 comments on commit e23b188

Please sign in to comment.