1 # Require or disallow padding lines between statements (padding-line-between-statements)
3 This rule requires or disallows blank lines between the given 2 kinds of statements.
4 Properly blank lines help developers to understand the code.
6 For example, the following configuration requires a blank line between a variable declaration and a `return` statement.
9 /*eslint padding-line-between-statements: [
11 { blankLine: "always", prev: "var", next: "return" }
23 This rule does nothing if no configurations are provided.
25 A configuration is an object which has 3 properties; `blankLine`, `prev` and `next`. For example, `{ blankLine: "always", prev: "var", next: "return" }` means "one or more blank lines are required between a variable declaration and a `return` statement."
26 You can supply any number of configurations. If a statement pair matches multiple configurations, the last matched configuration will be used.
30 "padding-line-between-statements": [
32 { "blankLine": LINEBREAK_TYPE, "prev": STATEMENT_TYPE, "next": STATEMENT_TYPE },
33 { "blankLine": LINEBREAK_TYPE, "prev": STATEMENT_TYPE, "next": STATEMENT_TYPE },
34 { "blankLine": LINEBREAK_TYPE, "prev": STATEMENT_TYPE, "next": STATEMENT_TYPE },
35 { "blankLine": LINEBREAK_TYPE, "prev": STATEMENT_TYPE, "next": STATEMENT_TYPE },
41 - `LINEBREAK_TYPE` is one of the following.
42 - `"any"` just ignores the statement pair.
43 - `"never"` disallows blank lines.
44 - `"always"` requires one or more blank lines. Note it does not count lines that comments exist as blank lines.
46 - `STATEMENT_TYPE` is one of the following, or an array of the following.
47 - `"*"` is wildcard. This matches any statements.
48 - `"block"` is lonely blocks.
49 - `"block-like"` is block like statements. This matches statements that the last token is the closing brace of blocks; e.g. `{ }`, `if (a) { }`, and `while (a) { }`. Also matches immediately invoked function expression statements.
50 - `"break"` is `break` statements.
51 - `"case"` is `case` clauses in `switch` statements.
52 - `"cjs-export"` is `export` statements of CommonJS; e.g. `module.exports = 0`, `module.exports.foo = 1`, and `exports.foo = 2`. This is a special case of assignment.
53 - `"cjs-import"` is `import` statements of CommonJS; e.g. `const foo = require("foo")`. This is a special case of variable declarations.
54 - `"class"` is `class` declarations.
55 - `"const"` is `const` variable declarations, both single-line and multiline.
56 - `"continue"` is `continue` statements.
57 - `"debugger"` is `debugger` statements.
58 - `"default"` is `default` clauses in `switch` statements.
59 - `"directive"` is directive prologues. This matches directives; e.g. `"use strict"`.
60 - `"do"` is `do-while` statements. This matches all statements that the first token is `do` keyword.
61 - `"empty"` is empty statements.
62 - `"export"` is `export` declarations.
63 - `"expression"` is expression statements.
64 - `"for"` is `for` loop families. This matches all statements that the first token is `for` keyword.
65 - `"function"` is function declarations.
66 - `"if"` is `if` statements.
67 - `"iife"` is immediately invoked function expression statements. This matches calls on a function expression, optionally prefixed with a unary operator.
68 - `"import"` is `import` declarations.
69 - `"let"` is `let` variable declarations, both single-line and multiline.
70 - `"multiline-block-like"` is block like statements. This is the same as `block-like` type, but only if the block is multiline.
71 - `"multiline-const"` is multiline `const` variable declarations.
72 - `"multiline-expression"` is expression statements. This is the same as `expression` type, but only if the statement is multiline.
73 - `"multiline-let"` is multiline `let` variable declarations.
74 - `"multiline-var"` is multiline `var` variable declarations.
75 - `"return"` is `return` statements.
76 - `"singleline-const"` is single-line `const` variable declarations.
77 - `"singleline-let"` is single-line `let` variable declarations.
78 - `"singleline-var"` is single-line `var` variable declarations.
79 - `"switch"` is `switch` statements.
80 - `"throw"` is `throw` statements.
81 - `"try"` is `try` statements.
82 - `"var"` is `var` variable declarations, both single-line and multiline.
83 - `"while"` is `while` loop statements.
84 - `"with"` is `with` statements.
88 This configuration would require blank lines before all `return` statements, like the [newline-before-return] rule.
90 Examples of **incorrect** code for the `[{ blankLine: "always", prev: "*", next: "return" }]` configuration:
93 /*eslint padding-line-between-statements: [
95 { blankLine: "always", prev: "*", next: "return" }
104 Examples of **correct** code for the `[{ blankLine: "always", prev: "*", next: "return" }]` configuration:
107 /*eslint padding-line-between-statements: [
109 { blankLine: "always", prev: "*", next: "return" }
125 This configuration would require blank lines after every sequence of variable declarations, like the [newline-after-var] rule.
127 Examples of **incorrect** code for the `[{ blankLine: "always", prev: ["const", "let", "var"], next: "*"}, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"]}]` configuration:
130 /*eslint padding-line-between-statements: [
132 { blankLine: "always", prev: ["const", "let", "var"], next: "*"},
133 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"]}
159 Examples of **correct** code for the `[{ blankLine: "always", prev: ["const", "let", "var"], next: "*"}, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"]}]` configuration:
162 /*eslint padding-line-between-statements: [
164 { blankLine: "always", prev: ["const", "let", "var"], next: "*"},
165 { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"]}
201 This configuration would require blank lines after all directive prologues, like the [lines-around-directive] rule.
203 Examples of **incorrect** code for the `[{ blankLine: "always", prev: "directive", next: "*" }, { blankLine: "any", prev: "directive", next: "directive" }]` configuration:
206 /*eslint padding-line-between-statements: [
208 { blankLine: "always", prev: "directive", next: "*" },
209 { blankLine: "any", prev: "directive", next: "directive" }
216 Examples of **correct** code for the `[{ blankLine: "always", prev: "directive", next: "*" }, { blankLine: "any", prev: "directive", next: "directive" }]` configuration:
219 /*eslint padding-line-between-statements: [
221 { blankLine: "always", prev: "directive", next: "*" },
222 { blankLine: "any", prev: "directive", next: "directive" }
233 This configuration would require blank lines between clauses in `switch` statements.
235 Examples of **incorrect** code for the `[{ blankLine: "always", prev: ["case", "default"], next: "*" }]` configuration:
238 /*eslint padding-line-between-statements: [
240 { blankLine: "always", prev: ["case", "default"], next: "*" }
256 Examples of **correct** code for the `[{ blankLine: "always", prev: ["case", "default"], next: "*" }]` configuration:
259 /*eslint padding-line-between-statements: [
261 { blankLine: "always", prev: ["case", "default"], next: "*" }
282 - **JSCS:** [requirePaddingNewLineAfterVariableDeclaration]
283 - **JSCS:** [requirePaddingNewLinesAfterBlocks]
284 - **JSCS:** [disallowPaddingNewLinesAfterBlocks]
285 - **JSCS:** [requirePaddingNewLinesAfterUseStrict]
286 - **JSCS:** [disallowPaddingNewLinesAfterUseStrict]
287 - **JSCS:** [requirePaddingNewLinesBeforeExport]
288 - **JSCS:** [disallowPaddingNewLinesBeforeExport]
289 - **JSCS:** [requirePaddingNewlinesBeforeKeywords]
290 - **JSCS:** [disallowPaddingNewlinesBeforeKeywords]
292 ## When Not To Use It
294 If you don't want to notify warnings about linebreaks, then it's safe to disable this rule.
296 [lines-around-directive]: https://eslint.org/docs/rules/lines-around-directive
297 [newline-after-var]: https://eslint.org/docs/rules/newline-after-var
298 [newline-before-return]: https://eslint.org/docs/rules/newline-before-return
299 [requirePaddingNewLineAfterVariableDeclaration]: https://jscs-dev.github.io/rule/requirePaddingNewLineAfterVariableDeclaration
300 [requirePaddingNewLinesAfterBlocks]: https://jscs-dev.github.io/rule/requirePaddingNewLinesAfterBlocks
301 [disallowPaddingNewLinesAfterBlocks]: https://jscs-dev.github.io/rule/disallowPaddingNewLinesAfterBlocks
302 [requirePaddingNewLinesAfterUseStrict]: https://jscs-dev.github.io/rule/requirePaddingNewLinesAfterUseStrict
303 [disallowPaddingNewLinesAfterUseStrict]: https://jscs-dev.github.io/rule/disallowPaddingNewLinesAfterUseStrict
304 [requirePaddingNewLinesBeforeExport]: https://jscs-dev.github.io/rule/requirePaddingNewLinesBeforeExport
305 [disallowPaddingNewLinesBeforeExport]: https://jscs-dev.github.io/rule/disallowPaddingNewLinesBeforeExport
306 [requirePaddingNewlinesBeforeKeywords]: https://jscs-dev.github.io/rule/requirePaddingNewlinesBeforeKeywords
307 [disallowPaddingNewlinesBeforeKeywords]: https://jscs-dev.github.io/rule/disallowPaddingNewlinesBeforeKeywords