|
| 1 | +<a name="user-content-convert-to-jsdoc-comments"></a> |
| 2 | +<a name="convert-to-jsdoc-comments"></a> |
| 3 | +# <code>convert-to-jsdoc-comments</code> |
| 4 | + |
| 5 | +Converts single line or non-JSDoc, multiline comments into JSDoc comments. |
| 6 | + |
| 7 | +<a name="user-content-convert-to-jsdoc-comments-options"></a> |
| 8 | +<a name="convert-to-jsdoc-comments-options"></a> |
| 9 | +## Options |
| 10 | + |
| 11 | +<a name="user-content-convert-to-jsdoc-comments-options-enablefixer"></a> |
| 12 | +<a name="convert-to-jsdoc-comments-options-enablefixer"></a> |
| 13 | +### <code>enableFixer</code> |
| 14 | + |
| 15 | +Set to `false` to disable fixing. |
| 16 | + |
| 17 | +<a name="user-content-convert-to-jsdoc-comments-options-lineorblockstyle"></a> |
| 18 | +<a name="convert-to-jsdoc-comments-options-lineorblockstyle"></a> |
| 19 | +### <code>lineOrBlockStyle</code> |
| 20 | + |
| 21 | +What style of comments to which to apply JSDoc conversion. |
| 22 | + |
| 23 | +- `block` - Applies to block-style comments (`/* ... */`) |
| 24 | +- `line` - Applies to line-style comments (`// ...`) |
| 25 | +- `both` - Applies to both block and line-style comments |
| 26 | + |
| 27 | +Defaults to `both`. |
| 28 | + |
| 29 | +<a name="user-content-convert-to-jsdoc-comments-options-enforcejsdoclinestyle"></a> |
| 30 | +<a name="convert-to-jsdoc-comments-options-enforcejsdoclinestyle"></a> |
| 31 | +### <code>enforceJsdocLineStyle</code> |
| 32 | + |
| 33 | +What policy to enforce on the conversion of non-JSDoc comments without |
| 34 | +line breaks. (Non-JSDoc (mulitline) comments with line breaks will always |
| 35 | +be converted to `multi` style JSDoc comments.) |
| 36 | + |
| 37 | +- `multi` - Convert to multi-line style |
| 38 | +```js |
| 39 | +/** |
| 40 | + * Some text |
| 41 | + */ |
| 42 | +``` |
| 43 | +- `single` - Convert to single-line style |
| 44 | +```js |
| 45 | +/** Some text */ |
| 46 | +``` |
| 47 | + |
| 48 | +Defaults to `multi`. |
| 49 | + |
| 50 | +<a name="user-content-convert-to-jsdoc-comments-options-allowedprefixes"></a> |
| 51 | +<a name="convert-to-jsdoc-comments-options-allowedprefixes"></a> |
| 52 | +### <code>allowedPrefixes</code> |
| 53 | + |
| 54 | +An array of prefixes to allow at the beginning of a comment. |
| 55 | + |
| 56 | +Defaults to `['@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-']`. |
| 57 | + |
| 58 | +Supplying your own value overrides the defaults. |
| 59 | + |
| 60 | +||| |
| 61 | +|---|---| |
| 62 | +|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`| |
| 63 | +|Tags|(N/A)| |
| 64 | +|Recommended|false| |
| 65 | +|Settings|`minLines`, `maxLines`| |
| 66 | +|Options|`enableFixer`, `enforceJsdocLineStyle`, `lineOrBlockStyle`| |
| 67 | + |
| 68 | +<a name="user-content-convert-to-jsdoc-comments-failing-examples"></a> |
| 69 | +<a name="convert-to-jsdoc-comments-failing-examples"></a> |
| 70 | +## Failing examples |
| 71 | + |
| 72 | +The following patterns are considered problems: |
| 73 | + |
| 74 | +````js |
| 75 | +// A single line comment |
| 76 | +function quux () {} |
| 77 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}] |
| 78 | +// Message: Line comments should be JSDoc-style. |
| 79 | + |
| 80 | +// A single line comment |
| 81 | +function quux () {} |
| 82 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contexts":[{"context":"FunctionDeclaration","inlineCommentBlock":true}]}] |
| 83 | +// Message: Line comments should be JSDoc-style. |
| 84 | + |
| 85 | +// A single line comment |
| 86 | +function quux () {} |
| 87 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enableFixer":false,"enforceJsdocLineStyle":"single"}] |
| 88 | +// Message: Line comments should be JSDoc-style. |
| 89 | + |
| 90 | +// A single line comment |
| 91 | +function quux () {} |
| 92 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"line","enforceJsdocLineStyle":"single"}] |
| 93 | +// Message: Line comments should be JSDoc-style. |
| 94 | + |
| 95 | +/* A single line comment */ |
| 96 | +function quux () {} |
| 97 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}] |
| 98 | +// Message: Block comments should be JSDoc-style. |
| 99 | + |
| 100 | +/* A single line comment */ |
| 101 | +function quux () {} |
| 102 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"block","enforceJsdocLineStyle":"single"}] |
| 103 | +// Message: Block comments should be JSDoc-style. |
| 104 | + |
| 105 | +// A single line comment |
| 106 | +function quux () {} |
| 107 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"multi"}] |
| 108 | +// Message: Line comments should be JSDoc-style. |
| 109 | + |
| 110 | +// A single line comment |
| 111 | +function quux () {} |
| 112 | +// Message: Line comments should be JSDoc-style. |
| 113 | + |
| 114 | +/* A single line comment */ |
| 115 | +function quux () {} |
| 116 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"multi"}] |
| 117 | +// Message: Block comments should be JSDoc-style. |
| 118 | + |
| 119 | +// Single line comment |
| 120 | +function quux() { |
| 121 | + |
| 122 | +} |
| 123 | +// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}} |
| 124 | +// Message: Cannot add "name" to `require` with the tag's `name` set to `false` |
| 125 | + |
| 126 | +/* Entity to represent a user in the system. */ |
| 127 | +@Entity('users', getVal()) |
| 128 | +export class User { |
| 129 | +} |
| 130 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contexts":["ClassDeclaration"]}] |
| 131 | +// Message: Block comments should be JSDoc-style. |
| 132 | + |
| 133 | +/* A single line comment */ function quux () {} |
| 134 | +// Settings: {"jsdoc":{"minLines":0,"maxLines":0}} |
| 135 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}] |
| 136 | +// Message: Block comments should be JSDoc-style. |
| 137 | +```` |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +<a name="user-content-convert-to-jsdoc-comments-passing-examples"></a> |
| 142 | +<a name="convert-to-jsdoc-comments-passing-examples"></a> |
| 143 | +## Passing examples |
| 144 | + |
| 145 | +The following patterns are not considered problems: |
| 146 | + |
| 147 | +````js |
| 148 | +/** A single line comment */ |
| 149 | +function quux () {} |
| 150 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}] |
| 151 | + |
| 152 | +/** A single line comment */ |
| 153 | +function quux () {} |
| 154 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"multi"}] |
| 155 | + |
| 156 | +/** A single line comment */ |
| 157 | +function quux () {} |
| 158 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"line"}] |
| 159 | + |
| 160 | +/** A single line comment */ |
| 161 | +function quux () {} |
| 162 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"block"}] |
| 163 | + |
| 164 | +/* A single line comment */ |
| 165 | +function quux () {} |
| 166 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"line","enforceJsdocLineStyle":"single"}] |
| 167 | + |
| 168 | +// A single line comment |
| 169 | +function quux () {} |
| 170 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"block","enforceJsdocLineStyle":"single"}] |
| 171 | + |
| 172 | +// @ts-expect-error |
| 173 | +function quux () {} |
| 174 | + |
| 175 | +// @custom-something |
| 176 | +function quux () {} |
| 177 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"allowedPrefixes":["@custom-"]}] |
| 178 | +```` |
| 179 | + |
0 commit comments