aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/noMagicNumbersRule.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/tslint/lib/rules/noMagicNumbersRule.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/tslint/lib/rules/noMagicNumbersRule.js')
-rw-r--r--node_modules/tslint/lib/rules/noMagicNumbersRule.js70
1 files changed, 34 insertions, 36 deletions
diff --git a/node_modules/tslint/lib/rules/noMagicNumbersRule.js b/node_modules/tslint/lib/rules/noMagicNumbersRule.js
index 1e1b5f5fb..8888ceb38 100644
--- a/node_modules/tslint/lib/rules/noMagicNumbersRule.js
+++ b/node_modules/tslint/lib/rules/noMagicNumbersRule.js
@@ -17,9 +17,9 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
-var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
+var utils_1 = require("../language/utils");
var Rule = (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
@@ -29,40 +29,40 @@ var Rule = (function (_super) {
var allowedNumbers = this.ruleArguments.length > 0 ? this.ruleArguments : Rule.DEFAULT_ALLOWED;
return this.applyWithWalker(new NoMagicNumbersWalker(sourceFile, this.ruleName, new Set(allowedNumbers.map(String))));
};
+ /* 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)),
+ optionsDescription: "A list of allowed numbers.",
+ options: {
+ type: "array",
+ items: {
+ type: "number",
+ },
+ minLength: 1,
+ },
+ optionExamples: [true, [true, 1, 2, 3]],
+ type: "typescript",
+ typescriptOnly: false,
+ };
+ /* tslint:enable:object-literal-sort-keys */
+ Rule.FAILURE_STRING = "'magic numbers' are not allowed";
+ Rule.ALLOWED_NODES = new Set([
+ ts.SyntaxKind.ExportAssignment,
+ ts.SyntaxKind.FirstAssignment,
+ ts.SyntaxKind.LastAssignment,
+ ts.SyntaxKind.PropertyAssignment,
+ ts.SyntaxKind.ShorthandPropertyAssignment,
+ ts.SyntaxKind.VariableDeclaration,
+ ts.SyntaxKind.VariableDeclarationList,
+ ts.SyntaxKind.EnumMember,
+ ts.SyntaxKind.PropertyDeclaration,
+ ts.SyntaxKind.Parameter,
+ ]);
+ Rule.DEFAULT_ALLOWED = [-1, 0, 1];
return Rule;
}(Lint.Rules.AbstractRule));
-/* 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)),
- optionsDescription: "A list of allowed numbers.",
- options: {
- type: "array",
- items: {
- type: "number",
- },
- minLength: 1,
- },
- optionExamples: [true, [true, 1, 2, 3]],
- type: "typescript",
- typescriptOnly: false,
-};
-/* tslint:enable:object-literal-sort-keys */
-Rule.FAILURE_STRING = "'magic numbers' are not allowed";
-Rule.ALLOWED_NODES = new Set([
- ts.SyntaxKind.ExportAssignment,
- ts.SyntaxKind.FirstAssignment,
- ts.SyntaxKind.LastAssignment,
- ts.SyntaxKind.PropertyAssignment,
- ts.SyntaxKind.ShorthandPropertyAssignment,
- ts.SyntaxKind.VariableDeclaration,
- ts.SyntaxKind.VariableDeclarationList,
- ts.SyntaxKind.EnumMember,
- ts.SyntaxKind.PropertyDeclaration,
- ts.SyntaxKind.Parameter,
-]);
-Rule.DEFAULT_ALLOWED = [-1, 0, 1];
exports.Rule = Rule;
var NoMagicNumbersWalker = (function (_super) {
tslib_1.__extends(NoMagicNumbersWalker, _super);
@@ -75,9 +75,7 @@ var NoMagicNumbersWalker = (function (_super) {
if (node.kind === ts.SyntaxKind.NumericLiteral) {
return _this.checkNumericLiteral(node, node.text);
}
- if (tsutils_1.isPrefixUnaryExpression(node) &&
- node.operator === ts.SyntaxKind.MinusToken &&
- node.operand.kind === ts.SyntaxKind.NumericLiteral) {
+ if (utils_1.isNegativeNumberLiteral(node)) {
return _this.checkNumericLiteral(node, "-" + node.operand.text);
}
return ts.forEachChild(node, cb);