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

Add option support for trailing comma in enums #354

Conversation

clementdessoude
Copy link
Contributor

@clementdessoude clementdessoude commented Jan 2, 2020

What changed with this PR:

  • Add options support for trailing commas in enum and arrays

Example

options:

--trailing-comma all
// Input
public enum Enum {
  ONE, TWO, THREE
}

// Output
public enum Enum {
  ONE, 
  TWO,
  THREE,
}
// Input
public class T {
  void t() {
    int[] ints = { 1, 2, 3, };
    int[] ints = { aVeryLongArrayValue, anotherVeryLongArrayValue, andYetAnotherVeryLongArrayValue };
  }
}

// Output
public class T {
  void t() {
    int[] ints = { 1, 2, 3 };
    int[] ints = {
      aVeryLongArrayValue,
      anotherVeryLongArrayValue,
      andYetAnotherVeryLongArrayValue,
    };
  }
}

Relative issues or prs:
Relative to #313, #314 and #319

cc @natdempk and @jhaber

@murdos
Copy link

murdos commented Jan 2, 2020

I'm not convinced that this is a feature we should support.
The prettier philosophy is to be opinionated and have few options, and I don't think a new option should be added here.

@clementdessoude
Copy link
Contributor Author

I agree with you that options should be added very carefully, and this one could create a precedent. However, it is one of the very few options provided by Prettier, so we might consider it anyway

@murdos
Copy link

murdos commented Jan 2, 2020

Ah, sorry! I was not aware that prettier already provided this option.
So definitely +1, we should indeed support it

@jhaber
Copy link
Contributor

jhaber commented Jan 2, 2020

I believe array initializers are the only other part of the language that support trailing commas, we may want this option to apply there too:
https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.6

A trailing comma may appear after the last expression in an array initializer and is ignored.

For example: int[] ints = { 1, 2, 3, }

@clementdessoude
Copy link
Contributor Author

Ok, so let's do this!

I added the trailing comma support in arrays too. I followed Prettier behavior which adds a comma (when the option is enabled) in arrays/objects only if they break

@clementdessoude clementdessoude merged commit 6794bda into jhipster:master Jan 3, 2020
@clementdessoude clementdessoude deleted the feature/options-trailing-commas branch January 3, 2020 21:37
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.

3 participants