From 8b8abe14a0945bfcd6f6544e7a5607a8f83ed7dc Mon Sep 17 00:00:00 2001 From: Sebastian Busch Date: Wed, 15 Jan 2020 11:14:03 +0100 Subject: [PATCH] @throws requires an value including docs, tests --- .README/rules/check-values.md | 1 + README.md | 16 ++++++++++++++++ src/rules/checkValues.js | 11 +++++++++++ test/rules/assertions/checkValues.js | 26 ++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/.README/rules/check-values.md b/.README/rules/check-values.md index ca0416b91..92a499845 100644 --- a/.README/rules/check-values.md +++ b/.README/rules/check-values.md @@ -10,6 +10,7 @@ This rule checks the values for a handful of tags: 4. `@author` - Checks there is a value present, and if the option `allowedAuthors` is present, ensure that the author value is one of these array items. +5. `@throws` - Checks that there is a value present. #### Options diff --git a/README.md b/README.md index d09675af4..0af304c81 100644 --- a/README.md +++ b/README.md @@ -3742,6 +3742,7 @@ This rule checks the values for a handful of tags: 4. `@author` - Checks there is a value present, and if the option `allowedAuthors` is present, ensure that the author value is one of these array items. +5. `@throws` - Checks that there is a value present. #### Options @@ -3878,6 +3879,14 @@ function quux (foo) { } // Options: [{"allowedAuthors":["Gajus Kuizinas","golopot"]}] // Message: Invalid JSDoc @author: "Brett Zamir"; expected one of Gajus Kuizinas, golopot. + +/** + * @throws + */ +function quux (foo) { + +} +// Message: Missing JSDoc @throws. ```` The following patterns are not considered problems: @@ -3972,6 +3981,13 @@ function quux (foo) { } // Options: [{"allowedAuthors":["Gajus Kuizinas","golopot","Brett Zamir"]}] + +/** + * @throws {DivideByZero} Argument x must be non-zero. + */ +function quux (foo) { + +} ```` diff --git a/src/rules/checkValues.js b/src/rules/checkValues.js index c3e8abe38..0674a702c 100644 --- a/src/rules/checkValues.js +++ b/src/rules/checkValues.js @@ -95,6 +95,17 @@ export default iterateJsdoc(({ } } }); + + utils.forEachPreferredTag('throws', (jsdocParameter, targetTagName) => { + const throws = jsdocParameter.description.trim(); + if (!throws) { + report( + `Missing JSDoc @${targetTagName}.`, + null, + jsdocParameter, + ); + } + }); }, { iterateAllJsdocs: true, meta: { diff --git a/test/rules/assertions/checkValues.js b/test/rules/assertions/checkValues.js index d690e9cb8..e10c4d2e3 100644 --- a/test/rules/assertions/checkValues.js +++ b/test/rules/assertions/checkValues.js @@ -206,6 +206,22 @@ export default { }, ], }, + { + code: ` + /** + * @throws + */ + function quux (foo) { + + } + `, + errors: [ + { + line: 3, + message: 'Missing JSDoc @throws.', + }, + ], + }, ], valid: [ { @@ -350,5 +366,15 @@ export default { }, ], }, + { + code: ` + /** + * @throws {DivideByZero} Argument x must be non-zero. + */ + function quux (foo) { + + } + `, + }, ], };