|
| 1 | +<a name="user-content-lines-before-block"></a> |
| 2 | +<a name="lines-before-block"></a> |
| 3 | +# <code>lines-before-block</code> |
| 4 | + |
| 5 | +This rule enforces minimum number of newlines before JSDoc comment blocks |
| 6 | +(except at the beginning of a file). |
| 7 | + |
| 8 | +<a name="user-content-lines-before-block-options"></a> |
| 9 | +<a name="lines-before-block-options"></a> |
| 10 | +## Options |
| 11 | + |
| 12 | +<a name="user-content-lines-before-block-options-lines"></a> |
| 13 | +<a name="lines-before-block-options-lines"></a> |
| 14 | +### <code>lines</code> |
| 15 | + |
| 16 | +The minimum number of lines to require. Defaults to 1. |
| 17 | + |
| 18 | +<a name="user-content-lines-before-block-options-ignoresameline"></a> |
| 19 | +<a name="lines-before-block-options-ignoresameline"></a> |
| 20 | +### <code>ignoreSameLine</code> |
| 21 | + |
| 22 | +This option excludes cases where the JSDoc block occurs on the same line as a |
| 23 | +preceding code or comment. Defaults to `true`. |
| 24 | + |
| 25 | +<a name="user-content-lines-before-block-options-excludedtags"></a> |
| 26 | +<a name="lines-before-block-options-excludedtags"></a> |
| 27 | +### <code>excludedTags</code> |
| 28 | + |
| 29 | +An array of tags whose presence in the JSDoc block will prevent the |
| 30 | +application of the rule. Defaults to `['type']` (i.e., if `@type` is present, |
| 31 | +lines before the block will not be added). |
| 32 | + |
| 33 | +||| |
| 34 | +|---|---| |
| 35 | +|Context|everywhere| |
| 36 | +|Tags|N/A| |
| 37 | +|Recommended|true| |
| 38 | +|Settings|| |
| 39 | +|Options|`excludedTags`, `ignoreSameLine`, `lines`| |
| 40 | + |
| 41 | +<a name="user-content-lines-before-block-failing-examples"></a> |
| 42 | +<a name="lines-before-block-failing-examples"></a> |
| 43 | +## Failing examples |
| 44 | + |
| 45 | +The following patterns are considered problems: |
| 46 | + |
| 47 | +````ts |
| 48 | +someCode; |
| 49 | +/** |
| 50 | + * |
| 51 | + */ |
| 52 | +// Message: Required 1 line(s) before JSDoc block |
| 53 | + |
| 54 | +someCode; /** |
| 55 | + * |
| 56 | + */ |
| 57 | +// "jsdoc/lines-before-block": ["error"|"warn", {"ignoreSameLine":false}] |
| 58 | +// Message: Required 1 line(s) before JSDoc block |
| 59 | + |
| 60 | +someCode; /** */ |
| 61 | +// "jsdoc/lines-before-block": ["error"|"warn", {"ignoreSameLine":false}] |
| 62 | +// Message: Required 1 line(s) before JSDoc block |
| 63 | + |
| 64 | +someCode; |
| 65 | +/** |
| 66 | + * |
| 67 | + */ |
| 68 | +// "jsdoc/lines-before-block": ["error"|"warn", {"lines":2}] |
| 69 | +// Message: Required 2 line(s) before JSDoc block |
| 70 | + |
| 71 | +// Some comment |
| 72 | +/** |
| 73 | + * |
| 74 | + */ |
| 75 | +// Message: Required 1 line(s) before JSDoc block |
| 76 | + |
| 77 | +/* Some comment */ |
| 78 | +/** |
| 79 | + * |
| 80 | + */ |
| 81 | +// Message: Required 1 line(s) before JSDoc block |
| 82 | + |
| 83 | +/** |
| 84 | + * Some comment |
| 85 | + */ |
| 86 | +/** |
| 87 | + * |
| 88 | + */ |
| 89 | +// Message: Required 1 line(s) before JSDoc block |
| 90 | +```` |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | +<a name="user-content-lines-before-block-passing-examples"></a> |
| 95 | +<a name="lines-before-block-passing-examples"></a> |
| 96 | +## Passing examples |
| 97 | + |
| 98 | +The following patterns are not considered problems: |
| 99 | + |
| 100 | +````ts |
| 101 | +/** |
| 102 | +* |
| 103 | +*/ |
| 104 | + |
| 105 | +someCode; |
| 106 | + |
| 107 | +/** |
| 108 | + * |
| 109 | + */ |
| 110 | + |
| 111 | +someCode; |
| 112 | + |
| 113 | + |
| 114 | +/** |
| 115 | + * |
| 116 | + */ |
| 117 | +// "jsdoc/lines-before-block": ["error"|"warn", {"lines":2}] |
| 118 | + |
| 119 | +// Some comment |
| 120 | + |
| 121 | +/** |
| 122 | + * |
| 123 | + */ |
| 124 | + |
| 125 | +/* Some comment */ |
| 126 | + |
| 127 | +/** |
| 128 | + * |
| 129 | + */ |
| 130 | + |
| 131 | +/** |
| 132 | + * Some comment |
| 133 | + */ |
| 134 | + |
| 135 | +/** |
| 136 | + * |
| 137 | + */ |
| 138 | + |
| 139 | +someCode; /** */ |
| 140 | + |
| 141 | +const a = { |
| 142 | + someProp: /** @type {SomeCast} */ (someVal) |
| 143 | +}; |
| 144 | + |
| 145 | +const a = /** @lends SomeClass */ { |
| 146 | + someProp: (someVal) |
| 147 | +}; |
| 148 | +// "jsdoc/lines-before-block": ["error"|"warn", {"excludedTags":["lends"],"ignoreSameLine":false}] |
| 149 | +```` |
| 150 | + |
0 commit comments