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

Unknown 'es5' option for 'trailingComma' #652

Closed
ArLau opened this issue Mar 4, 2024 · 5 comments · Fixed by #655
Closed

Unknown 'es5' option for 'trailingComma' #652

ArLau opened this issue Mar 4, 2024 · 5 comments · Fixed by #655

Comments

@ArLau
Copy link

ArLau commented Mar 4, 2024

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:

  • to use all globally and override with es5 for e.g. ts files
  • to override the trailingComma with all for java files

but this still fails with the same error message.

@Mahtis
Copy link

Mahtis commented Mar 5, 2024

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

@jtkiesel
Copy link
Contributor

jtkiesel commented Mar 5, 2024

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
Copy link
Contributor

jtkiesel commented Mar 6, 2024

@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
Copy link

Mahtis commented Mar 6, 2024

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
Copy link
Author

ArLau commented Mar 7, 2024

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

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 a pull request may close this issue.

3 participants