From 1beefd38239be035c929f0d46bd9a19fdcba4d07 Mon Sep 17 00:00:00 2001 From: Alexej Yaroshevich Date: Wed, 1 Jul 2015 04:47:07 +0300 Subject: [PATCH] checkReturnTypes: skip checking 'this.something' Fixes #115 Closes gh-120 --- lib/jsdoc.js | 6 +++++- test/lib/rules/validate-jsdoc/check-return-types.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/jsdoc.js b/lib/jsdoc.js index 8f27e6c..e9c9eb3 100644 --- a/lib/jsdoc.js +++ b/lib/jsdoc.js @@ -519,12 +519,16 @@ function jsDocMatchType (variants, argument) { result = result || (type === 'array'); } else if (argument.type === 'NewExpression' && type === 'object') { - result = result || true; + result = true; } else if (argument.type === 'NewExpression') { var c = argument.callee; var exam = c.name; if (!exam && c.type === 'MemberExpression') { + if (c.object.type === 'ThisExpression') { + result = true; + break; + } var cur = c; exam = []; while (cur.object) { diff --git a/test/lib/rules/validate-jsdoc/check-return-types.js b/test/lib/rules/validate-jsdoc/check-return-types.js index 45174aa..21421d2 100644 --- a/test/lib/rules/validate-jsdoc/check-return-types.js +++ b/test/lib/rules/validate-jsdoc/check-return-types.js @@ -291,6 +291,16 @@ describe('lib/rules/validate-jsdoc/check-return-types', function () { }; }; } + }, { + it: 'should not report on `@returns {Class}` for `new this.*`. issue #115', + code: function () { + /** + * @returns {Element} + */ + function foo() { + return new this.something(); + } + } } /* jshint ignore:end */ ]);