prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

Formatter always uses an old prettier.config.js file

Open PabloLION opened this issue 3 years ago • 9 comments

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:

  1. Create a prettier.config.js in the root of the package then add content
module.exports = {
  trailingComma: 'not-a-valid-value',
  tabWidth: 2,
  semi: false,
  singleQuote: true,
};
  1. run Format Document in VSCode
  2. It should fail for Error: Invalid trailingComma value. Expected "all", "es5" or "none", but received "not-a-valid-value".
  3. Edit the prettier.config.js. Set trailingComma: 'es5',
  4. Try step 2 and step 3 again.
  5. Reload VSCode window
  6. Try step 2 and step 3 again.
  7. Remove the file
  8. Try step 2 and the error is gone.
  9. Restore the file
  10. Try step 2 and step 3 again.
  11. Restart VSCode
  12. Try step 2 and step 3 again.
  13. Restart Computer
  14. 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.```

PabloLION avatar Dec 15 '21 03:12 PabloLION

I'm using an Apple Silicon

PabloLION avatar Dec 15 '21 03:12 PabloLION

also tried disable-reload-enable the extension

PabloLION avatar Dec 15 '21 03:12 PabloLION

Update: After removing all contents in the file and cut-paste it back, it works correctly.

PabloLION avatar Dec 15 '21 03:12 PabloLION

It seems like this is resolved.

ntotten avatar Jan 01 '22 16:01 ntotten

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?

PabloLION avatar Jan 02 '22 12:01 PabloLION

Current workaround

update work around

I use prettier.config.js now. it works correctly

PabloLION avatar Jan 02 '22 13:01 PabloLION

This may have been related to #2370. Can you check if this still happens in 9.2.0.

ntotten avatar Jan 29 '22 14:01 ntotten

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?

PabloLION avatar Jan 29 '22 22:01 PabloLION

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.

PabloLION avatar Jan 31 '22 12:01 PabloLION

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.

github-actions[bot] avatar Nov 19 '22 00:11 github-actions[bot]