gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.09k stars 157 forks source link

require-throws recursion #1138

Open PatrikTrefil opened 1 year ago

PatrikTrefil commented 1 year ago

Motivation

Currently, we can require @throws tag on functions that have a throw statement directly in their bodies. I think it would be great to take it to the next level and require the @throws tag for all errors that may be thrown by a function. All error handling is an important part of API behavior and should therefore be well documented. This is already done by languages such as Java.

Current behavior

// No error by ESLint :(
/**
 * Description.
 */
function a() {
    b();
}
/**
 * @throws Error - Always throws an error.
 */
function b() {
    throw new Error();
}

Desired behavior

// ESLint error: throws tag required for function a
/**
 * Description.
 */
function a() {
    b();
}
/**
 * @throws Error - Always throws an error.
 */
function b() {
    throw new Error();
}