GeezerVison is showing github.com — fix(`ts-method-signature-style`): do not turn optional or readonly fu… · gajus/eslint-plugin-jsdoc@94952b2
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: docs/rules/ts-method-signature-style.md +9Lines changed: 9 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -141,6 +141,15 @@ The following patterns are not considered problems: |
141 | 141 | */ |
142 | 142 | // "jsdoc/ts-method-signature-style": ["error"|"warn", "property"] |
143 | 143 |
|
| 144 | +/** |
| 145 | + * @param {{ |
| 146 | + * optionalFunc?: (arg: string) => number, |
| 147 | + * readonly readonlyFunc: (arg: string) => number, |
| 148 | + * optionalOverloads?: ((arg: string) => number) & ((arg: number) => string) |
| 149 | + * }} someName |
| 150 | + */ |
| 151 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] |
| 152 | + |
144 | 153 | /** |
145 | 154 | * @param {{ |
146 | 155 | * func: ((arg: number) => void) & |
|
Collapse file
Copy file name to clipboardExpand all lines: src/rules/tsMethodSignatureStyle.js +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,8 +51,11 @@ export default iterateJsdoc(({ |
51 | 51 | break; |
52 | 52 | } |
53 | 53 |
|
| 54 | + // Optional and readonly function properties have no method |
| 55 | + // signature equivalent that keeps their meaning here |
54 | 56 | if (parentNode?.type === 'JsdocTypeObjectField' && |
55 | | - typeof parentNode.key === 'string' |
| 57 | + typeof parentNode.key === 'string' && |
| 58 | + !parentNode.optional && !parentNode.readonly |
56 | 59 | ) { |
57 | 60 | utils.reportJSDoc( |
58 | 61 | 'Found function property; prefer method signature.', |
@@ -100,7 +103,11 @@ export default iterateJsdoc(({ |
100 | 103 | // @ts-expect-error Our own added API |
101 | 104 | parentNode.parentNode.parentNode.type === 'JsdocTypeObjectField' && |
102 | 105 | // @ts-expect-error Our own added API |
103 | | - typeof parentNode.parentNode.parentNode.key === 'string' |
| 106 | + typeof parentNode.parentNode.parentNode.key === 'string' && |
| 107 | + // @ts-expect-error Our own added API |
| 108 | + !parentNode.parentNode.parentNode.optional && |
| 109 | + // @ts-expect-error Our own added API |
| 110 | + !parentNode.parentNode.parentNode.readonly |
104 | 111 | ) { |
105 | 112 | // @ts-expect-error Our own added API |
106 | 113 | const intersection = parentNode.parentNode; |
|
Collapse file
Copy file name to clipboardExpand all lines: test/rules/assertions/tsMethodSignatureStyle.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -273,6 +273,20 @@ export default { |
273 | 273 | 'property', |
274 | 274 | ], |
275 | 275 | }, |
| 276 | + { |
| 277 | + code: ` |
| 278 | + /** |
| 279 | + * @param {{ |
| 280 | + * optionalFunc?: (arg: string) => number, |
| 281 | + * readonly readonlyFunc: (arg: string) => number, |
| 282 | + * optionalOverloads?: ((arg: string) => number) & ((arg: number) => string) |
| 283 | + * }} someName |
| 284 | + */ |
| 285 | + `, |
| 286 | + options: [ |
| 287 | + 'method', |
| 288 | + ], |
| 289 | + }, |
276 | 290 | { |
277 | 291 | code: ` |
278 | 292 | /** |
|