use prettier's builtin configuration instead of falling back to VS Code configuration when locally installed prettier is used
jedwards1211 opened this issue · 3 comments
Summary
I made a PR to a project that uses prettier but has no .prettierrc
or .editorconfig
etc - it just formats with prettier's builtin default settings.
I have my Prettier Path set to ./node_modules/prettier
.
When I format on save, prettier-vscode
does not format as running ./node_modules/prettier
would, but instead with options from VS Code settings.
Consequently, my PR fails the formatting check in CI. This issue has come up dozens of times. I don't want to waste my time rerunning prettier manually and pushing a new commit because prettier-vscode
applies the wrong format. It should have applied the correct format to begin with.
I just don't get it...who wants to configure prettier format via VSCode settings? Beginners who are working on simple projects?
Well-maintained projects check code format in CI against their own config (or prettier defaults), so the config the prettier
CLI uses is the only one that seems relevant to me.
Surely this is the mainstream way of doing professional software development? Surely professional software developers are the primary target userbase for prettier-vscode
? I would think most devs would be satisfied with a prettier extension that has literally zero options, and just formats with the project's installed prettier with same config as if running the CLI.
Github Repository to Reproduce Issue
https://github.com/semantic-release/github
Steps To Reproduce:
- Clone the repo
- Install dependencies
- Open the repo in a new VSCode window
- Set Prettier Path to
./node_modules/prettier
- Set Prettier: Trailing Comma to
es5
- Enable Format on Save
- Open
lib/definitions/errors.js
- Type some whitespace and save
prettier-vscode
incorrectly strips away trailing commas in the file
Expected result
The file format is unchanged.
When prettier is locally installed, vscode-prettier
should format a file the same way as running prettier
manually in the project would, period.
I should not have to bug FOSS projects to add an explicit prettier config to work around this!
Actual result
prettier-vscode
falls back to an irrelevant config from VS Code settings.
Additional information
Feel free to attach a screenshot.
VS Code Version: 1.91.1
Prettier Extension Version: 10.4.0
OS and version: macOS Sonoma 14.4.1 (23E224)
Prettier Log Output
["INFO" - 11:12:59 AM] Formatting file:///Users/andy/gh/github/lib/definitions/errors.js
["INFO" - 11:12:59 AM] PrettierInstance:
{
"modulePath": "/Users/andy/gh/github/node_modules/prettier",
"importResolver": {},
"callMethodResolvers": {},
"currentCallMethodId": 2,
"version": "3.3.3"
}
["INFO" - 11:12:59 AM] Using ignore file (if present) at /Users/andy/gh/github/.prettierignore
["INFO" - 11:12:59 AM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 11:12:59 AM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 11:12:59 AM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"singleAttributePerLine": false,
"bracketSameLine": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"embeddedLanguageFormatting": "auto",
"vueIndentScriptAndStyle": false,
"filepath": "/Users/andy/gh/github/lib/definitions/errors.js",
"parser": "babel"
}
["INFO" - 11:12:59 AM] Formatting completed in 36ms.
The recommendation here is to set the prettier.requireConfig
to false. While your point is valid, this has been a heavily debated topic on what defaults are right for the extension and changing this would break many other uses. I personally always use prettier.requireConfig: true
for this exact reason.
I already have prettier.requireConfig
turned off. It seems like you don't understand what I mean, are you saying that would enable me to format on save in a project with no explicit config, and get the same format that prettier CLI uses? Because that doesn't work, it falls back to settings from VSCode, thus it's impossible for me to get that behavior right now. I hope your intent is not to say that we're just out of luck if we're contributing to a project that doesn't declare an explicit prettier config? I will have to open a feature request for an option to format like the CLI would even if there is no explicit config in the project.
prettier.requireConfig: true
isn't an acceptable workaround because then I still have to run prettier
manually. We shouldn't have to essentially disable prettier-vscode
in a project that uses...prettier
. This extension should give us a way to let prettier
itself determine the options -- it's pretty absurd that it's impossible to make the de facto official prettier extension do this right now.