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

requireConfig only if there's prettier config, and then also use .editorconfig #2402

Open
orenklein opened this issue Jan 30, 2022 · 9 comments

Comments

@orenklein
Copy link

Description of feature
requireConfig of only prettier config, and if it exists then also use .editorconfig (If editorconfig exist but prettier config does not exist, skip the file)

Is your feature request related to a problem? Please describe.
I have a monorepo with multiple project and a root editorconfig and I've also defined prettier.requireConfig: true. In a project that has prettier, formatting with prettier works perfectly and merges the root's editorconfig with the project prettierrc. However, few of the projects does not have a prettier config file, but they still get formatted with prettier (and its default settings) due to the root's editorconfig.

If configuring prettier.useEditorConfig: false, it solves the issue for the projects without prettier config, but the projects with prettier config does not use the editorconfig for formatting anymore.

Describe the solution you'd like
Perhaps adding another option to requireConfig named prettierOnly

Describe alternatives you've considered
Moving .editorconfig up to the specific projects and remove the root's editorconfig. You'd need to copy it to any new project, and changes will need to be copied across all the projects

@ntotten
Copy link
Member

ntotten commented Mar 29, 2022

I like the idea. I think we'd need to add a new config requireLocalConfig with values never, prettierOnly, prettierAndEditorConfig or something.

Happy to take a PR.

@papandreou
Copy link

This is a much better default in my opinion. I originally specified the requireConfig option to prevent this extension from kicking in when I'm working on eg. an open source project that might not have prettier enabled. There are way more projects that have an .editorconfig than a prettier configuration, so it's really annoying to suddenly get everything reformatted with prettier when I work on one of those.

@papandreou
Copy link

papandreou commented Apr 9, 2022

Looks like 5624041 intended to fix this? However, it doesn't seem to work like that in 9.5.0. When I'm working on a clone of https://github.com/andrewkeig/express-validation, every .js file gets reformatted on save, despite no prettier configuration being present. If I delete .editorconfig, it works (ie. doesn't reformat on save).

My relevant settings are:

{
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "prettier.requireConfig": true,
    "editor.formatOnSave": true
}
@papandreou
Copy link

From playing around with "Install another version" in vscode, this appears to be a regression introduced in 9.0.0. When I go back to 8.2.0, it works fine and just logs:

["INFO" - 9:16:32 AM] Extension Name: esbenp.prettier-vscode.
["INFO" - 9:16:32 AM] Extension Version: 8.2.0.
["INFO" - 9:16:34 AM] Formatting /home/andreas/work/express-validation/lib/index.js
["INFO" - 9:16:34 AM] Require config set to true and no config present. Skipping file.

whereas with 9.0.0 it goes:

["INFO" - 9:18:36 AM] Extension Name: esbenp.prettier-vscode.
["INFO" - 9:18:36 AM] Extension Version: 9.0.0.
["INFO" - 9:18:38 AM] Formatting file:///home/andreas/work/express-validation/lib/index.js
["INFO" - 9:18:38 AM] Using ignore file (if present) at /home/andreas/work/express-validation/.prettierignore
["INFO" - 9:18:38 AM] File Info:
{
  "ignored": false,
  "inferredParser": "babel"
}
["INFO" - 9:18:38 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 9:18:38 AM] Prettier Options:
{
  "filepath": "/home/andreas/work/express-validation/lib/index.js",
  "parser": "babel",
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 120,
  "endOfLine": "lf"
}
["INFO" - 9:18:38 AM] Formatting completed in 0.223ms.
@roottool
Copy link
Contributor

Looks like 5624041 intended to fix this? However, it doesn't seem to work like that in 9.5.0. When I'm working on a clone of andrewkeig/express-validation, despite no prettier configuration being present. If I delete .editorconfig, it works (ie. doesn't reformat on save).

@papandreou I don't know why, but the content of that commit has already been deleted at c75c9d3#diff-03d72b89529ec98f4ae054a185a457dee5e48b2c90ea69dd869496fbdc194998.

@papandreou
Copy link

Hmm, right! @aeschli @ntotten, was that an accident?

@callym
Copy link

callym commented Aug 12, 2022

Hey, is there any update on this? It's super annoying to always have to do Ctrl+K - S to work around this in certain projects :(

redoPop added a commit to redoPop/prettier-vscode that referenced this issue Sep 8, 2022
This commit fixes prettier#2402 by reintroducing changes from 5624041.
@github-actions
Copy link

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

@github-actions github-actions bot added the Stale label Apr 22, 2023
@papandreou
Copy link

This problem still exists in v9.12.0, please unmark as stale.

@github-actions github-actions bot removed the Stale label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants