jhipster / prettier-java

Prettier Java Plugin
http://www.jhipster.tech/prettier-java/
Apache License 2.0
1.08k stars 103 forks source link

Unknown 'es5' option for 'trailingComma' #652

Closed ArLau closed 6 months ago

ArLau commented 7 months ago

Concerns Prettier-Java 2.6.0

Version 2.6.0 fails to format files if the trailingComma option is set to es5 in .prettierrc.yaml. According to https://prettier.io/docs/en/options.html#trailing-commas es5 is a valid option and it worked with version 2.5.0 of Prettier-Java.

Now we get:

$ prettier "**/*.(yaml|yml|md|ts|tsx|java)" --write
[error] Invalid trailingComma value. Expected "all" or "none", but received "es5".

Our configuration (.prettierrc.yaml) looks like this:

tabWidth: 4
trailingComma: 'es5'

plugins:
  - prettier-plugin-java

overrides:
  - files:
      - '*.yaml'
      - '*.yml'
    options:
      tabWidth: 2
  - files: '*.java'
    options:
      printWidth: 160
  - files: '*.md'
    options:
      printWidth: 80
      tabWidth: 2
  - files:
      - '*.ts'
      - '*.js'
      - '*.tsx'
      - '*.jsx'
    options:
      printWidth: 150

We also tried:

but this still fails with the same error message.

Mahtis commented 7 months ago

We are experiencing the exact same issue and cannot update to the latest version because of this.

jtkiesel commented 7 months ago

Thank you for reporting this! This was likely caused by #628, specifically this line. I hadn't realized that officially adding trailingComma to our plugin's options would cause Prettier to do this kind of validation, but it makes sense that it does. I'll add es5 as a valid option, and determine whether its behavior in 2.5.0 was identical to all or none.

jtkiesel commented 6 months ago

@ArLau You may be able to work around this issue by only using the prettier-java plugin for .java files. For example, changing your .prettierrc.yaml to something like this:

tabWidth: 4
trailingComma: 'es5'

overrides:
  - files:
      - '*.yaml'
      - '*.yml'
    options:
      tabWidth: 2
  - files: '*.java'
    options:
      plugins:
        - prettier-plugin-java
      printWidth: 160
      trailingComma: all
  - files: '*.md'
    options:
      printWidth: 80
      tabWidth: 2
  - files:
      - '*.ts'
      - '*.js'
      - '*.tsx'
      - '*.jsx'
    options:
      printWidth: 150
Mahtis commented 6 months ago

Thank you! This does seem to work. I tried a similar solution before but I realize I was putting the plugins directly under the overrides object, when it needed to be defined under the options.

ArLau commented 6 months ago

@jtkiesel Your suggestion works for us. Thanks a lot for your quick answer and your work on this plugin.