prettier-vscode
prettier-vscode copied to clipboard
Formatter always uses an old prettier.config.js file
It's really nice to have an extension to lint my code but very recently my prettier VSCE stopped working correctly
Summary
After updating VSCode to the latest version (maybe irrelevant), the prettier extension keeps using an old file that I've modified a while ago, even after removing then restoring the file.
Github Repository to Reproduce Issue
Some private repo, I can invite.
Steps To Reproduce:
- Create a
prettier.config.jsin the root of the package then add content
module.exports = {
trailingComma: 'not-a-valid-value',
tabWidth: 2,
semi: false,
singleQuote: true,
};
- run
Format Documentin VSCode - It should fail for
Error: Invalid trailingComma value. Expected "all", "es5" or "none", but received "not-a-valid-value". - Edit the
prettier.config.js. SettrailingComma: 'es5', - Try step 2 and step 3 again.
- Reload VSCode window
- Try step 2 and step 3 again.
- Remove the file
- Try step 2 and the error is gone.
- Restore the file
- Try step 2 and step 3 again.
- Restart VSCode
- Try step 2 and step 3 again.
- Restart Computer
- Try step 2 and step 3 again.
Expected result
The extension reads prettier.config.js correctly
Actual result
prettier.config.js is not updating
Additional information
See error chapter
VS Code Version:
Version: 1.63.1 Commit: fe719cd3e5825bf14e14182fddeb88ee8daf044f Date: 2021-12-14T02:13:46.212Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Darwin arm64 21.1.0 Prettier Extension Version: v9.0.0
OS and version: macOS 12.0.1 (21A559)
Prettier Log Output
["INFO" - 4:04:55 AM] Formatting file://~/LocalDocs/project/habit-icu/prettier.config.js
["INFO" - 4:04:55 AM] Using config file at '~/LocalDocs/project/habit-icu/prettier.config.js'
["INFO" - 4:04:55 AM] Using ignore file (if present) at ~/LocalDocs/project/habit-icu/.prettierignore
["INFO" - 4:04:55 AM] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 4:04:55 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 4:04:55 AM] Prettier Options:
{
"filepath": "~/LocalDocs/project/habit-icu/prettier.config.js",
"parser": "babel",
"trailingComma": "es6",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
["ERROR" - 4:04:55 AM] Error formatting document.
["ERROR" - 4:04:55 AM] Invalid trailingComma value. Expected "all", "es5" or "none", but received "es6".
Error: Invalid trailingComma value. Expected "all", "es5" or "none", but received "es6".
at Normalizer._applyNormalization (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:8935:57)
at applyNormalization (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:8884:46)
at Normalizer.normalize (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:8890:5)
at normalizeOptions$3 (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:11101:33)
at Object.normalizeApiOptions (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:11230:10)
at normalize$1 (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:12604:28)
at formatWithCursor$1 (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:14265:46)
at ~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:59304:12
at Object.Success [as format] (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/node_modules/prettier/index.js:59324:12)
at t.default.<anonymous> (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/src/PrettierEditService.ts:434:45)
at Generator.next (<anonymous>)
at s (~/.vscode/extensions/esbenp.prettier-vscode-9.0.0/dist/extension.js:1:7872)
["INFO" - 4:04:55 AM] Formatting completed in 0.012ms.```
I'm using an Apple Silicon
also tried disable-reload-enable the extension
Update: After removing all contents in the file and cut-paste it back, it works correctly.
It seems like this is resolved.
Hi @ntotten. Sorry for not making it very clear. It's not resolved yet.
Current workaround
Removing all contents, save, and paste it back.
This is the more difficult than editing the file and not the way how it was designed to work.
So I think it's still a bug?
Current workaround
update work around
I use prettier.config.js now. it works correctly
This may have been related to #2370. Can you check if this still happens in 9.2.0.
Just checked with v9.2.0 and the problem is gone.
The problem only occurs with prettier.config.js but not with .prettierrc.
I'm using create-react-app without eject. (maybe worths mentioning)
However when I set the tabWidth to 1 or 3 during the test, it always reads 2 (seen in the "output" tab), setting it to 2,4,5 was fine. Maybe it's designed like this?
Also when formatting (v9.2.0) a .md file withprettier.config.js like this
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true,
};
In vscode "output" it shows "tabWidth": 4,. I checked the Using config file at ... and the path was correct.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.