diff options
Diffstat (limited to 'node_modules/tslint/lib/rules/noMagicNumbersRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noMagicNumbersRule.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/node_modules/tslint/lib/rules/noMagicNumbersRule.js b/node_modules/tslint/lib/rules/noMagicNumbersRule.js index 483130dfe..4678c4f73 100644 --- a/node_modules/tslint/lib/rules/noMagicNumbersRule.js +++ b/node_modules/tslint/lib/rules/noMagicNumbersRule.js @@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var ts = require("typescript"); +var tsutils_1 = require("tsutils"); var Lint = require("../index"); var utils_1 = require("../language/utils"); var Rule = /** @class */ (function (_super) { @@ -26,14 +27,13 @@ var Rule = /** @class */ (function (_super) { return _super !== null && _super.apply(this, arguments) || this; } Rule.prototype.apply = function (sourceFile) { - var allowedNumbers = this.ruleArguments.length > 0 ? this.ruleArguments : Rule.DEFAULT_ALLOWED; - return this.applyWithWalker(new NoMagicNumbersWalker(sourceFile, this.ruleName, new Set(allowedNumbers.map(String)))); + return this.applyWithWalker(new NoMagicNumbersWalker(sourceFile, this.ruleName, this.ruleArguments.length > 0 ? this.ruleArguments : Rule.DEFAULT_ALLOWED)); }; /* tslint:disable:object-literal-sort-keys */ Rule.metadata = { ruleName: "no-magic-numbers", - description: (_a = ["\n Disallows the use constant number values outside of variable assignments.\n When no list of allowed values is specified, -1, 0 and 1 are allowed by default."], _a.raw = ["\n Disallows the use constant number values outside of variable assignments.\n When no list of allowed values is specified, -1, 0 and 1 are allowed by default."], Lint.Utils.dedent(_a)), - rationale: (_b = ["\n Magic numbers should be avoided as they often lack documentation, forcing\n them to be stored in variables gives them implicit documentation."], _b.raw = ["\n Magic numbers should be avoided as they often lack documentation, forcing\n them to be stored in variables gives them implicit documentation."], Lint.Utils.dedent(_b)), + description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Disallows the use constant number values outside of variable assignments.\n When no list of allowed values is specified, -1, 0 and 1 are allowed by default."], ["\n Disallows the use constant number values outside of variable assignments.\n When no list of allowed values is specified, -1, 0 and 1 are allowed by default."]))), + rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n Magic numbers should be avoided as they often lack documentation.\n Forcing them to be stored in variables gives them implicit documentation.\n "], ["\n Magic numbers should be avoided as they often lack documentation.\n Forcing them to be stored in variables gives them implicit documentation.\n "]))), optionsDescription: "A list of allowed numbers.", options: { type: "array", @@ -72,6 +72,9 @@ var NoMagicNumbersWalker = /** @class */ (function (_super) { NoMagicNumbersWalker.prototype.walk = function (sourceFile) { var _this = this; var cb = function (node) { + if (tsutils_1.isCallExpression(node) && tsutils_1.isIdentifier(node.expression) && node.expression.text === "parseInt") { + return node.arguments.length === 0 ? undefined : cb(node.arguments[0]); + } if (node.kind === ts.SyntaxKind.NumericLiteral) { return _this.checkNumericLiteral(node, node.text); } @@ -83,10 +86,12 @@ var NoMagicNumbersWalker = /** @class */ (function (_super) { return ts.forEachChild(sourceFile, cb); }; NoMagicNumbersWalker.prototype.checkNumericLiteral = function (node, num) { - if (!Rule.ALLOWED_NODES.has(node.parent.kind) && !this.options.has(num)) { + /* Using Object.is() to differentiate between pos/neg zero */ + if (!Rule.ALLOWED_NODES.has(node.parent.kind) && + !this.options.some(function (allowedNum) { return Object.is(allowedNum, parseFloat(num)); })) { this.addFailureAtNode(node, Rule.FAILURE_STRING); } }; return NoMagicNumbersWalker; }(Lint.AbstractWalker)); -var _a, _b; +var templateObject_1, templateObject_2; |