Conversation
bdb352c
to
854c226
Compare
How should I update documentation for this? |
you can run the doc generator by running |
@natgabb done |
~~~~~~~~~~~~~~~~~~~~~~~~~~ [typeof must be compared to correct value] | ||
|
||
const string = "string"; | ||
typeof bar === string |
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.
needs more positive tests. Currently only tests against a string variable. Needs to test against directly against a string, against a template string, and a template string with a replacement variable. Also exercise different types of valid types
Hmmm failures don't make sense to me |
} | ||
|
||
private static isLegalStringLiteral(node: ts.Node) { | ||
return ComparisonWalker.LEGAL_TYPEOF_RESULTS.indexOf(node.getText()) > -1; |
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.
it's failing here because node.getText()
includes the quotes. For example, "string"
instead of what you want: string
. If you use node.text
, it will exclude the quotes
@mohsen1 thanks for the contribution! |
PR checklist
What changes did you make?
Added
typeof-compare
rule. It makes sure result oftypeof
expressions are always compared to legal strings. I originally asked TypeScript to make comparing result oftypeof
to illegal strings a compiler error but per spectypeof
can return anything!Is there anything you'd like reviewers to focus on?
This is my first rule. I'm almost certain I'm missing stuff in this PR.