GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(`ts-method-signature-style`): keep `?` when converting between fu… · gajus/eslint-plugin-jsdoc@a4040aa

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/rules
    • ts-method-signature-style.md
  • src/rules
    • tsMethodSignatureStyle.js
  • test/rules/assertions
    • tsMethodSignatureStyle.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/rules/ts-method-signature-style.md‎

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 numberDiff line numberDiff line change
@@ -123,6 +123,40 @@ The following patterns are considered problems:
123123
*/
124124
// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"]
125125
// 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.
126160
````
127161

128162

@@ -143,9 +177,8 @@ The following patterns are not considered problems:
143177

144178
/**
145179
* @param {{
146-
* optionalFunc?: (arg: string) => number,
147180
* readonly readonlyFunc: (arg: string) => number,
148-
* optionalOverloads?: ((arg: string) => number) & ((arg: number) => string)
181+
* readonly readonlyOverloads: ((arg: string) => number) & ((arg: number) => string)
149182
* }} someName
150183
*/
151184
// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"]
Collapse file

‎src/rules/tsMethodSignatureStyle.js‎

Copy file name to clipboardExpand all lines: src/rules/tsMethodSignatureStyle.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export default iterateJsdoc(({
5151
break;
5252
}
5353

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)
5656
if (parentNode?.type === 'JsdocTypeObjectField' &&
5757
typeof parentNode.key === 'string' &&
58-
!parentNode.optional && !parentNode.readonly
58+
!parentNode.readonly
5959
) {
6060
utils.reportJSDoc(
6161
'Found function property; prefer method signature.',
@@ -83,6 +83,7 @@ export default iterateJsdoc(({
8383
quote: objectField.meta.quote,
8484
},
8585
name: /** @type {string} */ (objectField.key),
86+
optional: objectField.optional,
8687
parameters: nde.parameters,
8788
returnType: /** @type {import('jsdoc-type-pratt-parser').RootResult} */ (
8889
nde.returnType
@@ -105,8 +106,6 @@ export default iterateJsdoc(({
105106
// @ts-expect-error Our own added API
106107
typeof parentNode.parentNode.parentNode.key === 'string' &&
107108
// @ts-expect-error Our own added API
108-
!parentNode.parentNode.parentNode.optional &&
109-
// @ts-expect-error Our own added API
110109
!parentNode.parentNode.parentNode.readonly
111110
) {
112111
// @ts-expect-error Our own added API
@@ -130,6 +129,7 @@ export default iterateJsdoc(({
130129
quote: objectField.meta.quote,
131130
},
132131
name: /** @type {string} */ (objectField.key),
132+
optional: objectField.optional,
133133
parameters: func.parameters,
134134
returnType: /** @type {import('jsdoc-type-pratt-parser').RootResult} */ (
135135
func.returnType
@@ -233,7 +233,7 @@ export default iterateJsdoc(({
233233
object.elements[idx] = /** @type {import('jsdoc-type-pratt-parser').ObjectFieldResult} */ ({
234234
key: nde.name,
235235
meta: nde.meta,
236-
optional: false,
236+
optional: nde.optional === true,
237237
readonly: false,
238238
right: funcs[0],
239239
type: 'JsdocTypeObjectField',
@@ -246,7 +246,7 @@ export default iterateJsdoc(({
246246
object.elements[idx] = {
247247
key: nde.name,
248248
meta: nde.meta,
249-
optional: false,
249+
optional: nde.optional === true,
250250
readonly: false,
251251
right: {
252252
elements: funcs.map((func) => {
Collapse file

‎test/rules/assertions/tsMethodSignatureStyle.js‎

Copy file name to clipboardExpand all lines: test/rules/assertions/tsMethodSignatureStyle.js
+102-2Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,107 @@ export default {
259259
*/
260260
`,
261261
},
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+
},
262363
],
263364
valid: [
264365
{
@@ -277,9 +378,8 @@ export default {
277378
code: `
278379
/**
279380
* @param {{
280-
* optionalFunc?: (arg: string) => number,
281381
* readonly readonlyFunc: (arg: string) => number,
282-
* optionalOverloads?: ((arg: string) => number) & ((arg: number) => string)
382+
* readonly readonlyOverloads: ((arg: string) => number) & ((arg: number) => string)
283383
* }} someName
284384
*/
285385
`,

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.