-
Notifications
You must be signed in to change notification settings - Fork 885
Conversation
Thanks for your interest in palantir/tslint, @subash-a! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
554cbfe
to
5dc069a
Compare
Looks great to me 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, minor changes
@@ -0,0 +1,77 @@ | |||
import * as ts from "typescript"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license, metadata
import * as Lint from "../index"; | ||
|
||
export class Rule extends Lint.Rules.TypedRule { | ||
public static EMPTY_INTERFACE_INSTANCE = "Invalid {} type: Explicit type parameter needs to be provided to the constructor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove Invalid {} type:
class NoInferredEmptyObjectTypeRule extends Lint.ProgramAwareRuleWalker { | ||
|
||
public visitNewExpression(node: ts.NewExpression): void { | ||
let checker = this.getTypeChecker(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do this once, in a constructor. Store in class member
let nodeTypeArgs = node.typeArguments; | ||
let isObjectReference = (o: ts.TypeReference) => { | ||
/* tslint:disable:no-bitwise */ | ||
return ((o.flags & ts.TypeFlags.Reference) === ts.TypeFlags.Reference); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use utils.isNodeFlagSet
private isEmptyObjectInterface(objType: ts.ObjectType): boolean { | ||
let typeChecker = this.getTypeChecker(); | ||
/* tslint:disable:no-bitwise */ | ||
let isAnonymous = ((objType.flags & ts.TypeFlags.Anonymous) === ts.TypeFlags.Anonymous); // the type of the Object will be anonymous |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use utils.isNodeFlagSet
hasProblematicCallSignatures = true; | ||
} | ||
} | ||
if (isAnonymous && !hasProblematicCallSignatures && !hasProperties && !hasNumberIndexType && !hasStringIndexType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need if
statement, just return the condition
5dc069a
to
39e78b8
Compare
@nchen63 Thanks for the review again, I have made all the suggested changes, however the |
Yes, please add this function to utils |
The `no-inferred-empty-object-type` rule is useful for capturing the errors caused by typescript in places where it assumes {} as the default type since no explicit type has been provided.
39e78b8
to
f37006e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
PR checklist
Introduced a rule which checks for type inference being {} (empty object type) and then throws an error, this PR is based on discussions in the issue mentioned above. @myitcv any comments on how we can improve this?