|
| 1 | +<a name="user-content-no-lines-after-blocks"></a> |
| 2 | +<a name="no-lines-after-blocks"></a> |
| 3 | +# <code>no-lines-after-blocks</code> |
| 4 | + |
| 5 | +Reports extra lines between functions (and other language structures) and their |
| 6 | +JSDoc blocks. |
| 7 | + |
| 8 | +Standalone comments such as `@typedef` and `@callback` will not be reported even |
| 9 | +if they are followed by a language structure. |
| 10 | + |
| 11 | +<a name="user-content-no-lines-after-blocks-fixer"></a> |
| 12 | +<a name="no-lines-after-blocks-fixer"></a> |
| 13 | +## Fixer |
| 14 | + |
| 15 | +Removes extra lines between functions (and other language structures) and their |
| 16 | +JSDoc blocks. Uses the `maxLines` setting to determine whether to remove lines. |
| 17 | + |
| 18 | +<a name="user-content-no-lines-after-blocks-options"></a> |
| 19 | +<a name="no-lines-after-blocks-options"></a> |
| 20 | +## Options |
| 21 | + |
| 22 | +A single options object has the following properties. |
| 23 | + |
| 24 | +<a name="user-content-no-lines-after-blocks-options-contexts"></a> |
| 25 | +<a name="no-lines-after-blocks-options-contexts"></a> |
| 26 | +### <code>contexts</code> |
| 27 | + |
| 28 | +Set this to an array of strings representing the AST context (or an object with |
| 29 | +`context` and `comment` properties) where you wish the rule to be applied. |
| 30 | + |
| 31 | +`context` defaults to `any` and `comment` defaults to no specific comment context. |
| 32 | + |
| 33 | +Overrides the default contexts (`ArrowFunctionExpression`, `FunctionDeclaration`, |
| 34 | +`FunctionExpression`). Setting to `"any"` may be problematic if you have |
| 35 | +JSDoc-style comments at the top of your files. |
| 36 | + |
| 37 | +See the ["AST and Selectors"](#user-content-eslint-plugin-jsdoc-advanced-ast-and-selectors) |
| 38 | +section of our Advanced docs for more on the expected format. |
| 39 | +<a name="user-content-no-lines-after-blocks-options-enablefixer"></a> |
| 40 | +<a name="no-lines-after-blocks-options-enablefixer"></a> |
| 41 | +### <code>enableFixer</code> |
| 42 | + |
| 43 | +Whether to enable the fixer to remove line breaks |
| 44 | +<a name="user-content-no-lines-after-blocks-options-exemptedby"></a> |
| 45 | +<a name="no-lines-after-blocks-options-exemptedby"></a> |
| 46 | +### <code>exemptedBy</code> |
| 47 | + |
| 48 | +Tag names to be added to those which will exempt reporting for a block. Defaults to: |
| 49 | + |
| 50 | +- 'callback' |
| 51 | +- 'copyright' |
| 52 | +- 'exports' |
| 53 | +- 'interface' |
| 54 | +- 'event' |
| 55 | +- 'external' |
| 56 | +- 'file' |
| 57 | +- 'fileoverview' |
| 58 | +- 'host' |
| 59 | +- 'import' |
| 60 | +- 'license' |
| 61 | +- 'module' |
| 62 | +- 'namespace' |
| 63 | +- 'overview' |
| 64 | +- 'typedef' |
| 65 | + |
| 66 | +<a name="user-content-no-lines-after-blocks-options-overridedefaultexemptions"></a> |
| 67 | +<a name="no-lines-after-blocks-options-overridedefaultexemptions"></a> |
| 68 | +### <code>overrideDefaultExemptions</code> |
| 69 | + |
| 70 | +Determines whether `exemptedBy` will override the default values. Defaults to `false`. |
| 71 | +<a name="user-content-no-lines-after-blocks-options-preferminlines"></a> |
| 72 | +<a name="no-lines-after-blocks-options-preferminlines"></a> |
| 73 | +### <code>preferMinLines</code> |
| 74 | + |
| 75 | +Whether to use the setting `minLines` as the basis for fixing lines going past `maxLines` |
| 76 | + |
| 77 | + |
| 78 | +||| |
| 79 | +|---|---| |
| 80 | +|Context|everywhere| |
| 81 | +|Tags|N/A| |
| 82 | +|Recommended|false| |
| 83 | +|Settings|`maxLines`, `minLines`| |
| 84 | +|Options|`contexts`, `enableFixer`, `exemptedBy`, `overrideDefaultExemptions`, `preferMinLines`| |
| 85 | + |
| 86 | +<a name="user-content-no-lines-after-blocks-failing-examples"></a> |
| 87 | +<a name="no-lines-after-blocks-failing-examples"></a> |
| 88 | +## Failing examples |
| 89 | + |
| 90 | +The following patterns are considered problems: |
| 91 | + |
| 92 | +````ts |
| 93 | +/** This is a description of some function!*/ |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +function someFunction() {} |
| 101 | +// Message: There should be no extra lines above structures with JSDoc blocks |
| 102 | + |
| 103 | +/** This is a description of some function!*/ |
| 104 | + |
| 105 | +function someFunction() {} |
| 106 | +// "jsdoc/no-lines-after-blocks": ["error"|"warn", {"enableFixer":false}] |
| 107 | +// Message: There should be no extra lines above structures with JSDoc blocks |
| 108 | + |
| 109 | +/** This is a description of some function!*/ |
| 110 | + |
| 111 | + |
| 112 | +function someFunction() {} |
| 113 | +// Settings: {"jsdoc":{"maxLines":2}} |
| 114 | +// Message: There should be no extra lines above structures with JSDoc blocks |
| 115 | + |
| 116 | +/** This is a description of some function!*/ |
| 117 | + |
| 118 | + |
| 119 | +function someFunction() {} |
| 120 | +// Settings: {"jsdoc":{"maxLines":2,"minLines":1}} |
| 121 | +// "jsdoc/no-lines-after-blocks": ["error"|"warn", {"preferMinLines":true}] |
| 122 | +// Message: There should be no extra lines above structures with JSDoc blocks |
| 123 | + |
| 124 | +/** @typedef SomeType */ |
| 125 | + |
| 126 | +function someFunction() {} |
| 127 | +// "jsdoc/no-lines-after-blocks": ["error"|"warn", {"exemptedBy":["function"],"overrideDefaultExemptions":true}] |
| 128 | +// Message: There should be no extra lines above structures with JSDoc blocks |
| 129 | +```` |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +<a name="user-content-no-lines-after-blocks-passing-examples"></a> |
| 134 | +<a name="no-lines-after-blocks-passing-examples"></a> |
| 135 | +## Passing examples |
| 136 | + |
| 137 | +The following patterns are not considered problems: |
| 138 | + |
| 139 | +````ts |
| 140 | +function someFunction() {} |
| 141 | + |
| 142 | +/** JSDoc */ function someFunction() {} |
| 143 | + |
| 144 | +/** This is a description of some function! */ |
| 145 | +// extra comment |
| 146 | +function someFunction() {} |
| 147 | + |
| 148 | +/** Standalone comment (e.g. a type definition) */ |
| 149 | + |
| 150 | +/** The actual description */ |
| 151 | +function someFunction() {} |
| 152 | + |
| 153 | +/* Regular block comment */ |
| 154 | + |
| 155 | +function someFunction() {} |
| 156 | + |
| 157 | +// Regular line comment |
| 158 | + |
| 159 | +function someFunction() {} |
| 160 | + |
| 161 | +/** This is a description of some function!*/ |
| 162 | + |
| 163 | +function someFunction() {} |
| 164 | +// Settings: {"jsdoc":{"maxLines":2}} |
| 165 | + |
| 166 | +/** @typedef {string} SomeType */ |
| 167 | + |
| 168 | +function someFunction() {} |
| 169 | + |
| 170 | +/** @function SomeType */ |
| 171 | + |
| 172 | +function someFunction() {} |
| 173 | +// "jsdoc/no-lines-after-blocks": ["error"|"warn", {"exemptedBy":["function"]}] |
| 174 | + |
| 175 | +/** |
| 176 | + * JSDoc block at top of file without import declaration context. |
| 177 | + */ |
| 178 | + |
| 179 | +import {sth} from 'sth'; |
| 180 | +```` |
| 181 | + |
0 commit comments