Skip to content

Commit 353bd57

Browse files
committed
feat(require-jsdoc): add on-by-default skipInterveningOverloadedDeclarations option; fixes #1434
BREAKING CHANGE: Now requires `skipInterveningOverloadedDeclarations: true` option to get behavior of checking at the top of overloaded functions from #1369
1 parent e51a7a8 commit 353bd57

File tree

8 files changed

+231
-29
lines changed

8 files changed

+231
-29
lines changed

.README/rules/require-jsdoc.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,20 @@ apply to any context; see `contexts` for line counts per context.
113113
An optional message to add to the inserted JSDoc block. Defaults to the
114114
empty string.
115115

116+
### `skipInterveningOverloadedDeclarations`
117+
118+
If `true`, will skip above uncommented overloaded functions to check
119+
for a comment block (e.g., at the top of a set of overloaded functions).
120+
Defaults to `true`.
121+
116122
## Context and settings
117123

118124
|||
119125
|---|---|
120126
|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
121127
|Tags|N/A|
122128
|Recommended|true|
123-
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`, `enableFixer`, `minLineCount`, `fixerMessage`|
129+
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`, `enableFixer`, `minLineCount`, `fixerMessage`, `skipInterveningOverloadedDeclarations`|
124130

125131
## Failing examples
126132

docs/rules/require-jsdoc.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [`enableFixer`](#user-content-require-jsdoc-options-enablefixer)
1616
* [`minLineCount`](#user-content-require-jsdoc-options-minlinecount)
1717
* [`fixerMessage`](#user-content-require-jsdoc-options-fixermessage)
18+
* [`skipInterveningOverloadedDeclarations`](#user-content-require-jsdoc-options-skipinterveningoverloadeddeclarations)
1819
* [Context and settings](#user-content-require-jsdoc-context-and-settings)
1920
* [Failing examples](#user-content-require-jsdoc-failing-examples)
2021
* [Passing examples](#user-content-require-jsdoc-passing-examples)
@@ -157,6 +158,14 @@ apply to any context; see `contexts` for line counts per context.
157158
An optional message to add to the inserted JSDoc block. Defaults to the
158159
empty string.
159160

161+
<a name="user-content-require-jsdoc-options-skipinterveningoverloadeddeclarations"></a>
162+
<a name="require-jsdoc-options-skipinterveningoverloadeddeclarations"></a>
163+
### <code>skipInterveningOverloadedDeclarations</code>
164+
165+
If `true`, will skip above uncommented overloaded functions to check
166+
for a comment block (e.g., at the top of a set of overloaded functions).
167+
Defaults to `true`.
168+
160169
<a name="user-content-require-jsdoc-context-and-settings"></a>
161170
<a name="require-jsdoc-context-and-settings"></a>
162171
## Context and settings
@@ -166,7 +175,7 @@ empty string.
166175
|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
167176
|Tags|N/A|
168177
|Recommended|true|
169-
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`, `enableFixer`, `minLineCount`, `fixerMessage`|
178+
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`, `enableFixer`, `minLineCount`, `fixerMessage`, `skipInterveningOverloadedDeclarations`|
170179

171180
<a name="user-content-require-jsdoc-failing-examples"></a>
172181
<a name="require-jsdoc-failing-examples"></a>
@@ -1041,6 +1050,32 @@ export class B implements A, B {
10411050
}
10421051
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition"]}]
10431052
// Message: Missing JSDoc comment.
1053+
1054+
/**
1055+
* Test function with param.
1056+
* @param foo - Test param.
1057+
*/
1058+
function myFunction(foo: string): void;
1059+
/**
1060+
* Test function without param.
1061+
*/
1062+
function myFunction(): void;
1063+
function myFunction(foo?: string) {}
1064+
// "jsdoc/require-jsdoc": ["error"|"warn", {"skipInterveningOverloadedDeclarations":false}]
1065+
// Message: Missing JSDoc comment.
1066+
1067+
/**
1068+
* Test function without param.
1069+
*/
1070+
function myFunction(): void;
1071+
/**
1072+
* Test function with param.
1073+
* @param foo - Test param.
1074+
*/
1075+
function myFunction(foo: string): void;
1076+
function myFunction(foo?: string) {}
1077+
// "jsdoc/require-jsdoc": ["error"|"warn", {"skipInterveningOverloadedDeclarations":false}]
1078+
// Message: Missing JSDoc comment.
10441079
````
10451080

10461081

@@ -1944,6 +1979,7 @@ export function arrayMap<Target, Source extends Array<unknown>>(data: Source, ca
19441979
export function arrayMap<Target, Source extends AnyArrayType>(data: Source, callback: MapCallback<Target, Source>): AnyArrayType<Target> {
19451980
return data.map(callback);
19461981
}
1982+
// "jsdoc/require-jsdoc": ["error"|"warn", {"skipInterveningOverloadedDeclarations":true}]
19471983

19481984
export interface A {
19491985
a: string;
@@ -1960,5 +1996,16 @@ export class B implements A {
19601996
}
19611997
}
19621998
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition"]}]
1999+
2000+
/**
2001+
* Test function with param.
2002+
* @param foo - Test param.
2003+
*/
2004+
function myFunction(foo: string): void;
2005+
/**
2006+
* Test function without param.
2007+
*/
2008+
function myFunction(): void;
2009+
function myFunction(foo?: string) {}
19632010
````
19642011

docs/rules/require-param.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,5 +1842,16 @@ const inner = (c: number, d: string): void => {
18421842
*/
18431843
function quux (a, b) {}
18441844
// "jsdoc/require-param": ["error"|"warn", {"ignoreWhenAllParamsMissing":true}]
1845+
1846+
/**
1847+
* Test function with param.
1848+
* @param foo - Test param.
1849+
*/
1850+
function myFunction(foo: string): void;
1851+
/**
1852+
* Test function without param.
1853+
*/
1854+
function myFunction(): void;
1855+
function myFunction(foo?: string) {}
18451856
````
18461857

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"@es-joy/jsdoccomment": "~0.53.0",
8+
"@es-joy/jsdoccomment": "~0.54.0",
99
"are-docs-informative": "^0.0.2",
1010
"comment-parser": "1.4.1",
1111
"debug": "^4.4.1",
@@ -40,7 +40,7 @@
4040
"@types/json-schema": "^7.0.15",
4141
"@types/lodash.defaultsdeep": "^4.6.9",
4242
"@types/mocha": "^10.0.10",
43-
"@types/node": "^24.2.1",
43+
"@types/node": "^24.3.0",
4444
"@types/semver": "^7.7.0",
4545
"@types/spdx-expression-parse": "^3.0.5",
4646
"@typescript-eslint/types": "^8.39.1",

pnpm-lock.yaml

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rules/requireJsdoc.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ const OPTIONS_SCHEMA = {
169169
},
170170
type: 'object',
171171
},
172+
skipInterveningOverloadedDeclarations: {
173+
default: true,
174+
type: 'boolean',
175+
},
172176
},
173177
type: 'object',
174178
};
@@ -302,6 +306,7 @@ const getOption = (context, baseObject, option, key) => {
302306
* enableFixer: boolean,
303307
* exemptEmptyConstructors: boolean,
304308
* exemptEmptyFunctions: boolean,
309+
* skipInterveningOverloadedDeclarations: boolean,
305310
* fixerMessage: string,
306311
* minLineCount: undefined|import('../iterateJsdoc.js').Integer,
307312
* publicOnly: boolean|{[key: string]: boolean|undefined}
@@ -317,6 +322,7 @@ const getOptions = (context, settings) => {
317322
fixerMessage = '',
318323
minLineCount = undefined,
319324
publicOnly,
325+
skipInterveningOverloadedDeclarations = true,
320326
} = context.options[0] || {};
321327

322328
return {
@@ -386,6 +392,7 @@ const getOptions = (context, settings) => {
386392
/** @type {import('json-schema').JSONSchema4Object} */
387393
(OPTIONS_SCHEMA.properties).require,
388394
),
395+
skipInterveningOverloadedDeclarations,
389396
};
390397
};
391398

@@ -411,6 +418,7 @@ export default {
411418
fixerMessage,
412419
minLineCount,
413420
require: requireOption,
421+
skipInterveningOverloadedDeclarations,
414422
} = opts;
415423

416424
const publicOnly =
@@ -476,7 +484,11 @@ export default {
476484
}
477485
}
478486

479-
const jsDocNode = getJSDocComment(sourceCode, node, settings);
487+
const jsDocNode = getJSDocComment(
488+
sourceCode, node, settings, {
489+
checkOverloads: skipInterveningOverloadedDeclarations,
490+
},
491+
);
480492

481493
if (jsDocNode) {
482494
return;

0 commit comments

Comments
 (0)