Skip to content

Commit

Permalink
Update: Use process @abstract when processing @return (fixes eslint#5941
Browse files Browse the repository at this point in the history
) (eslint#5945)

Allow @return(s) without return keyword in function when @abstract/virtual is present
  • Loading branch information
SimonSchick authored and nzakas committed Apr 25, 2016
1 parent 52a4bea commit 51ddd4b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/rules/valid-jsdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ class Foo {
this.num1 = num1;
}
}

// @returns allowed without return if used with @abstract
class Foo {
/**
* @abstract
* @return {Number} num
*/
abstractMethod () {
throw new Error('Not implemented');
}
}

```

## Options
Expand Down
8 changes: 7 additions & 1 deletion lib/rules/valid-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ module.exports = function(context) {
hasConstructor = false,
isInterface = false,
isOverride = false,
isAbstract = false,
params = Object.create(null),
jsdoc;

Expand Down Expand Up @@ -233,7 +234,7 @@ module.exports = function(context) {
case "returns":
hasReturns = true;

if (!requireReturn && !functionData.returnPresent && (tag.type === null || !isValidReturnType(tag))) {
if (!requireReturn && !functionData.returnPresent && (tag.type === null || !isValidReturnType(tag)) && !isAbstract) {
context.report(jsdocNode, "Unexpected @" + tag.title + " tag; function has no return statement.");
} else {
if (requireReturnType && !tag.type) {
Expand All @@ -257,6 +258,11 @@ module.exports = function(context) {
isOverride = true;
break;

case "abstract":
case "virtual":
isAbstract = true;
break;

case "interface":
isInterface = true;
break;
Expand Down
42 changes: 42 additions & 0 deletions tests/lib/rules/valid-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,48 @@ ruleTester.run("valid-jsdoc", rule, {
parserOptions: {
ecmaVersion: 6
}
},

// abstract
{
code:
"/**\n" +
"* Description\n" +
"* @abstract\n" +
"* @returns {Number} desc\n" +
"*/\n" +
"function foo(){ throw new Error('Not Implemented'); }",
options: [{ requireReturn: false }]
},
{
code:
"/**\n" +
"* Description\n" +
"* @virtual\n" +
"* @returns {Number} desc\n" +
"*/\n" +
"function foo(){ throw new Error('Not Implemented'); }",
options: [{ requireReturn: false }]
},
{
code:
"/**\n" +
"* Description\n" +
"* @abstract\n" +
"* @returns {Number} desc\n" +
"*/\n" +
"function foo(){ throw new Error('Not Implemented'); }",
options: [{ requireReturn: true }]
},
{
code:
"/**\n" +
"* Description\n" +
"* @abstract\n" +
"* @returns {Number} desc\n" +
"*/\n" +
"function foo(){}",
options: [{ requireReturn: true }]
}
],

Expand Down

0 comments on commit 51ddd4b

Please sign in to comment.