|
| 1 | +<a name="user-content-ts-method-signature-style"></a> |
| 2 | +<a name="ts-method-signature-style"></a> |
| 3 | +# <code>ts-method-signature-style</code> |
| 4 | + |
| 5 | +Inspired by `typescript-eslint`'s [method-signature-style](https://typescript-eslint.io/rules/method-signature-style/) rule. |
| 6 | + |
| 7 | +See that rule for the rationale behind preferring the function |
| 8 | +property. |
| 9 | + |
| 10 | +<a name="user-content-ts-method-signature-style-options"></a> |
| 11 | +<a name="ts-method-signature-style-options"></a> |
| 12 | +## Options |
| 13 | + |
| 14 | +The first option is a string with the following possible values: "method", "property". |
| 15 | + |
| 16 | + |
| 17 | +The next option is an object with the following properties. |
| 18 | + |
| 19 | +<a name="user-content-ts-method-signature-style-options-enablefixer"></a> |
| 20 | +<a name="ts-method-signature-style-options-enablefixer"></a> |
| 21 | +### <code>enableFixer</code> |
| 22 | + |
| 23 | +Whether to enable the fixer. Defaults to `true`. |
| 24 | + |
| 25 | + |
| 26 | +||| |
| 27 | +|---|---| |
| 28 | +|Context|everywhere| |
| 29 | +|Tags|``| |
| 30 | +|Recommended|false| |
| 31 | +|Settings|| |
| 32 | +|Options|string ("method", "property") followed by object with `enableFixer`| |
| 33 | + |
| 34 | +<a name="user-content-ts-method-signature-style-failing-examples"></a> |
| 35 | +<a name="ts-method-signature-style-failing-examples"></a> |
| 36 | +## Failing examples |
| 37 | + |
| 38 | +The following patterns are considered problems: |
| 39 | + |
| 40 | +````ts |
| 41 | +/** |
| 42 | + * @param {{ |
| 43 | + * func(arg: string): number |
| 44 | + * }} someName |
| 45 | + */ |
| 46 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "property"] |
| 47 | +// Message: Found method signature; prefer function property. |
| 48 | + |
| 49 | +/** |
| 50 | + * @param {{ |
| 51 | + * func(arg: string): number |
| 52 | + * }} someName |
| 53 | + */ |
| 54 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "property",{"enableFixer":false}] |
| 55 | +// Message: Found method signature; prefer function property. |
| 56 | + |
| 57 | +/** |
| 58 | + * @param {{ |
| 59 | + * func(arg: number): void |
| 60 | + * func(arg: string): void |
| 61 | + * func(arg: boolean): void |
| 62 | + * }} someName |
| 63 | + */ |
| 64 | +// Message: Found method signature; prefer function property. |
| 65 | + |
| 66 | +/** |
| 67 | + * @param {{ |
| 68 | + * func: (arg: string) => number |
| 69 | + * }} someName |
| 70 | + */ |
| 71 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] |
| 72 | +// Message: Found function property; prefer method signature. |
| 73 | + |
| 74 | +/** |
| 75 | + * @param {{ |
| 76 | + * func: (arg: string) => number |
| 77 | + * }} someName |
| 78 | + */ |
| 79 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method",{"enableFixer":false}] |
| 80 | +// Message: Found function property; prefer method signature. |
| 81 | + |
| 82 | +/** |
| 83 | + * @type {{ |
| 84 | + * func: ((arg: number) => void) & |
| 85 | + * ((arg: string) => void) & |
| 86 | + * ((arg: boolean) => void) |
| 87 | + * }} |
| 88 | + */ |
| 89 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] |
| 90 | +// Message: Found function property; prefer method signature. |
| 91 | + |
| 92 | +/** |
| 93 | + * @param {{ |
| 94 | + * func: ((arg: number) => void) & |
| 95 | + * ((arg: string) => void) & |
| 96 | + * ((arg: boolean) => void) |
| 97 | + * }} someName |
| 98 | + */ |
| 99 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method",{"enableFixer":false}] |
| 100 | +// Message: Found function property; prefer method signature. |
| 101 | + |
| 102 | +/** |
| 103 | + * @param {{ |
| 104 | + * "func"(arg: string): number |
| 105 | + * }} someName |
| 106 | + */ |
| 107 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "property"] |
| 108 | +// Message: Found method signature; prefer function property. |
| 109 | + |
| 110 | +/** |
| 111 | + * @param {{ |
| 112 | + * 'func': (arg: string) => number |
| 113 | + * }} someName |
| 114 | + */ |
| 115 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] |
| 116 | +// Message: Found function property; prefer method signature. |
| 117 | + |
| 118 | +/** @type {{ |
| 119 | + * func: ((arg: number) => void) & |
| 120 | + * ((arg: string) => void) & |
| 121 | + * ((arg: boolean) => void) |
| 122 | + * }} |
| 123 | + */ |
| 124 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] |
| 125 | +// Message: Found function property; prefer method signature. |
| 126 | +```` |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +<a name="user-content-ts-method-signature-style-passing-examples"></a> |
| 131 | +<a name="ts-method-signature-style-passing-examples"></a> |
| 132 | +## Passing examples |
| 133 | + |
| 134 | +The following patterns are not considered problems: |
| 135 | + |
| 136 | +````ts |
| 137 | +/** |
| 138 | + * @param {{ |
| 139 | + * func: (arg: string) => number |
| 140 | + * }} |
| 141 | + */ |
| 142 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "property"] |
| 143 | + |
| 144 | +/** |
| 145 | + * @param {{ |
| 146 | + * func: ((arg: number) => void) & |
| 147 | + * ((arg: string) => void) & |
| 148 | + * ((arg: boolean) => void) |
| 149 | + * }} |
| 150 | + */ |
| 151 | + |
| 152 | +/** |
| 153 | + * @param {abc<} |
| 154 | + */ |
| 155 | + |
| 156 | +/** |
| 157 | + * @param {{ |
| 158 | + * func: ((arg: number) => void) & (SomeType) |
| 159 | + * }} |
| 160 | + */ |
| 161 | +// "jsdoc/ts-method-signature-style": ["error"|"warn", "method"] |
| 162 | +```` |
| 163 | + |
0 commit comments