aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/radixRule.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/tslint/lib/rules/radixRule.js')
-rw-r--r--node_modules/tslint/lib/rules/radixRule.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/node_modules/tslint/lib/rules/radixRule.js b/node_modules/tslint/lib/rules/radixRule.js
index 3d1f695de..e5548c558 100644
--- a/node_modules/tslint/lib/rules/radixRule.js
+++ b/node_modules/tslint/lib/rules/radixRule.js
@@ -32,7 +32,7 @@ var Rule = /** @class */ (function (_super) {
Rule.metadata = {
ruleName: "radix",
description: "Requires the radix parameter to be specified when calling `parseInt`.",
- rationale: (_a = ["\n From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt):\n > Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.\n > Different implementations produce different results when a radix is not specified, usually defaulting the value to 10."], _a.raw = ["\n From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt):\n > Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.\n > Different implementations produce different results when a radix is not specified, usually defaulting the value to 10."], Lint.Utils.dedent(_a)),
+ rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt):\n > Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.\n > Different implementations produce different results when a radix is not specified, usually defaulting the value to 10."], ["\n From [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt):\n > Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.\n > Different implementations produce different results when a radix is not specified, usually defaulting the value to 10."]))),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
@@ -44,21 +44,36 @@ var Rule = /** @class */ (function (_super) {
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
+function isParseInt(expression) {
+ return tsutils_1.isIdentifier(expression) && expression.text === "parseInt";
+}
+function isPropertyAccessParseInt(expression) {
+ return tsutils_1.isPropertyAccessExpression(expression) && expression.name.text === "parseInt";
+}
+function isPropertyAccessOfIdentifier(expression, identifers) {
+ return tsutils_1.isPropertyAccessExpression(expression) && tsutils_1.isIdentifier(expression.expression) &&
+ identifers.some(function (identifer) { return expression.expression.text === identifer; });
+}
+function isPropertyAccessOfProperty(expression, identifers) {
+ return tsutils_1.isPropertyAccessExpression(expression) && tsutils_1.isPropertyAccessExpression(expression.expression) &&
+ identifers.some(function (identifer) { return expression.expression.name.text === identifer; });
+}
function walk(ctx) {
return ts.forEachChild(ctx.sourceFile, function cb(node) {
if (tsutils_1.isCallExpression(node) && node.arguments.length === 1 &&
(
// parseInt("123")
- tsutils_1.isIdentifier(node.expression) && node.expression.text === "parseInt" ||
- // window.parseInt("123") || global.parseInt("123")
- tsutils_1.isPropertyAccessExpression(node.expression) &&
- node.expression.name.text === "parseInt" &&
- tsutils_1.isIdentifier(node.expression.expression) &&
- (node.expression.expression.text === "global" ||
- node.expression.expression.text === "window"))) {
+ isParseInt(node.expression) ||
+ // window.parseInt("123") || global.parseInt("123") || Number.parseInt("123")
+ isPropertyAccessParseInt(node.expression) &&
+ isPropertyAccessOfIdentifier(node.expression, ["global", "window", "Number"]) ||
+ // window.Number.parseInt("123") || global.Number.parseInt("123")
+ isPropertyAccessParseInt(node.expression) &&
+ isPropertyAccessOfProperty(node.expression, ["Number"]) &&
+ isPropertyAccessOfIdentifier(node.expression.expression, ["global", "window"]))) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
}
return ts.forEachChild(node, cb);
});
}
-var _a;
+var templateObject_1;