Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(check-values): @throws must not be empty #481

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .README/rules/check-values.md
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -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.

<a name="eslint-plugin-jsdoc-rules-check-values-options-7"></a>
#### Options
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) {

}
````


Expand Down
11 changes: 11 additions & 0 deletions src/rules/checkValues.js
Expand Up @@ -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: {
Expand Down
26 changes: 26 additions & 0 deletions test/rules/assertions/checkValues.js
Expand Up @@ -206,6 +206,22 @@ export default {
},
],
},
{
code: `
/**
* @throws
*/
function quux (foo) {

}
`,
errors: [
{
line: 3,
message: 'Missing JSDoc @throws.',
},
],
},
],
valid: [
{
Expand Down Expand Up @@ -350,5 +366,15 @@ export default {
},
],
},
{
code: `
/**
* @throws {DivideByZero} Argument x must be non-zero.
*/
function quux (foo) {

}
`,
},
],
};