From ac4d19b33f42bc3bec2b679c499c6b79f688a2b8 Mon Sep 17 00:00:00 2001 From: Lobstrosity Date: Tue, 30 May 2017 09:32:59 -0700 Subject: [PATCH 1/5] Update: Add multiline-expression statement type --- lib/rules/padding-line-between-statements.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/rules/padding-line-between-statements.js b/lib/rules/padding-line-between-statements.js index 707cf33d85c..53b802e3d20 100644 --- a/lib/rules/padding-line-between-statements.js +++ b/lib/rules/padding-line-between-statements.js @@ -356,6 +356,12 @@ const StatementTypes = { node.loc.start.line !== node.loc.end.line && isBlockLikeStatement(sourceCode, node) }, + "multiline-expression": { + test: (node, sourceCode) => + node.loc.start.line !== node.loc.end.line && + node.type === "ExpressionStatement" && + !isDirectivePrologue(node, sourceCode) + }, block: newNodeTypeTester("BlockStatement"), empty: newNodeTypeTester("EmptyStatement"), @@ -585,3 +591,4 @@ module.exports = { }; } }; + From 69f0adfa7f1ab810061a4eca6dc2ad7553745094 Mon Sep 17 00:00:00 2001 From: Lobstrosity Date: Tue, 30 May 2017 09:35:21 -0700 Subject: [PATCH 2/5] Chore: Add valid and invalid tests for multiline-expression --- .../rules/padding-line-between-statements.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index 2cb260f3e56..470422085cf 100644 --- a/tests/lib/rules/padding-line-between-statements.js +++ b/tests/lib/rules/padding-line-between-statements.js @@ -534,6 +534,23 @@ ruleTester.run("padding-line-between-statements", rule, { ] }, + //---------------------------------------------------------------------- + // multiline-expression + //---------------------------------------------------------------------- + + { + code: "foo()\n\nfoo(\n\tx,\n\ty\n)", + options: [ + { blankLine: "always", prev: "*", next: "multiline-expression" } + ] + }, + { + code: "foo()\nfoo()", + options: [ + { blankLine: "always", prev: "*", next: "multiline-expression" } + ] + }, + //---------------------------------------------------------------------- // break //---------------------------------------------------------------------- @@ -2988,6 +3005,27 @@ ruleTester.run("padding-line-between-statements", rule, { errors: [MESSAGE_ALWAYS] }, + //---------------------------------------------------------------------- + // multiline-expression + //---------------------------------------------------------------------- + + { + code: "foo()\n\nfoo(\n\tx,\n\ty\n)", + output: "foo()\nfoo(\n\tx,\n\ty\n)", + options: [ + { blankLine: "never", prev: "*", next: "multiline-expression" } + ], + errors: [MESSAGE_NEVER] + }, + { + code: "foo()\nfoo(\n\tx,\n\ty\n)", + output: "foo()\n\nfoo(\n\tx,\n\ty\n)", + options: [ + { blankLine: "always", prev: "*", next: "multiline-expression" } + ], + errors: [MESSAGE_ALWAYS] + }, + //---------------------------------------------------------------------- // break //---------------------------------------------------------------------- @@ -4443,3 +4481,4 @@ ruleTester.run("padding-line-between-statements", rule, { } ] }); + From ed9d086827e64e5fbb60c5e06387d0875a4a43c2 Mon Sep 17 00:00:00 2001 From: Lobstrosity Date: Tue, 30 May 2017 09:35:59 -0700 Subject: [PATCH 3/5] Docs: Add description of multiline-expression And minor tweaks to existing descriptions. --- docs/rules/padding-line-between-statements.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/rules/padding-line-between-statements.md b/docs/rules/padding-line-between-statements.md index 8c22b73685a..622c5cd6c9a 100644 --- a/docs/rules/padding-line-between-statements.md +++ b/docs/rules/padding-line-between-statements.md @@ -22,8 +22,8 @@ function foo() { This rule does nothing if no configuration. -A configuration is an object which has 3 properties; `blankLine`, `prev` and `next`. For example, `{ blankLine: "always", prev: "var", next: "return" }` is meaning "it requires one or more blank lines between a variable declaration and a `return` statement." -You can supply any number of configurations. If an statement pair matches multiple configurations, the last matched configuration will be used. +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." +You can supply any number of configurations. If a statement pair matches multiple configurations, the last matched configuration will be used. ```json { @@ -66,7 +66,8 @@ You can supply any number of configurations. If an statement pair matches multip - `"if"` is `if` statements. - `"import"` is `import` declarations. - `"let"` is `let` variable declarations. - - `"multiline-block-like"` is block like statements. This is the same as `block-like` type, but only the block is multiline. + - `"multiline-block-like"` is block like statements. This is the same as `block-like` type, but only if the block is multiline. + - `"multiline-expression"` is expression statements. This is the same as `expression` type, but only if the statement is multiline. - `"return"` is `return` statements. - `"switch"` is `switch` statements. - `"throw"` is `throw` statements. @@ -233,3 +234,4 @@ If you don't want to notify warnings about linebreaks, then it's safe to disable [disallowPaddingNewLinesBeforeExport]: http://jscs.info/rule/disallowPaddingNewLinesBeforeExport [requirePaddingNewlinesBeforeKeywords]: http://jscs.info/rule/requirePaddingNewlinesBeforeKeywords [disallowPaddingNewlinesBeforeKeywords]: http://jscs.info/rule/disallowPaddingNewlinesBeforeKeywords + From 0be5cc3531b8e85a513c078da8e37b144596dae3 Mon Sep 17 00:00:00 2001 From: Lobstrosity Date: Tue, 30 May 2017 09:44:41 -0700 Subject: [PATCH 4/5] Chore: Remove spurious newlines --- docs/rules/padding-line-between-statements.md | 1 - lib/rules/padding-line-between-statements.js | 1 - tests/lib/rules/padding-line-between-statements.js | 1 - 3 files changed, 3 deletions(-) diff --git a/docs/rules/padding-line-between-statements.md b/docs/rules/padding-line-between-statements.md index 622c5cd6c9a..c5fb8f6c6d8 100644 --- a/docs/rules/padding-line-between-statements.md +++ b/docs/rules/padding-line-between-statements.md @@ -234,4 +234,3 @@ If you don't want to notify warnings about linebreaks, then it's safe to disable [disallowPaddingNewLinesBeforeExport]: http://jscs.info/rule/disallowPaddingNewLinesBeforeExport [requirePaddingNewlinesBeforeKeywords]: http://jscs.info/rule/requirePaddingNewlinesBeforeKeywords [disallowPaddingNewlinesBeforeKeywords]: http://jscs.info/rule/disallowPaddingNewlinesBeforeKeywords - diff --git a/lib/rules/padding-line-between-statements.js b/lib/rules/padding-line-between-statements.js index 53b802e3d20..9e74c5dd912 100644 --- a/lib/rules/padding-line-between-statements.js +++ b/lib/rules/padding-line-between-statements.js @@ -591,4 +591,3 @@ module.exports = { }; } }; - diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index 470422085cf..f11561772a7 100644 --- a/tests/lib/rules/padding-line-between-statements.js +++ b/tests/lib/rules/padding-line-between-statements.js @@ -4481,4 +4481,3 @@ ruleTester.run("padding-line-between-statements", rule, { } ] }); - From 1dfa09539b9419e7c44ae0427c989f45ef90a789 Mon Sep 17 00:00:00 2001 From: Lobstrosity Date: Sat, 27 Jan 2018 19:43:14 -0700 Subject: [PATCH 5/5] Chore: Add additional test cases --- .../rules/padding-line-between-statements.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index 653ff2d51c1..597c4883500 100644 --- a/tests/lib/rules/padding-line-between-statements.js +++ b/tests/lib/rules/padding-line-between-statements.js @@ -550,6 +550,18 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "*", next: "multiline-expression" } ] }, + { + code: "() => {\n\tsomeArray.forEach(x => doSomething(x));\n\treturn theThing;\n}", + options: [ + { blankLine: "always", prev: "multiline-expression", next: "return" } + ] + }, + { + code: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\n\treturn theThing;\n}", + options: [ + { blankLine: "always", prev: "multiline-expression", next: "return" } + ] + }, //---------------------------------------------------------------------- // break @@ -2980,6 +2992,14 @@ ruleTester.run("padding-line-between-statements", rule, { ], errors: [MESSAGE_ALWAYS] }, + { + code: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\treturn theThing;\n}", + output: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\n\treturn theThing;\n}", + options: [ + { blankLine: "always", prev: "multiline-expression", next: "return" } + ], + errors: [MESSAGE_ALWAYS] + }, //---------------------------------------------------------------------- // break