You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/10/06 22:31:40 UTC
[royale-compiler] 03/04: formatter: block close before paren close
or comma does not require a new line
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit bf83e8f06799519ccfaf316b657b409c236e0723
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 14:43:22 2021 -0700
formatter: block close before paren close or comma does not require a new line
---
.../org/apache/royale/formatter/FORMATTER.java | 4 +-
.../royale/formatter/TestFunctionDeclaration.java | 50 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
index 4b542eb..02dec76 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -899,7 +899,9 @@ class FORMATTER {
blockStack.remove(blockStack.size() - 1);
}
if (!(item instanceof ObjectLiteralBlockStackItem)
- && (nextToken == null || nextToken.getType() != ASTokenTypes.TOKEN_SEMICOLON)) {
+ && (nextToken == null || (nextToken.getType() != ASTokenTypes.TOKEN_SEMICOLON
+ && nextToken.getType() != ASTokenTypes.TOKEN_PAREN_CLOSE
+ && nextToken.getType() != ASTokenTypes.TOKEN_COMMA))) {
numRequiredNewLines = Math.max(numRequiredNewLines, 1);
}
}
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
index 50729e2..a15fa8d 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
@@ -270,4 +270,54 @@ public class TestFunctionDeclaration extends BaseFormatterTests {
// @formatter:on
result);
}
+
+ @Test
+ public void testWrappedInParentheses() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatText(
+ // @formatter:off
+ "(function myFunction(...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "});",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "(function myFunction(...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "});",
+ // @formatter:on
+ result);
+ }
+
+ @Test
+ public void testAsArgument() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatText(
+ // @formatter:off
+ "identifier(function myFunction(...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "}, 123.4);",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "identifier(function myFunction(...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "}, 123.4);",
+ // @formatter:on
+ result);
+ }
}