eslint-plugin-jsdoc
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -24,5 +24,14 @@ "use strict"; | ||
var sourcecode = utils.getFunctionSourceCode(); | ||
var sourcecode = utils.getFunctionSourceCode(); // build a one-liner to test against | ||
if (JSON.stringify(jsdocTags) === '[]' && sourcecode.indexOf('return') >= 1) { | ||
var flattenedSource = sourcecode.replace(/\r?\n|\r|\s/g, ''); | ||
var startsWithReturn = '(\\)\\s?\\{return)'; | ||
var endsWithReturn = '(return.*\\})'; | ||
var implicitReturn = '(\\s?=>\\s?\\b.*)'; | ||
var implicitObjectReturn = '(\\s?=>\\s?\\(\\{)'; | ||
var matcher = new RegExp([startsWithReturn, endsWithReturn, implicitObjectReturn, implicitReturn].join('|'), 'gim'); | ||
var positiveTest = (flattenedSource.match(matcher) || []).length > 0; | ||
var negativeTest = (flattenedSource.match(/(\{.*\{.*return)/gim) || []).length > 0 && (flattenedSource.match(/(return)/gim) || []).length < 2; | ||
if (JSON.stringify(jsdocTags) === '[]' && positiveTest && !negativeTest) { | ||
report('Missing JSDoc @' + targetTagName + ' declaration.'); | ||
@@ -29,0 +38,0 @@ } |
@@ -63,3 +63,3 @@ { | ||
}, | ||
"version": "4.0.1" | ||
"version": "4.1.0" | ||
} |
289
README.md
@@ -36,2 +36,3 @@ <a name="eslint-plugin-jsdoc"></a> | ||
* [`require-returns-type`](#eslint-plugin-jsdoc-rules-require-returns-type) | ||
* [`require-returns-check`](#eslint-plugin-jsdoc-rules-require-returns-check) | ||
* [`require-returns`](#eslint-plugin-jsdoc-rules-require-returns) | ||
@@ -62,2 +63,3 @@ * [`valid-types`](#eslint-plugin-jsdoc-rules-valid-types) | ||
| [`require-returns`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-returns) | [`requireReturn`](https://github.com/jscs-dev/jscs-jsdoc#requirereturn) | | ||
| [`require-returns-check`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-returns-check) | [`requireReturn`](https://github.com/jscs-dev/jscs-jsdoc#requirereturncheck) | | ||
| [`require-returns-description`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-returns-description) | [`requireReturnDescription`](https://github.com/jscs-dev/jscs-jsdoc#requirereturndescription) | | ||
@@ -122,2 +124,3 @@ | [`require-returns-type`](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-require-returns-type) | [`requireReturnTypes`](https://github.com/jscs-dev/jscs-jsdoc#requirereturntypes) | | ||
"jsdoc/require-returns": 1, | ||
"jsdoc/require-returns-check": 1, | ||
"jsdoc/require-returns-description": 1, | ||
@@ -382,3 +385,3 @@ "jsdoc/require-returns-type": 1, | ||
// Settings: {"jsdoc":{"baseConfig":{"rules":{"no-undef":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":true}} | ||
// Message: @example error (semi): Extra semicolon. | ||
// Message: @example error (no-undef): 'quux' is not defined. | ||
@@ -2204,6 +2207,6 @@ /** | ||
<a name="eslint-plugin-jsdoc-rules-require-returns"></a> | ||
### <code>require-returns</code> | ||
<a name="eslint-plugin-jsdoc-rules-require-returns-check"></a> | ||
### <code>require-returns-check</code> | ||
Requires returns are documented. | ||
Checks if the return expression exists in function body and in the comment. | ||
@@ -2219,3 +2222,3 @@ ||| | ||
/** | ||
* | ||
* @returns | ||
*/ | ||
@@ -2225,6 +2228,6 @@ function quux (foo) { | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
// Message: Present JSDoc @returns declaration but not available return expression in function. | ||
/** | ||
* | ||
* @return | ||
*/ | ||
@@ -2234,96 +2237,4 @@ function quux (foo) { | ||
} | ||
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}} | ||
// Message: Missing JSDoc @arg "foo" declaration. | ||
/** | ||
* @param foo | ||
*/ | ||
function quux (foo, bar) { | ||
} | ||
// Message: Missing JSDoc @param "bar" declaration. | ||
/** | ||
* @override | ||
*/ | ||
function quux (foo) { | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @implements | ||
*/ | ||
function quux (foo) { | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @augments | ||
*/ | ||
function quux (foo) { | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @extends | ||
*/ | ||
function quux (foo) { | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @override | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @implements | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @augments | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
/** | ||
* @extends | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Message: Missing JSDoc @param "foo" declaration. | ||
// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}} | ||
// Message: Present JSDoc @return declaration but not available return expression in function. | ||
```` | ||
@@ -2335,186 +2246,82 @@ | ||
/** | ||
* @param foo | ||
* @returns Foo. | ||
*/ | ||
function quux (foo) { | ||
function quux () { | ||
return foo; | ||
} | ||
/** | ||
* @inheritdoc | ||
* @returns {void} Foo. | ||
*/ | ||
function quux (foo) { | ||
function quux () { | ||
return foo; | ||
} | ||
/** | ||
* @arg foo | ||
* @returns {undefined} Foo. | ||
*/ | ||
function quux (foo) { | ||
function quux () { | ||
return foo; | ||
} | ||
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}} | ||
/** | ||
* @override | ||
* @param foo | ||
* | ||
*/ | ||
function quux (foo) { | ||
function quux () { | ||
} | ||
```` | ||
/** | ||
* @override | ||
*/ | ||
function quux (foo) { | ||
} | ||
// Settings: {"jsdoc":{"allowOverrideWithoutParam":true}} | ||
<a name="eslint-plugin-jsdoc-rules-require-returns"></a> | ||
### <code>require-returns</code> | ||
/** | ||
* @implements | ||
*/ | ||
function quux (foo) { | ||
Requires returns are documented. | ||
} | ||
// Settings: {"jsdoc":{"allowImplementsWithoutParam":true}} | ||
||| | ||
|---|---| | ||
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`| | ||
|Tags|`returns`| | ||
/** | ||
* @implements | ||
* @param foo | ||
*/ | ||
function quux (foo) { | ||
The following patterns are considered problems: | ||
} | ||
````js | ||
/** | ||
* @augments | ||
* | ||
*/ | ||
function quux (foo) { | ||
return foo; | ||
} | ||
// Settings: {"jsdoc":{"allowAugmentsExtendsWithoutParam":true}} | ||
// Message: Missing JSDoc @returns declaration. | ||
/** | ||
* @augments | ||
* @param foo | ||
* | ||
*/ | ||
function quux (foo) { | ||
return foo; | ||
} | ||
// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}} | ||
// Message: Missing JSDoc @return declaration. | ||
```` | ||
/** | ||
* @extends | ||
*/ | ||
function quux (foo) { | ||
The following patterns are not considered problems: | ||
} | ||
// Settings: {"jsdoc":{"allowAugmentsExtendsWithoutParam":true}} | ||
````js | ||
/** | ||
* @extends | ||
* @param foo | ||
* @returns Foo. | ||
*/ | ||
function quux (foo) { | ||
function quux () { | ||
return foo; | ||
} | ||
/** | ||
* @override | ||
* | ||
*/ | ||
class A { | ||
/** | ||
* @param foo | ||
*/ | ||
quux (foo) { | ||
} | ||
function quux () { | ||
} | ||
/** | ||
* @override | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Settings: {"jsdoc":{"allowOverrideWithoutParam":true}} | ||
/** | ||
* @implements | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Settings: {"jsdoc":{"allowImplementsWithoutParam":true}} | ||
/** | ||
* @implements | ||
*/ | ||
class A { | ||
/** | ||
* @param foo | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
/** | ||
* @augments | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Settings: {"jsdoc":{"allowAugmentsExtendsWithoutParam":true}} | ||
/** | ||
* @augments | ||
*/ | ||
class A { | ||
/** | ||
* @param foo | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
/** | ||
* @extends | ||
*/ | ||
class A { | ||
/** | ||
* | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
// Settings: {"jsdoc":{"allowAugmentsExtendsWithoutParam":true}} | ||
/** | ||
* @extends | ||
*/ | ||
class A { | ||
/** | ||
* @param foo | ||
*/ | ||
quux (foo) { | ||
} | ||
} | ||
```` | ||
@@ -2521,0 +2328,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
206330
1331
2369