-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Feature] require-returns #14 #137 * docs: generate docs * [Feature] require-returns #14 #137 * [Feature] require-returns #14 #137 * [Misprint] remove eslint --fix * [Docs] Available require-returns * docs: generate docs * [Docs] Removed docs generated from README.md * docs: generate docs * [Docs] Restore generated docs
- Loading branch information
Showing
7 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### `require-returns` | ||
|
||
Requires returns are documented. | ||
|
||
||| | ||
|---|---| | ||
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`| | ||
|Tags|`returns`| | ||
|
||
<!-- assertions requireParam --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import _ from 'lodash'; | ||
import iterateJsdoc from '../iterateJsdoc'; | ||
|
||
export default iterateJsdoc(({ | ||
jsdoc, | ||
report, | ||
utils | ||
}) => { | ||
const targetTagName = utils.getPreferredTagName('returns'); | ||
|
||
const jsdocTags = _.filter(jsdoc.tags, { | ||
tag: targetTagName | ||
}); | ||
|
||
const sourcecode = utils.getFunctionSourceCode(); | ||
|
||
if (JSON.stringify(jsdocTags) === '[]' && sourcecode.indexOf('return') >= 1) { | ||
report('Missing JSDoc @' + targetTagName + ' declaration.'); | ||
} | ||
|
||
if (JSON.stringify(jsdocTags) !== '[]' && sourcecode.indexOf('return') < 1) { | ||
report('Present JSDoc @' + targetTagName + ' declaration but not available return expression in function.'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
export default { | ||
invalid: [ | ||
{ | ||
code: ` | ||
/** | ||
* | ||
*/ | ||
function quux (foo) { | ||
return foo; | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
line: 2, | ||
message: 'Missing JSDoc @returns declaration.' | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
/** | ||
* | ||
*/ | ||
function quux (foo) { | ||
return foo; | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
line: 2, | ||
message: 'Missing JSDoc @return declaration.' | ||
} | ||
], | ||
settings: { | ||
jsdoc: { | ||
tagNamePreference: { | ||
returns: 'return' | ||
} | ||
} | ||
} | ||
} | ||
], | ||
valid: [ | ||
{ | ||
code: ` | ||
/** | ||
* @returns Foo. | ||
*/ | ||
function quux () { | ||
return foo; | ||
} | ||
` | ||
}, | ||
{ | ||
code: ` | ||
/** | ||
* | ||
*/ | ||
function quux () { | ||
} | ||
` | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters