|
| 1 | +<a name="user-content-require-template"></a> |
| 2 | +<a name="require-template"></a> |
| 3 | +# <code>require-template</code> |
| 4 | + |
| 5 | +Checks to see that `@template` tags are present for any detected type |
| 6 | +parameters. |
| 7 | + |
| 8 | +Currently checks `TSTypeAliasDeclaration` such as: |
| 9 | + |
| 10 | +```ts |
| 11 | +export type Pairs<D, V> = [D, V | undefined]; |
| 12 | +``` |
| 13 | + |
| 14 | +or |
| 15 | + |
| 16 | +```js |
| 17 | +/** |
| 18 | + * @typedef {[D, V | undefined]} Pairs |
| 19 | + */ |
| 20 | +``` |
| 21 | + |
| 22 | +Note that in the latter TypeScript-flavor JavaScript example, there is no way |
| 23 | +for us to firmly distinguish between `D` and `V` as type parameters or as some |
| 24 | +other identifiers, so we use an algorithm that any single capital letters |
| 25 | +are assumed to be templates. |
| 26 | + |
| 27 | +<a name="user-content-require-template-options"></a> |
| 28 | +<a name="require-template-options"></a> |
| 29 | +## Options |
| 30 | + |
| 31 | +<a name="user-content-require-template-options-requireseparatetemplates"></a> |
| 32 | +<a name="require-template-options-requireseparatetemplates"></a> |
| 33 | +### <code>requireSeparateTemplates</code> |
| 34 | + |
| 35 | +Requires that each template have its own separate line, i.e., preventing |
| 36 | +templates of this format: |
| 37 | + |
| 38 | +```js |
| 39 | +/** |
| 40 | + * @template T, U, V |
| 41 | + */ |
| 42 | +``` |
| 43 | + |
| 44 | +Defaults to `false`. |
| 45 | + |
| 46 | +||| |
| 47 | +|---|---| |
| 48 | +|Context|everywhere| |
| 49 | +|Tags|`template`| |
| 50 | +|Recommended|true| |
| 51 | +|Settings|| |
| 52 | +|Options|`requireSeparateTemplates`| |
| 53 | + |
| 54 | +<a name="user-content-require-template-failing-examples"></a> |
| 55 | +<a name="require-template-failing-examples"></a> |
| 56 | +## Failing examples |
| 57 | + |
| 58 | +The following patterns are considered problems: |
| 59 | + |
| 60 | +````js |
| 61 | +/** |
| 62 | + * |
| 63 | + */ |
| 64 | +type Pairs<D, V> = [D, V | undefined]; |
| 65 | +// Message: Missing @template D |
| 66 | + |
| 67 | +/** |
| 68 | + * |
| 69 | + */ |
| 70 | +export type Pairs<D, V> = [D, V | undefined]; |
| 71 | +// Message: Missing @template D |
| 72 | + |
| 73 | +/** |
| 74 | + * @typedef {[D, V | undefined]} Pairs |
| 75 | + */ |
| 76 | +// Message: Missing @template D |
| 77 | + |
| 78 | +/** |
| 79 | + * @typedef {[D, V | undefined]} Pairs |
| 80 | + */ |
| 81 | +// Settings: {"jsdoc":{"mode":"permissive"}} |
| 82 | +// Message: Missing @template D |
| 83 | + |
| 84 | +/** |
| 85 | + * @template D, U |
| 86 | + */ |
| 87 | +export type Extras<D, U, V> = [D, U, V | undefined]; |
| 88 | +// Message: Missing @template V |
| 89 | + |
| 90 | +/** |
| 91 | + * @template D, U |
| 92 | + * @typedef {[D, U, V | undefined]} Extras |
| 93 | + */ |
| 94 | +// Message: Missing @template V |
| 95 | + |
| 96 | +/** |
| 97 | + * @template D, V |
| 98 | + */ |
| 99 | +export type Pairs<D, V> = [D, V | undefined]; |
| 100 | +// "jsdoc/require-template": ["error"|"warn", {"requireSeparateTemplates":true}] |
| 101 | +// Message: Missing separate @template for V |
| 102 | + |
| 103 | +/** |
| 104 | + * @template D, V |
| 105 | + * @typedef {[D, V | undefined]} Pairs |
| 106 | + */ |
| 107 | +// "jsdoc/require-template": ["error"|"warn", {"requireSeparateTemplates":true}] |
| 108 | +// Message: Missing separate @template for V |
| 109 | +```` |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +<a name="user-content-require-template-passing-examples"></a> |
| 114 | +<a name="require-template-passing-examples"></a> |
| 115 | +## Passing examples |
| 116 | + |
| 117 | +The following patterns are not considered problems: |
| 118 | + |
| 119 | +````js |
| 120 | +/** |
| 121 | + * @template D |
| 122 | + * @template V |
| 123 | + */ |
| 124 | +export type Pairs<D, V> = [D, V | undefined]; |
| 125 | + |
| 126 | +/** |
| 127 | + * @template D |
| 128 | + * @template V |
| 129 | + * @typedef {[D, V | undefined]} Pairs |
| 130 | + */ |
| 131 | + |
| 132 | +/** |
| 133 | + * @template D, U, V |
| 134 | + */ |
| 135 | +export type Extras<D, U, V> = [D, U, V | undefined]; |
| 136 | + |
| 137 | +/** |
| 138 | + * @template D, U, V |
| 139 | + * @typedef {[D, U, V | undefined]} Extras |
| 140 | + */ |
| 141 | + |
| 142 | +/** |
| 143 | + * @typedef {[D, U, V | undefined]} Extras |
| 144 | + * @typedef {[D, U, V | undefined]} Extras |
| 145 | + */ |
| 146 | +```` |
| 147 | + |
0 commit comments