|
4 | 4 |
|
5 | 5 | Converts single line or non-JSDoc, multiline comments into JSDoc comments.
|
6 | 6 |
|
| 7 | +Note that this rule is experimental. As usual with fixers, please confirm |
| 8 | +the results before committing. |
| 9 | + |
7 | 10 | <a name="user-content-convert-to-jsdoc-comments-options"></a>
|
8 | 11 | <a name="convert-to-jsdoc-comments-options"></a>
|
9 | 12 | ## Options
|
@@ -57,13 +60,39 @@ Defaults to `['@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-']`.
|
57 | 60 |
|
58 | 61 | Supplying your own value overrides the defaults.
|
59 | 62 |
|
| 63 | +<a name="user-content-convert-to-jsdoc-comments-options-contexts"></a> |
| 64 | +<a name="convert-to-jsdoc-comments-options-contexts"></a> |
| 65 | +### <code>contexts</code> |
| 66 | + |
| 67 | +The contexts which will be checked for preceding content. |
| 68 | + |
| 69 | +Defaults to `ArrowFunctionExpression`, `FunctionDeclaration`, |
| 70 | +`FunctionExpression`, `TSDeclareFunction`. |
| 71 | + |
| 72 | +<a name="user-content-convert-to-jsdoc-comments-options-contextsafter"></a> |
| 73 | +<a name="convert-to-jsdoc-comments-options-contextsafter"></a> |
| 74 | +### <code>contextsAfter</code> |
| 75 | + |
| 76 | +The contexts which will be checked for content on the same line after. |
| 77 | + |
| 78 | +Defaults to an empty array. |
| 79 | + |
| 80 | +<a name="user-content-convert-to-jsdoc-comments-options-contextsbeforeandafter"></a> |
| 81 | +<a name="convert-to-jsdoc-comments-options-contextsbeforeandafter"></a> |
| 82 | +### <code>contextsBeforeAndAfter</code> |
| 83 | + |
| 84 | +The contexts which will be checked for content before and on the same |
| 85 | +line after. |
| 86 | + |
| 87 | +Defaults to `VariableDeclarator`, `TSPropertySignature`, `PropertyDefinition`. |
| 88 | + |
60 | 89 | |||
|
61 | 90 | |---|---|
|
62 | 91 | |Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
|
63 | 92 | |Tags|(N/A)|
|
64 | 93 | |Recommended|false|
|
65 | 94 | |Settings|`minLines`, `maxLines`|
|
66 |
| -|Options|`enableFixer`, `enforceJsdocLineStyle`, `lineOrBlockStyle`| |
| 95 | +|Options|`enableFixer`, `enforceJsdocLineStyle`, `lineOrBlockStyle`, `allowedPrefixes`, `contexts`, `contextsAfter`, `contextsBeforeAndAfter`| |
67 | 96 |
|
68 | 97 | <a name="user-content-convert-to-jsdoc-comments-failing-examples"></a>
|
69 | 98 | <a name="convert-to-jsdoc-comments-failing-examples"></a>
|
@@ -134,6 +163,44 @@ export class User {
|
134 | 163 | // Settings: {"jsdoc":{"minLines":0,"maxLines":0}}
|
135 | 164 | // "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}]
|
136 | 165 | // Message: Block comments should be JSDoc-style.
|
| 166 | + |
| 167 | +var a = []; // Test comment |
| 168 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":[],"contextsAfter":["VariableDeclarator"]}] |
| 169 | +// Message: Line comments should be JSDoc-style. |
| 170 | + |
| 171 | +var a = []; // Test comment |
| 172 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":[],"contextsAfter":[{"context":"VariableDeclarator","inlineCommentBlock":true}]}] |
| 173 | +// Message: Line comments should be JSDoc-style. |
| 174 | + |
| 175 | +var a = []; // Test comment |
| 176 | +// Settings: {"jsdoc":{"minLines":0,"maxLines":0}} |
| 177 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":[],"contextsAfter":[{"context":"VariableDeclarator","inlineCommentBlock":true}]}] |
| 178 | +// Message: Line comments should be JSDoc-style. |
| 179 | + |
| 180 | +// Test comment |
| 181 | +var a = []; |
| 182 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":["VariableDeclaration"]}] |
| 183 | +// Message: Line comments should be JSDoc-style. |
| 184 | + |
| 185 | +var a = []; // Test comment |
| 186 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":["VariableDeclaration"]}] |
| 187 | +// Message: Line comments should be JSDoc-style. |
| 188 | + |
| 189 | +interface B { |
| 190 | + g: () => string; // Test comment |
| 191 | +} |
| 192 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":["TSPropertySignature"]}] |
| 193 | +// Message: Line comments should be JSDoc-style. |
| 194 | + |
| 195 | +class TestClass { |
| 196 | + public Test: (id: number) => string; // Test comment |
| 197 | +} |
| 198 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":["PropertyDefinition"]}] |
| 199 | +// Message: Line comments should be JSDoc-style. |
| 200 | + |
| 201 | +var a = []; // Test comment |
| 202 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":["VariableDeclarator"]}] |
| 203 | +// Message: Line comments should be JSDoc-style. |
137 | 204 | ````
|
138 | 205 |
|
139 | 206 |
|
@@ -175,5 +242,9 @@ function quux () {}
|
175 | 242 | // @custom-something
|
176 | 243 | function quux () {}
|
177 | 244 | // "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"allowedPrefixes":["@custom-"]}]
|
| 245 | + |
| 246 | +// Test comment |
| 247 | +var a = []; |
| 248 | +// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contextsBeforeAndAfter":[],"contextsAfter":["VariableDeclarator"]}] |
178 | 249 | ````
|
179 | 250 |
|
0 commit comments