prettier-vscode
prettier-vscode copied to clipboard
requireConfig only if there's prettier config, and then also use .editorconfig
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
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.
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.
Looks like https://github.com/prettier/prettier-vscode/commit/5624041037fcf9c8c4612796dc4c083f0159b521 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
}
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.
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 https://github.com/prettier/prettier-vscode/commit/c75c9d3f29666d7c2fbceeee504c54c9a9e7f968#diff-03d72b89529ec98f4ae054a185a457dee5e48b2c90ea69dd869496fbdc194998.
Hmm, right! @aeschli @ntotten, was that an accident?
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 :(
This issue has been labeled as stale due to inactivity. Reply to keep this issue open.
This problem still exists in v9.12.0, please unmark as stale.