GeezerVison is showing github.com — fix(`ts-method-signature-style`): keep `?` when converting between fu… · gajus/eslint-plugin-jsdoc@a4040aa
File treeExpand 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 +35-2Lines changed: 35 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -123,6 +123,40 @@ The following patterns are considered problems: | 123 | 123 | */ | 124 | 124 | // "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] | 125 | 125 | // Message: Found function property; prefer method signature. | | 126 | + | | 127 | +/** | | 128 | + * @param {{ | | 129 | + * optionalFunc?: (arg: string) => number | | 130 | + * }} someName | | 131 | + */ | | 132 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] | | 133 | +// Message: Found function property; prefer method signature. | | 134 | + | | 135 | +/** | | 136 | + * @type {{ | | 137 | + * func?: ((arg: number) => void) & | | 138 | + * ((arg: string) => void) | | 139 | + * }} | | 140 | + */ | | 141 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] | | 142 | +// Message: Found function property; prefer method signature. | | 143 | + | | 144 | +/** | | 145 | + * @param {{ | | 146 | + * optionalMethod?(arg: string): number | | 147 | + * }} someName | | 148 | + */ | | 149 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "property"] | | 150 | +// Message: Found method signature; prefer function property. | | 151 | + | | 152 | +/** | | 153 | + * @param {{ | | 154 | + * func?(arg: number): void | | 155 | + * func?(arg: string): void | | 156 | + * }} someName | | 157 | + */ | | 158 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "property"] | | 159 | +// Message: Found method signature; prefer function property. | 126 | 160 | ```` | 127 | 161 |
| 128 | 162 |
| @@ -143,9 +177,8 @@ The following patterns are not considered problems: | 143 | 177 |
| 144 | 178 | /** | 145 | 179 | * @param {{ | 146 | | - * optionalFunc?: (arg: string) => number, | 147 | 180 | * readonly readonlyFunc: (arg: string) => number, | 148 | | - * optionalOverloads?: ((arg: string) => number) & ((arg: number) => string) | | 181 | + * readonly readonlyOverloads: ((arg: string) => number) & ((arg: number) => string) | 149 | 182 | * }} someName | 150 | 183 | */ | 151 | 184 | // "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] | |
Collapse file Copy file name to clipboardExpand all lines: src/rules/tsMethodSignatureStyle.js +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,11 +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 | + // A `readonly` function property has no method signature | | 55 | + // equivalent (`readonly` is not allowed on methods) | 56 | 56 | if (parentNode?.type === 'JsdocTypeObjectField' && | 57 | 57 | typeof parentNode.key === 'string' && | 58 | | - !parentNode.optional && !parentNode.readonly | | 58 | + !parentNode.readonly | 59 | 59 | ) { | 60 | 60 | utils.reportJSDoc( | 61 | 61 | 'Found function property; prefer method signature.', | @@ -83,6 +83,7 @@ export default iterateJsdoc(({ | 83 | 83 | quote: objectField.meta.quote, | 84 | 84 | }, | 85 | 85 | name: /** @type {string} */ (objectField.key), | | 86 | + optional: objectField.optional, | 86 | 87 | parameters: nde.parameters, | 87 | 88 | returnType: /** @type {import('jsdoc-type-pratt-parser').RootResult} */ ( | 88 | 89 | nde.returnType | @@ -105,8 +106,6 @@ export default iterateJsdoc(({ | 105 | 106 | // @ts-expect-error Our own added API | 106 | 107 | typeof parentNode.parentNode.parentNode.key === 'string' && | 107 | 108 | // @ts-expect-error Our own added API | 108 | | - !parentNode.parentNode.parentNode.optional && | 109 | | - // @ts-expect-error Our own added API | 110 | 109 | !parentNode.parentNode.parentNode.readonly | 111 | 110 | ) { | 112 | 111 | // @ts-expect-error Our own added API | @@ -130,6 +129,7 @@ export default iterateJsdoc(({ | 130 | 129 | quote: objectField.meta.quote, | 131 | 130 | }, | 132 | 131 | name: /** @type {string} */ (objectField.key), | | 132 | + optional: objectField.optional, | 133 | 133 | parameters: func.parameters, | 134 | 134 | returnType: /** @type {import('jsdoc-type-pratt-parser').RootResult} */ ( | 135 | 135 | func.returnType | @@ -233,7 +233,7 @@ export default iterateJsdoc(({ | 233 | 233 | object.elements[idx] = /** @type {import('jsdoc-type-pratt-parser').ObjectFieldResult} */ ({ | 234 | 234 | key: nde.name, | 235 | 235 | meta: nde.meta, | 236 | | - optional: false, | | 236 | + optional: nde.optional === true, | 237 | 237 | readonly: false, | 238 | 238 | right: funcs[0], | 239 | 239 | type: 'JsdocTypeObjectField', | @@ -246,7 +246,7 @@ export default iterateJsdoc(({ | 246 | 246 | object.elements[idx] = { | 247 | 247 | key: nde.name, | 248 | 248 | meta: nde.meta, | 249 | | - optional: false, | | 249 | + optional: nde.optional === true, | 250 | 250 | readonly: false, | 251 | 251 | right: { | 252 | 252 | elements: funcs.map((func) => { | |
Collapse file Copy file name to clipboardExpand all lines: test/rules/assertions/tsMethodSignatureStyle.js +102-2Lines changed: 102 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -259,6 +259,107 @@ export default { | 259 | 259 | */ | 260 | 260 | `, | 261 | 261 | }, | | 262 | + { | | 263 | + code: ` | | 264 | + /** | | 265 | + * @param {{ | | 266 | + * optionalFunc?: (arg: string) => number | | 267 | + * }} someName | | 268 | + */ | | 269 | + `, | | 270 | + errors: [ | | 271 | + { | | 272 | + line: 3, | | 273 | + message: 'Found function property; prefer method signature.', | | 274 | + }, | | 275 | + ], | | 276 | + options: [ | | 277 | + 'method', | | 278 | + ], | | 279 | + output: ` | | 280 | + /** | | 281 | + * @param {{optionalFunc?(arg: string): number}} someName | | 282 | + */ | | 283 | + `, | | 284 | + }, | | 285 | + { | | 286 | + code: ` | | 287 | + /** | | 288 | + * @type {{ | | 289 | + * func?: ((arg: number) => void) & | | 290 | + * ((arg: string) => void) | | 291 | + * }} | | 292 | + */ | | 293 | + `, | | 294 | + errors: [ | | 295 | + { | | 296 | + line: 3, | | 297 | + message: 'Found function property; prefer method signature.', | | 298 | + }, | | 299 | + { | | 300 | + line: 3, | | 301 | + message: 'Found function property; prefer method signature.', | | 302 | + }, | | 303 | + ], | | 304 | + options: [ | | 305 | + 'method', | | 306 | + ], | | 307 | + output: ` | | 308 | + /** | | 309 | + * @type {{ | | 310 | + * func?(arg: number): void | | 311 | + * func?(arg: string): void | | 312 | + * }} | | 313 | + */ | | 314 | + `, | | 315 | + }, | | 316 | + { | | 317 | + code: ` | | 318 | + /** | | 319 | + * @param {{ | | 320 | + * optionalMethod?(arg: string): number | | 321 | + * }} someName | | 322 | + */ | | 323 | + `, | | 324 | + errors: [ | | 325 | + { | | 326 | + line: 3, | | 327 | + message: 'Found method signature; prefer function property.', | | 328 | + }, | | 329 | + ], | | 330 | + options: [ | | 331 | + 'property', | | 332 | + ], | | 333 | + output: ` | | 334 | + /** | | 335 | + * @param {{optionalMethod?: (arg: string) => number}} someName | | 336 | + */ | | 337 | + `, | | 338 | + }, | | 339 | + { | | 340 | + code: ` | | 341 | + /** | | 342 | + * @param {{ | | 343 | + * func?(arg: number): void | | 344 | + * func?(arg: string): void | | 345 | + * }} someName | | 346 | + */ | | 347 | + `, | | 348 | + errors: [ | | 349 | + { | | 350 | + line: 3, | | 351 | + message: 'Found method signature; prefer function property.', | | 352 | + }, | | 353 | + ], | | 354 | + options: [ | | 355 | + 'property', | | 356 | + ], | | 357 | + output: ` | | 358 | + /** | | 359 | + * @param {{func?: ((arg: number) => void) & ((arg: string) => void)}} someName | | 360 | + */ | | 361 | + `, | | 362 | + }, | 262 | 363 | ], | 263 | 364 | valid: [ | 264 | 365 | { | @@ -277,9 +378,8 @@ export default { | 277 | 378 | code: ` | 278 | 379 | /** | 279 | 380 | * @param {{ | 280 | | - * optionalFunc?: (arg: string) => number, | 281 | 381 | * readonly readonlyFunc: (arg: string) => number, | 282 | | - * optionalOverloads?: ((arg: string) => number) & ((arg: number) => string) | | 382 | + * readonly readonlyOverloads: ((arg: string) => number) & ((arg: number) => string) | 283 | 383 | * }} someName | 284 | 384 | */ | 285 | 385 | `, | |
|