diff options
Diffstat (limited to 'node_modules/tslint/lib/rules/noStringLiteralRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noStringLiteralRule.js | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/node_modules/tslint/lib/rules/noStringLiteralRule.js b/node_modules/tslint/lib/rules/noStringLiteralRule.js index c543aa4d8..c0669cf83 100644 --- a/node_modules/tslint/lib/rules/noStringLiteralRule.js +++ b/node_modules/tslint/lib/rules/noStringLiteralRule.js @@ -25,14 +25,17 @@ var Rule = /** @class */ (function (_super) { function Rule() { return _super !== null && _super.apply(this, arguments) || this; } + Rule.id = function (input) { + return input; + }; Rule.prototype.apply = function (sourceFile) { return this.applyWithFunction(sourceFile, walk); }; /* tslint:disable:object-literal-sort-keys */ Rule.metadata = { ruleName: "no-string-literal", - description: (_a = ["\n Forbids unnecessary string literal property access.\n Allows `obj[\"prop-erty\"]` (can't be a regular property access).\n Disallows `obj[\"property\"]` (should be `obj.property`)."], _a.raw = ["\n Forbids unnecessary string literal property access.\n Allows \\`obj[\"prop-erty\"]\\` (can't be a regular property access).\n Disallows \\`obj[\"property\"]\\` (should be \\`obj.property\\`)."], Lint.Utils.dedent(_a)), - rationale: (_b = ["\n If `--noImplicitAny` is turned off,\n property access via a string literal will be 'any' if the property does not exist."], _b.raw = ["\n If \\`--noImplicitAny\\` is turned off,\n property access via a string literal will be 'any' if the property does not exist."], Lint.Utils.dedent(_b)), + description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Forbids unnecessary string literal property access.\n Allows `obj[\"prop-erty\"]` (can't be a regular property access).\n Disallows `obj[\"property\"]` (should be `obj.property`)."], ["\n Forbids unnecessary string literal property access.\n Allows \\`obj[\"prop-erty\"]\\` (can't be a regular property access).\n Disallows \\`obj[\"property\"]\\` (should be \\`obj.property\\`)."]))), + rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n If `--noImplicitAny` is turned off,\n property access via a string literal will be 'any' if the property does not exist."], ["\n If \\`--noImplicitAny\\` is turned off,\n property access via a string literal will be 'any' if the property does not exist."]))), optionsDescription: "Not configurable.", options: null, optionExamples: [true], @@ -50,8 +53,12 @@ function walk(ctx) { if (tsutils_1.isElementAccessExpression(node)) { var argument = node.argumentExpression; if (argument !== undefined && tsutils_1.isStringLiteral(argument) && tsutils_1.isValidPropertyAccess(argument.text)) { - // for compatibility with typescript@<2.5.0 to avoid fixing expr['__foo'] to expr.___foo - var propertyName = ts.unescapeIdentifier(argument.text); // tslint:disable-line:deprecation + // typescript@<2.5.0 has an extra underscore in escaped identifier text content, + // to avoid fixing issue `expr['__foo'] → expr.___foo`, unescapeIdentifier() is to be used + // As of typescript@3, unescapeIdentifier() removed, thus check in runtime, if the method exists + // tslint:disable-next-line no-unsafe-any strict-boolean-expressions + var unescapeIdentifier = ts.unescapeIdentifier || Rule.id; + var propertyName = unescapeIdentifier(argument.text); ctx.addFailureAtNode(argument, Rule.FAILURE_STRING, // expr['foo'] -> expr.foo Lint.Replacement.replaceFromTo(node.expression.end, node.end, "." + propertyName)); @@ -60,4 +67,4 @@ function walk(ctx) { return ts.forEachChild(node, cb); }); } -var _a, _b; +var templateObject_1, templateObject_2; |