Skip to content

Commit 6cb63fd

Browse files
platinumazurenot-an-aardvark
authored andcommittedOct 12, 2018
Update: Add iife to padding-line-between-statements (fixes #10853) (#10916)
1 parent 5fd1bda commit 6cb63fd

File tree

3 files changed

+83
-5
lines changed

3 files changed

+83
-5
lines changed
 

‎docs/rules/padding-line-between-statements.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function foo() {
2020

2121
## Rule Details
2222

23-
This rule does nothing if no configuration.
23+
This rule does nothing if no configurations are provided.
2424

25-
A configuration is an object which has 3 properties; `blankLine`, `prev` and `next`. For example, `{ blankLine: "always", prev: "var", next: "return" }` means "it requires one or more blank lines between a variable declaration and a `return` statement."
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."
2626
You can supply any number of configurations. If a statement pair matches multiple configurations, the last matched configuration will be used.
2727

2828
```json
@@ -46,11 +46,11 @@ You can supply any number of configurations. If a statement pair matches multipl
4646
- `STATEMENT_TYPE` is one of the following, or an array of the following.
4747
- `"*"` is wildcard. This matches any statements.
4848
- `"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) { }`.
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.
5050
- `"break"` is `break` statements.
5151
- `"case"` is `case` labels.
52-
- `"cjs-export"` is `export` statements of CommonJS; e.g. `module.exports = 0`, `module.exports.foo = 1`, and `exports.foo = 2`. This is the special cases of assignment.
53-
- `"cjs-import"` is `import` statements of CommonJS; e.g. `const foo = require("foo")`. This is the special cases of variable declarations.
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.
5454
- `"class"` is `class` declarations.
5555
- `"const"` is `const` variable declarations.
5656
- `"continue"` is `continue` statements.
@@ -64,6 +64,7 @@ You can supply any number of configurations. If a statement pair matches multipl
6464
- `"for"` is `for` loop families. This matches all statements that the first token is `for` keyword.
6565
- `"function"` is function declarations.
6666
- `"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.
6768
- `"import"` is `import` declarations.
6869
- `"let"` is `let` variable declarations.
6970
- `"multiline-block-like"` is block like statements. This is the same as `block-like` type, but only if the block is multiline.

‎lib/rules/padding-line-between-statements.js

+3
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ const StatementTypes = {
353353
node.type === "ExpressionStatement" &&
354354
!isDirectivePrologue(node, sourceCode)
355355
},
356+
iife: {
357+
test: isIIFEStatement
358+
},
356359
"multiline-block-like": {
357360
test: (node, sourceCode) =>
358361
node.loc.start.line !== node.loc.end.line &&

‎tests/lib/rules/padding-line-between-statements.js

+74
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,35 @@ ruleTester.run("padding-line-between-statements", rule, {
852852
]
853853
},
854854

855+
//----------------------------------------------------------------------
856+
// iife
857+
//----------------------------------------------------------------------
858+
859+
{
860+
code: "(function(){\n})()\n\nvar a = 2;",
861+
options: [
862+
{ blankLine: "always", prev: "iife", next: "*" }
863+
]
864+
},
865+
{
866+
code: "+(function(){\n})()\n\nvar a = 2;",
867+
options: [
868+
{ blankLine: "always", prev: "iife", next: "*" }
869+
]
870+
},
871+
{
872+
code: "(function(){\n})()\nvar a = 2;",
873+
options: [
874+
{ blankLine: "never", prev: "iife", next: "*" }
875+
]
876+
},
877+
{
878+
code: "+(function(){\n})()\nvar a = 2;",
879+
options: [
880+
{ blankLine: "never", prev: "iife", next: "*" }
881+
]
882+
},
883+
855884
//----------------------------------------------------------------------
856885
// import
857886
//----------------------------------------------------------------------
@@ -3371,6 +3400,43 @@ ruleTester.run("padding-line-between-statements", rule, {
33713400
errors: [MESSAGE_ALWAYS]
33723401
},
33733402

3403+
//----------------------------------------------------------------------
3404+
// iife
3405+
//----------------------------------------------------------------------
3406+
3407+
{
3408+
code: "(function(){\n})()\n\nvar a = 2;",
3409+
output: "(function(){\n})()\nvar a = 2;",
3410+
options: [
3411+
{ blankLine: "never", prev: "iife", next: "*" }
3412+
],
3413+
errors: [MESSAGE_NEVER]
3414+
},
3415+
{
3416+
code: "+(function(){\n})()\n\nvar a = 2;",
3417+
output: "+(function(){\n})()\nvar a = 2;",
3418+
options: [
3419+
{ blankLine: "never", prev: "iife", next: "*" }
3420+
],
3421+
errors: [MESSAGE_NEVER]
3422+
},
3423+
{
3424+
code: "(function(){\n})()\nvar a = 2;",
3425+
output: "(function(){\n})()\n\nvar a = 2;",
3426+
options: [
3427+
{ blankLine: "always", prev: "iife", next: "*" }
3428+
],
3429+
errors: [MESSAGE_ALWAYS]
3430+
},
3431+
{
3432+
code: "+(function(){\n})()\nvar a = 2;",
3433+
output: "+(function(){\n})()\n\nvar a = 2;",
3434+
options: [
3435+
{ blankLine: "always", prev: "iife", next: "*" }
3436+
],
3437+
errors: [MESSAGE_ALWAYS]
3438+
},
3439+
33743440
//----------------------------------------------------------------------
33753441
// import
33763442
//----------------------------------------------------------------------
@@ -4247,6 +4313,14 @@ ruleTester.run("padding-line-between-statements", rule, {
42474313
],
42484314
errors: [MESSAGE_NEVER]
42494315
},
4316+
{
4317+
code: "+(function(){\n})()\n\nvar a = 2;",
4318+
output: "+(function(){\n})()\nvar a = 2;",
4319+
options: [
4320+
{ blankLine: "never", prev: "block-like", next: "*" }
4321+
],
4322+
errors: [MESSAGE_NEVER]
4323+
},
42504324
{
42514325
code: "var a = function() {};\n\nvar b = 2;",
42524326
output: "var a = function() {};\nvar b = 2;",

0 commit comments

Comments
 (0)
Please sign in to comment.