aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/tslint/lib/rules/noUnsafeAnyRule.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/tslint/lib/rules/noUnsafeAnyRule.js')
-rw-r--r--node_modules/tslint/lib/rules/noUnsafeAnyRule.js50
1 files changed, 44 insertions, 6 deletions
diff --git a/node_modules/tslint/lib/rules/noUnsafeAnyRule.js b/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
index c0a36360a..301b55b48 100644
--- a/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
+++ b/node_modules/tslint/lib/rules/noUnsafeAnyRule.js
@@ -20,6 +20,7 @@ var tslib_1 = require("tslib");
var tsutils_1 = require("tsutils");
var ts = require("typescript");
var Lint = require("../index");
+var utils_1 = require("../utils");
var Rule = /** @class */ (function (_super) {
tslib_1.__extends(Rule, _super);
function Rule() {
@@ -31,10 +32,11 @@ var Rule = /** @class */ (function (_super) {
/* tslint:disable:object-literal-sort-keys */
Rule.metadata = {
ruleName: "no-unsafe-any",
- description: (_a = ["\n Warns when using an expression of type 'any' in a dynamic way.\n Uses are only allowed if they would work for `{} | null | undefined`.\n Type casts and tests are allowed.\n Expressions that work on all values (such as `\"\" + x`) are allowed."], _a.raw = ["\n Warns when using an expression of type 'any' in a dynamic way.\n Uses are only allowed if they would work for \\`{} | null | undefined\\`.\n Type casts and tests are allowed.\n Expressions that work on all values (such as \\`\"\" + x\\`) are allowed."], Lint.Utils.dedent(_a)),
+ description: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Warns when using an expression of type 'any' in a dynamic way.\n Uses are only allowed if they would work for `{} | null | undefined`.\n Type casts and tests are allowed.\n Expressions that work on all values (such as `\"\" + x`) are allowed."], ["\n Warns when using an expression of type 'any' in a dynamic way.\n Uses are only allowed if they would work for \\`{} | null | undefined\\`.\n Type casts and tests are allowed.\n Expressions that work on all values (such as \\`\"\" + x\\`) are allowed."]))),
optionsDescription: "Not configurable.",
options: null,
optionExamples: [true],
+ rationale: Lint.Utils.dedent(templateObject_2 || (templateObject_2 = tslib_1.__makeTemplateObject(["\n If you're dealing with data of unknown or \"any\" types, you shouldn't be accessing members of it.\n Either add type annotations for properties that may exist or change the data type to the empty object type `{}`.\n\n Alternately, if you're creating storage or handling for consistent but unknown types, such as in data structures\n or serialization, use `<T>` template types for generic type handling.\n\n Also see the `no-any` rule.\n "], ["\n If you're dealing with data of unknown or \"any\" types, you shouldn't be accessing members of it.\n Either add type annotations for properties that may exist or change the data type to the empty object type \\`{}\\`.\n\n Alternately, if you're creating storage or handling for consistent but unknown types, such as in data structures\n or serialization, use \\`<T>\\` template types for generic type handling.\n\n Also see the \\`no-any\\` rule.\n "]))),
type: "functionality",
typescriptOnly: true,
requiresTypeInfo: true,
@@ -115,6 +117,10 @@ var NoUnsafeAnyWalker = /** @class */ (function (_super) {
return initializer !== undefined &&
this.visitNode(initializer, isPropertyAny(node, this.checker));
}
+ case ts.SyntaxKind.SpreadAssignment:
+ return this.visitNode(node.expression,
+ // allow any in object spread, but not in object rest
+ !tsutils_1.isReassignmentTarget(node.parent));
case ts.SyntaxKind.ComputedPropertyName:
return this.visitNode(node.expression, true);
case ts.SyntaxKind.TaggedTemplateExpression: {
@@ -284,10 +290,10 @@ var NoUnsafeAnyWalker = /** @class */ (function (_super) {
case ts.SyntaxKind.EqualsEqualsToken:
case ts.SyntaxKind.CommaToken: // Allow `any, any`
case ts.SyntaxKind.BarBarToken: // Allow `any || any`
- case ts.SyntaxKind.AmpersandAmpersandToken:// Allow `any && any`
+ case ts.SyntaxKind.AmpersandAmpersandToken: // Allow `any && any`
allowAnyLeft = allowAnyRight = true;
break;
- case ts.SyntaxKind.InstanceOfKeyword:// Allow test
+ case ts.SyntaxKind.InstanceOfKeyword: // Allow test
allowAnyLeft = true;
break;
case ts.SyntaxKind.EqualsToken:
@@ -359,12 +365,44 @@ function isPropertyAny(node, checker) {
return true;
}
function isNodeAny(node, checker) {
+ var symbol = checker.getSymbolAtLocation(node);
+ if (symbol !== undefined && tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Alias)) {
+ symbol = checker.getAliasedSymbol(symbol);
+ }
+ if (symbol !== undefined) {
+ // NamespaceModule is a type-only namespace without runtime value, its type is 'any' when used as 'ns.Type' -> avoid error
+ if (tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.NamespaceModule)) {
+ return false;
+ }
+ if (tsutils_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Type)) {
+ return isAny(checker.getDeclaredTypeOfSymbol(symbol));
+ }
+ }
+ // Lowercase JSX elements are assumed to be allowed by design
+ if (isJsxNativeElement(node)) {
+ return false;
+ }
return isAny(checker.getTypeAtLocation(node));
}
+var jsxElementTypes = new Set([
+ ts.SyntaxKind.JsxClosingElement,
+ ts.SyntaxKind.JsxOpeningElement,
+ ts.SyntaxKind.JsxSelfClosingElement,
+]);
+function isJsxNativeElement(node) {
+ if (!tsutils_1.isIdentifier(node) || node.parent === undefined) {
+ return false;
+ }
+ // TypeScript <=2.1 incorrectly parses JSX fragments
+ if (node.text === "") {
+ return true;
+ }
+ return jsxElementTypes.has(node.parent.kind) && utils_1.isLowerCase(node.text[0]);
+}
function isStringLike(expr, checker) {
- return Lint.isTypeFlagSet(checker.getTypeAtLocation(expr), ts.TypeFlags.StringLike);
+ return tsutils_1.isTypeFlagSet(checker.getTypeAtLocation(expr), ts.TypeFlags.StringLike);
}
function isAny(type) {
- return type !== undefined && Lint.isTypeFlagSet(type, ts.TypeFlags.Any);
+ return type !== undefined && tsutils_1.isTypeFlagSet(type, ts.TypeFlags.Any);
}
-var _a;
+var templateObject_1, templateObject_2;