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(require-param): add ignoreWhenAllParamsMissing option #1318

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .README/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ documentation). Defaults to `true`.
Set to `true` if you wish to expect documentation of properties on objects
supplied as default values. Defaults to `false`.

### `ignoreWhenAllParamsMissing`

Set to `true` to ignore reporting when all params are missing. Defaults to
`false`.

## Context and settings

| | |
Expand All @@ -377,7 +382,7 @@ supplied as default values. Defaults to `false`.
| Tags | `param` |
| Aliases | `arg`, `argument` |
|Recommended | true|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `ignoreWhenAllParamsMissing`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Settings | `ignoreReplacesDocs`, `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|

## Failing examples
Expand Down
24 changes: 23 additions & 1 deletion docs/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [`checkDestructured`](#user-content-require-param-options-checkdestructured)
* [`checkDestructuredRoots`](#user-content-require-param-options-checkdestructuredroots)
* [`useDefaultObjectProperties`](#user-content-require-param-options-usedefaultobjectproperties)
* [`ignoreWhenAllParamsMissing`](#user-content-require-param-options-ignorewhenallparamsmissing)
* [Context and settings](#user-content-require-param-context-and-settings)
* [Failing examples](#user-content-require-param-failing-examples)
* [Passing examples](#user-content-require-param-passing-examples)
Expand Down Expand Up @@ -437,6 +438,13 @@ documentation). Defaults to `true`.
Set to `true` if you wish to expect documentation of properties on objects
supplied as default values. Defaults to `false`.

<a name="user-content-require-param-options-ignorewhenallparamsmissing"></a>
<a name="require-param-options-ignorewhenallparamsmissing"></a>
### <code>ignoreWhenAllParamsMissing</code>

Set to `true` to ignore reporting when all params are missing. Defaults to
`false`.

<a name="user-content-require-param-context-and-settings"></a>
<a name="require-param-context-and-settings"></a>
## Context and settings
Expand All @@ -447,7 +455,7 @@ supplied as default values. Defaults to `false`.
| Tags | `param` |
| Aliases | `arg`, `argument` |
|Recommended | true|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `ignoreWhenAllParamsMissing`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Settings | `ignoreReplacesDocs`, `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|

<a name="user-content-require-param-failing-examples"></a>
Expand Down Expand Up @@ -1162,6 +1170,14 @@ class A {
}
}
// Message: Missing JSDoc @param "root1" declaration.

/**
* Some desc.
* @param a
*/
function quux (a, b) {}
// "jsdoc/require-param": ["error"|"warn", {"ignoreWhenAllParamsMissing":true}]
// Message: Missing JSDoc @param "b" declaration.
````


Expand Down Expand Up @@ -1813,5 +1829,11 @@ const inner = (c: number, d: string): void => {
console.log(d);
};
// Settings: {"jsdoc":{"contexts":["VariableDeclaration"]}}

/**
* Some desc.
*/
function quux (a, b) {}
// "jsdoc/require-param": ["error"|"warn", {"ignoreWhenAllParamsMissing":true}]
````

8 changes: 8 additions & 0 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default iterateJsdoc(({
'root',
],
useDefaultObjectProperties = false,
ignoreWhenAllParamsMissing = false,
} = context.options[0] || {};

const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({
Expand All @@ -83,6 +84,10 @@ export default iterateJsdoc(({
* }[]}
*/ (utils.getJsdocTagsDeep(preferredTagName));

if (ignoreWhenAllParamsMissing && !jsdocParameterNames.length) {
return;
}

const shallowJsdocParameterNames = jsdocParameterNames.filter((tag) => {
return !tag.name.includes('.');
}).map((tag, idx) => {
Expand Down Expand Up @@ -571,6 +576,9 @@ export default iterateJsdoc(({
},
type: 'array',
},
ignoreWhenAllParamsMissing: {
type: 'boolean',
},
unnamedRootBase: {
items: {
type: 'string',
Expand Down
40 changes: 40 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,33 @@ export default {
}
`,
},
{
code: `
/**
* Some desc.
* @param a
*/
function quux (a, b) {}
`,
errors: [
{
message: 'Missing JSDoc @param "b" declaration.',
},
],
options: [
{
ignoreWhenAllParamsMissing: true,
}
],
output: `
/**
* Some desc.
* @param a
* @param b
*/
function quux (a, b) {}
`,
},
],
valid: [
{
Expand Down Expand Up @@ -3604,5 +3631,18 @@ export default {
}
},
},
{
code: `
/**
* Some desc.
*/
function quux (a, b) {}
`,
options: [
{
ignoreWhenAllParamsMissing: true,
}
],
},
],
};
Loading