plugin-php: Explicit `trailingComma: "es5"` value in config causes "Invalid trailingComma ..." error

Prettier 1.16.4

PHP Plugin 0.10.2

I have an existing project to which I’m wanting to process PHP files using this plugin. After installing the plugin, when I try to process non-PHP files, Prettier tells me Invalid trailingComma value. Expected "all", "none", "php5" or "php7.2", but received "es5".

I already have the following .prettierrc:

{
  "printWidth": 80,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": false,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
  "arrowParens": "avoid",
  "requirePragma": false,
  "insertPragma": false,
  "proseWrap": "preserve"
}

1. Works as expected, before installing the plugin:

Command:

prettier 'src/app.js'  --write --loglevel debug --config .prettierrc

Output:

[debug] normalized argv: {"_":["src/app.js"],"color":true,"editorconfig":true,"write":true,"loglevel":"debug","config":".prettierrc","plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","debug-repeat":0,"config-precedence":"cli-override"}
[debug] load config file from '.prettierrc'
[debug] loaded options `{"printWidth":80,"tabWidth":2,"useTabs":false,"semi":true,"singleQuote":false,"trailingComma":"es5","bracketSpacing":true,"jsxBracketSameLine":false,"arrowParens":"avoid","requirePragma":false,"insertPragma":false,"proseWrap":"preserve"}`
[debug] applied config-precedence (cli-override): {"arrowParens":"avoid","bracketSpacing":true,"insertPragma":false,"jsxBracketSameLine":false,"printWidth":80,"proseWrap":"preserve","requirePragma":false,"semi":true,"singleQuote":false,"tabWidth":2,"trailingComma":"es5","useTabs":false}
src/app.js 39ms

2. Install plugin

yarn global add @prettier/plugin-php

yarn global v1.13.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
warning "@prettier/plugin-php@0.10.2" has no binaries
✨  Done in 5.33s.

3. Breaks, after installing plugin:

prettier 'src/app.js'  --write --loglevel debug --config .prettierrc

Output

[debug] normalized argv: {"_":["src/app.js"],"color":true,"editorconfig":true,"write":true,"loglevel":"debug","config":".prettierrc","plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","debug-repeat":0,"config-precedence":"cli-override"}
[debug] load config file from '.prettierrc'
[debug] loaded options `{"printWidth":80,"tabWidth":2,"useTabs":false,"semi":true,"singleQuote":false,"trailingComma":"es5","bracketSpacing":true,"jsxBracketSameLine":false,"arrowParens":"avoid","requirePragma":false,"insertPragma":false,"proseWrap":"preserve"}`
[error] Unable to expand glob patterns: src/app.js !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/**

[error] Invalid trailingComma value. Expected "all", "none", "php5" or "php7.2", but received "es5".

Against PHP files, it works as expected after adding this to .prettierrc:

  "overrides": [
    {
      "files": "*.php",
      "options": {
        "tabWidth": 4,
        "trailingComma": "php7.2",
      }
    }
  ]

Expected behavior:

  • My existing config should just work after installing the plugin, but it appears to be trying to process .js files as PHP.
  • The plugin should know that .js files aren’t .php files and ignore them.

Sorry if I’m not understanding something with setup, but the docs don’t suggest I need to do much more than install and go.

  • Am I supposed to set up two separate scripts to process PHP separately from other files?

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Would a simple PR with trailingCommaPHP work?

Okay, so when updating my .prettierrc for this:

{
  "trailingComma": "es5",
  "pluginSearchDirs": ["./web/app"]
}

I “counter” the plugins autoloading behavior and I got ESLint + Prettier working: Sélection_391

Ok, let’s fix it

@jasonschock oh, looks you should use overrides right now https://github.com/prettier/prettier/blob/master/docs/configuration.md#configuration-overrides,

It is bug in prettier, not in plugin, prettier should respect same options for plugins, i think.

/cc @ikatyang What do you think?

I noticed the Ruby plugin recently changed the option name to addTrailingCommas.

Perhaps needed for this plugin as well?