diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/tslint/lib/rules/noUnboundMethodRule.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/tslint/lib/rules/noUnboundMethodRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noUnboundMethodRule.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/node_modules/tslint/lib/rules/noUnboundMethodRule.js b/node_modules/tslint/lib/rules/noUnboundMethodRule.js index 153550c57..d8085193a 100644 --- a/node_modules/tslint/lib/rules/noUnboundMethodRule.js +++ b/node_modules/tslint/lib/rules/noUnboundMethodRule.js @@ -34,13 +34,14 @@ var Rule = /** @class */ (function (_super) { /* tslint:disable:object-literal-sort-keys */ Rule.metadata = { ruleName: "no-unbound-method", - description: "Warns when a method is used as outside of a method call.", + description: "Warns when a method is used outside of a method call.", optionsDescription: "You may optionally pass \"" + OPTION_IGNORE_STATIC + "\" to ignore static methods.", options: { type: "string", enum: [OPTION_IGNORE_STATIC], }, optionExamples: [true, [true, OPTION_IGNORE_STATIC]], + rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Class functions don't preserve the class scope when passed as standalone variables.\n For example, this code will log the global scope (`window`/`global`), not the class instance:\n\n ```\n class MyClass {\n public log(): void {\n console.log(this);\n }\n }\n\n const instance = new MyClass();\n const log = instance.log;\n\n log();\n ```\n\n You need to either use an arrow lambda (`() => {...}`) or call the function with the correct scope.\n\n ```\n class MyClass {\n public logArrowBound = (): void => {\n console.log(bound);\n };\n\n public logManualBind(): void {\n console.log(this);\n }\n }\n\n const instance = new MyClass();\n const logArrowBound = instance.logArrowBound;\n const logManualBind = instance.logManualBind.bind(instance);\n\n logArrowBound();\n logManualBind();\n ```\n "], ["\n Class functions don't preserve the class scope when passed as standalone variables.\n For example, this code will log the global scope (\\`window\\`/\\`global\\`), not the class instance:\n\n \\`\\`\\`\n class MyClass {\n public log(): void {\n console.log(this);\n }\n }\n\n const instance = new MyClass();\n const log = instance.log;\n\n log();\n \\`\\`\\`\n\n You need to either use an arrow lambda (\\`() => {...}\\`) or call the function with the correct scope.\n\n \\`\\`\\`\n class MyClass {\n public logArrowBound = (): void => {\n console.log(bound);\n };\n\n public logManualBind(): void {\n console.log(this);\n }\n }\n\n const instance = new MyClass();\n const logArrowBound = instance.logArrowBound;\n const logManualBind = instance.logManualBind.bind(instance);\n\n logArrowBound();\n logManualBind();\n \\`\\`\\`\n "]))), type: "functionality", typescriptOnly: true, requiresTypeInfo: true, @@ -78,8 +79,9 @@ function isSafeUse(node) { return parent.expression === node; case ts.SyntaxKind.TaggedTemplateExpression: return parent.tag === node; - // E.g. `obj.method.bind(obj)`. + // E.g. `obj.method.bind(obj) or obj.method["prop"]`. case ts.SyntaxKind.PropertyAccessExpression: + case ts.SyntaxKind.ElementAccessExpression: return true; // Allow most binary operators, but don't allow e.g. `myArray.forEach(obj.method || otherObj.otherMethod)`. case ts.SyntaxKind.BinaryExpression: @@ -102,3 +104,4 @@ function isSafeUse(node) { return false; } } +var templateObject_1; |