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

Commit

Permalink
no-unbound-method: add another exception (#3610)
Browse files Browse the repository at this point in the history
Reading a property with square brackets, though rare, should be allowed because it won't be effected by an unbound this.
  • Loading branch information
ethanresnick authored and giladgray committed May 1, 2018
1 parent 0503f6d commit f47aeb3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/noUnboundMethodRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ function isSafeUse(node: ts.Node): boolean {
return (parent as ts.CallExpression).expression === node;
case ts.SyntaxKind.TaggedTemplateExpression:
return (parent as ts.TaggedTemplateExpression).tag === node;
// E.g. `obj.method.bind(obj)`.
// E.g. `obj.method.bind(obj) or obj.method["prop"]`.
case ts.SyntaxKind.PropertyAccessExpression:
case ts.SyntaxKind.ElementAccessExpression:
return true;
// Allow most binary operators, but don't allow e.g. `myArray.forEach(obj.method || otherObj.otherMethod)`.
case ts.SyntaxKind.BinaryExpression:
Expand Down
1 change: 1 addition & 0 deletions test/rules/no-unbound-method/default/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function f(i: I) {
i.m ? 1 : 2;
if (i.m) {}
!i.m;
i.m["length"];
return i.m!;
~~~ [0]
}
Expand Down

0 comments on commit f47aeb3

Please sign in to comment.