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

[v3] plugins declared in .prettierrc are not loaded on directory #15079

Closed
JounQin opened this issue Jul 11, 2023 · 12 comments · Fixed by #15433
Closed

[v3] plugins declared in .prettierrc are not loaded on directory #15079

JounQin opened this issue Jul 11, 2023 · 12 comments · Fixed by #15433
Labels
area:cli Issues with Prettier's Command Line Interface locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@JounQin
Copy link
Member

JounQin commented Jul 11, 2023

Environments:

  • Prettier Version: 3.0.0
  • Running Prettier via: CLI
  • Runtime: v18.16.0
  • Operating System: Linux
  • Prettier plugins (if any): prettier-plugin-sh

Steps to reproduce:

un-ts/prettier#273 (comment)

Expected behavior:

Like prettier v2, .sh files should be checked

Actual behavior:

.sh files are not checked


After debugging, getSupportedFilesGlob here

function getSupportedFilesGlob() {
if (!supportedFilesGlob) {
const extensions = context.languages.flatMap(
(lang) => lang.extensions || [],
);
const filenames = context.languages.flatMap(
(lang) => lang.filenames || [],
);
supportedFilesGlob = `**/{${[
...extensions.map((ext) => "*" + (ext[0] === "." ? ext : "." + ext)),
...filenames,
]}}`;
}
return supportedFilesGlob;
}
}

does not resolve .sh files correctly.

@fisker
Copy link
Member

fisker commented Jul 11, 2023

It's a known issue, are you sure it works in v2?

@JounQin
Copy link
Member Author

JounQin commented Jul 11, 2023

@fisker I tried @devcrev's reproduction at https://github.com/devcrev/p-sh-old, it works on v2.

> [email protected] format
> prettier --check .

Checking formatting...
[warn] level-0/go.sh
[warn] level-0/hello.sh
[warn] level-0/level-1/another.sh
[warn] level-0/level-1/library.js
[warn] level-0/level-1/runme.sh
[warn] level-0/program.js
[warn] Code style issues found in 6 files. Forgot to run Prettier?

@fisker fisker added the status:needs discussion Issues needing discussion and a decision to be made before action can be taken label Jul 11, 2023
@JounQin
Copy link
Member Author

JounQin commented Jul 11, 2023

Could be related to Plugin search feature has been removed?

@tylervz
Copy link

tylervz commented Jul 11, 2023

I am having this same issue with the .xml files and .properties files in my project. I'm using plugin-xml version 3.1.0 and the latest commit of prettier-plugin-properties (npm install -D [email protected]:eemeli/prettier-plugin-properties.git#0c7072dae2006c0d0a588f70b19940390a50add1)

@fisker fisker added status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug and removed status:needs discussion Issues needing discussion and a decision to be made before action can be taken labels Jul 11, 2023
@Jeto143
Copy link

Jeto143 commented Jul 14, 2023

I've noticed that you now need to specify something like **/*.* (rather than a folder, such as .) to the CLI command in order to parse files that have been registered by a plugin declared in the prettier configuration file. This wasn't the case with 2.*. It might be related to #14759, as @JounQin pointed out.

Related issue I've opened in a plugin's repo (as I thought it no longer worked): shufo/prettier-plugin-blade#213

@devcrev
Copy link

devcrev commented Jul 14, 2023

The current documentation seems to indicate that the behavior should be as it was in version 2.

image

@devcrev
Copy link

devcrev commented Jul 14, 2023

This package.json script for v3 does what I want and what v2 did with prettier . --check:

"scripts": {
   "format": "prettier './**/*' --check --ignore-unknown"
 },

@dummdidumm
Copy link

I'm observing this bug, too. Running npx prettier --write . will ignore any .svelte files, running npx prettier --plugin prettier-plugin-svelte --write . works. My debugging so far lead my to believe that this issue is with the file glob. The file glob is created from the context that is created at the start of the CLI run. If I pass the plugin, the context contains the info that Svelte files are eligible for formatting so the file glob includes Svelte files, else it doesn't.

So the fix is either to adjust the context creation to also search for a .prettierrc starting from process.cwd() and load any plugins from there, or to widen the file glob to include all files, not just the ones the context says it knows about.

@thorn0
Copy link
Member

thorn0 commented Jul 21, 2023

@dummdidumm Indeed. Config files are resolved for each processed file, which is too late.

@thorn0 thorn0 added type:bug Issues identifying ugly output, or a defect in the program area:cli Issues with Prettier's Command Line Interface and removed status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug labels Jul 21, 2023
@sosukesuzuki
Copy link
Member

I'll work on this

legnaleurc added a commit to legnaleurc/dvd that referenced this issue Aug 27, 2023
archlinux-github pushed a commit to archlinux/neoasknot that referenced this issue Aug 31, 2023
Need to pass `--plugin` options to `prettier` until
prettier/prettier#15079 is resolved.
justuswilhelm added a commit to jwpconsulting/projectify-frontend that referenced this issue Sep 4, 2023
Partially reverts 5e3e77a

Prettier v3 has a problem where it does not run plugins correctly:

prettier/prettier#15079

Until this is resolved we manually add prettier as a plugin to our invocations.

This commit also fixes the since then neglected lints
justuswilhelm added a commit to jwpconsulting/projectify-frontend that referenced this issue Sep 4, 2023
Partially reverts 5e3e77a

Prettier v3 has a problem where it does not run plugins correctly:

prettier/prettier#15079

Until this is resolved we manually add prettier as a plugin to our invocations.

This commit also fixes the since then neglected lints
justuswilhelm added a commit to jwpconsulting/projectify-frontend that referenced this issue Sep 4, 2023
Partially reverts 5e3e77a

Prettier v3 has a problem where it does not run plugins correctly:

prettier/prettier#15079

Until this is resolved we manually add prettier as a plugin to our invocations.

This commit also fixes the since then neglected lints
@sdellysse
Copy link

Just chiming in that I was just bit by this trying to get .sh files to be formatted with prettier-plugin-sh. I have to do prettier --plugin=prettier-plugin-sh . to get it working. I'm willing to take a stab at fixing this, but I have no knowledge of the codebase. Would anyone have any pointers as to where to start debugging this issue?

atjn added a commit to Ecdar/Ecdar-GUI-Web that referenced this issue Sep 22, 2023
None of our svelte files were formatted because of this bug: prettier/prettier#15079
@sosukesuzuki
Copy link
Member

@sdellysse I'm working on this, please wait. #15433

atjn added a commit to Ecdar/Ecdar-GUI-Web that referenced this issue Sep 29, 2023
* Ensure prettier follows .editorconfig
* Fix prettier plugin bug (prettier/prettier#15079)
yongrenjie added a commit to Urban-Analytics-Technology-Platform/Urban-Analytics-Technology-Platform.github.io that referenced this issue Oct 27, 2023
Right now, prettier 3.0 doesn't correctly format astro files using the
plugin. This will be fixed in 3.1 but it hasn't been released yet. If
we upgrade it means that we don't have to specify **/*.astro in the
invocation of prettier.

withastro/prettier-plugin-astro#358
prettier/prettier#15079
prettier/prettier#15433
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Dec 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:cli Issues with Prettier's Command Line Interface locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
9 participants