prettier / prettier/plugin-php

[Bug] Formatting not applying outside of node root

Open
#2,414 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.9k
Forks
139
PR merge metrics
No merged PRs in 30d

Description

My projects separates the PHP and Node apps like so

/
├── cms/
│   └── composer.json
│   └── vendor/
│   └── etc...
├── buildchain/
│   └── package.json
│   └── node_modules/
│   └── .prettierrc.json
│   └── .prettierignore
│   └── .tsconfig
│   └── src/
│       └── ts/
│       └── css/
│   └── etc...
└─── .editorconfig

I want to format files in cms using cd buildchain && npx prettier -w .. which I managed to get working using this .prettierignore

package.json
package-lock.json

../*
!../cms
../cms/*
!../cms/**/*.php
!../cms/**/*.twig
!../cms/**/*.ts # For demonstration
../cms/vendor

This works fine with typescript files eg.

/var/www/html/buildchain$ npx prettier -c ../cms/app.ts --config .prettierrc.json --log-level debug
[debug] normalized argv: {"":["../cms/app.ts"],"cache":false,"color":true,"editorconfig":true,"config":".prettierrc.json","logLevel":"debug","configPrecedence":"cli-override","debugRepeat":0,"ignorePath":[".gitignore",".prettierignore"],"plugins":[],"check":true,"_":["../cms/app.ts"],"__raw":{"_":["../cms/app.ts"],"cache":false,"c":true,"color":true,"editorconfig":true,"config":".prettierrc.json","log-level":"debug","config-precedence":"cli-override","debug-repeat":0,"ignore-path":[".gitignore",".prettierignore"],"plugin":[]}}
Checking formatting...
[debug] load config file from '.prettierrc.json'
[debug] loaded options `{"useTabs":false,"tabWidth":2,"endOfLine":"lf","plugins":["@prettier/plugin-php"],"singleQuote":true,"printWidth":100}`
[debug] applied config-precedence (cli-override): {"singleQuote":true,"endOfLine":"lf","plugins":["@prettier/plugin-php"],"printWidth":100,"tabWidth":2,"useTabs":false}
[warn] ../cms/app.ts
[warn] Code style issues found in the above file. Run Prettier with --write to fix.

It doesn't work for PHP files though

/var/www/html/buildchain$ npx prettier -c ../cms/app.php --config .prettierrc.json --log-level debug
[debug] normalized argv: {"":["../cms/app.php"],"cache":false,"color":true,"editorconfig":true,"config":".prettierrc.json","logLevel":"debug","configPrecedence":"cli-override","debugRepeat":0,"ignorePath":[".gitignore",".prettierignore"],"plugins":[],"check":true,"_":["../cms/app.php"],"__raw":{"_":["../cms/app.php"],"cache":false,"c":true,"color":true,"editorconfig":true,"config":".prettierrc.json","log-level":"debug","config-precedence":"cli-override","debug-repeat":0,"ignore-path":[".gitignore",".prettierignore"],"plugin":[]}}
Checking formatting...
All matched files use Prettier code style!

It does however work fine when the same file is located in buildchain

/var/www/html/buildchain$ npx prettier -c app.php --config .prettierrc.json --log-level debug
[debug] normalized argv: {"":["app.php"],"cache":false,"color":true,"editorconfig":true,"config":".prettierrc.json","logLevel":"debug","configPrecedence":"cli-override","debugRepeat":0,"ignorePath":[".gitignore",".prettierignore"],"plugins":[],"check":true,"_":["app.php"],"__raw":{"_":["app.php"],"cache":false,"c":true,"color":true,"editorconfig":true,"config":".prettierrc.json","log-level":"debug","config-precedence":"cli-override","debug-repeat":0,"ignore-path":[".gitignore",".prettierignore"],"plugin":[]}}
Checking formatting...
[debug] load config file from '.prettierrc.json'
[debug] loaded options `{"useTabs":false,"tabWidth":4,"endOfLine":"lf","plugins":["@prettier/plugin-php"],"singleQuote":true,"printWidth":100}`
[debug] applied config-precedence (cli-override): {"singleQuote":true,"endOfLine":"lf","plugins":["@prettier/plugin-php"],"printWidth":100,"tabWidth":4,"useTabs":false}
[warn] app.php
[warn] Code style issues found in the above file. Run Prettier with --write to fix.

Versions

  • node 20.15.0
  • prettier 3.4.2
  • @prettier/plugin-php 0.22.2

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the .prettierignore and .prettierrc.json files in buildchain, then compare the logged commands for ../cms/app.php and app.php. Reproduce the difference with the listed Node, Prettier, and PHP plugin versions; done means PHP files outside the Node root receive the configured plugin and formatting options consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.