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

Radix rule checks Number.parseInt(), window.Number.parseInt(), global… #3901

Merged
merged 1 commit into from
Jun 26, 2018

Conversation

david-cannady
Copy link
Contributor

….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:

@palantirtech
Copy link
Member

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.

@david-cannady
Copy link
Contributor Author

Test failures don't appear to be the result of any changes that I've made.

Copy link

@giladgray giladgray left a 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

isIdentifier(node.expression.expression.expression) &&
(
node.expression.expression.expression.text === "global" ||
node.expression.expression.expression.text === "window"
Copy link

@giladgray giladgray May 17, 2018

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.

@david-cannady david-cannady force-pushed the radix-Number branch 3 times, most recently from 52b90cd to 37c9a9f Compare June 8, 2018 22:29
@david-cannady
Copy link
Contributor Author

david-cannady commented Jun 8, 2018

Sorry for the lateness of this update. This should be a lot easier to read and validate. However, some CI unrelated tests are failing.

@giladgray
Copy link

@david-cannady please merge latest master to fix tests

function isPropertyAccessParseInt(
expression: ts.LeftHandSideExpression,
): expression is ts.PropertyAccessExpression {
return isPropertyAccessExpression(expression) && expression.name.text === "parseInt";

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.

Copy link
Contributor Author

@david-cannady david-cannady Jun 19, 2018

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@giladgray giladgray merged commit d95dd91 into palantir:master Jun 26, 2018
pablobirukov pushed a commit to evolution-gaming/tslint that referenced this pull request Jul 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants