-
Notifications
You must be signed in to change notification settings - Fork 889
Radix rule checks Number.parseInt(), window.Number.parseInt(), global… #3901
Conversation
Thanks for your interest in palantir/tslint, @david-cannady! 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. |
Test failures don't appear to be the result of any changes that I've made. |
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.
pushing a new commit should resolve build errors
src/rules/radixRule.ts
Outdated
isIdentifier(node.expression.expression.expression) && | ||
( | ||
node.expression.expression.expression.text === "global" || | ||
node.expression.expression.expression.text === "window" |
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.
please split this absolute unit of a condition into multiple variables, one for each top-level ||
clause.
so it reads like if (isParseInt || isGlobalParseInt || isNumberParseInt)
instead of this madness which is quite hard to validate correctness now that you've added more ||
clauses.
52b90cd
to
37c9a9f
Compare
Sorry for the lateness of this update. This should be a lot easier to read and validate. However, some CI unrelated tests are failing. |
@david-cannady please merge latest |
function isPropertyAccessParseInt( | ||
expression: ts.LeftHandSideExpression, | ||
): expression is ts.PropertyAccessExpression { | ||
return isPropertyAccessExpression(expression) && expression.name.text === "parseInt"; |
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.
this seems like it would ban myCustomClass.parseInt(arg)
, which could be a perfectly valid use of a non-library function called parseInt
. true?
please add a test for this case.
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.
isPropertyAccessParseInt() will return true for that case yes. However, in conjunction with isPropertyAccessOfProperty() and isPropertyAccessOfIdentifier(), the check is constrained to specific instances. A test already exists for this:
parser.parseInt("123");
on line 6 of the radix rule test.
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.
nice
….Number.parseInt()
37c9a9f
to
81f6fed
Compare
….Number.parseInt() (palantir#3901)
….Number.parseInt()
PR checklist
Overview of change:
radix rule now enforced on calls to Number.parseInt(), window.Number.parseInt(), and global.Number.parseInt()
Is there anything you'd like reviewers to focus on?
CHANGELOG.md entry: