prettier / prettier/plugin-php

[Bug] Formatting not applying outside of node root

Abierto
#2,414 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
PHP
Estrellas
1.9k
Forks
139
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con los archivos .prettierignore y .prettierrc.json en buildchain y, después, compara los comandos registrados para ../cms/app.php y app.php. Reproduce la diferencia con las versiones indicadas de Node, Prettier y el plugin de PHP; se considera terminado cuando los archivos PHP fuera de la raíz de Node reciben de forma coherente el plugin configurado y las opciones de formato.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
node.js, php
Área
tooling
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.