Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support trailing commas in parameter declarations. Include newline after trailing comma. #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hubertta
Copy link

@hubertta hubertta commented Dec 18, 2022

Hi, the initial trailing comma support (#262) is very limited. Even the "expected" code in the test case is not valid (it expects the trailing comma in the same line as closing paren which is forbidden in Scala). The other problem with current master is that whenever the trailing comma appears in parameter declaration (eg. case class fields or function declaration), an assertion fails with java.lang.IllegalArgumentException: requirement failed: Parse tokens differ from expected. (SpecificFormatter.scala:54).

My commit fixes both of these issues.

  1. The assert is fixed by adding the trailing comma token back to the tokens field in classes ImportClause and ParamClause in AstNodes.scala. This also prevents the trailing comma from disappearing in the formatted code.
  2. I enforce a newline after a trailing comma even if the preference DanglingCloseParenthesis would not normally result in a newline. This is to prevent Scala compiler errors.

I added a bunch of test cases.

Please let me know if you can merge this and make a new release, so that this fix could be propagated to sbt-scalariform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant