Trying to format .rb files fails with "Error formatting document"
See original GitHub issueSummary
Trying to format .rb
files fails with:
["ERROR" - 12:59:23 PM] Error formatting document.
["INFO" - 12:59:23 PM] Formatting completed in 114.150958ms.
Github Repository to Reproduce Issue
https://github.com/tobilen/vscode-prettier-test
Steps To Reproduce:
- Check out
- Run
yarn
in repository - Install prettier-vscode
- Run formatter in
file.rb
Expected result
Successful formatting
Actual result
["INFO" - 1:47:29 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 1:47:29 PM] Extension Version: 4.6.0.
["INFO" - 1:47:29 PM] Loaded module 'prettier@1.19.1' from '/home/tobias/projects/vscode-prettier-test/node_modules/prettier'
["INFO" - 1:47:29 PM] Enabling prettier for languages
[
"css",
"graphql",
"html",
"javascript",
"javascriptreact",
"json",
"json5",
"jsonc",
"less",
"markdown",
"mdx",
"mongo",
"postcss",
"ruby",
"scss",
"typescript",
"typescriptreact",
"vue",
"yaml"
]
["INFO" - 1:47:29 PM] Enabling prettier for range supported languages
[
"graphql",
"javascript",
"javascriptreact",
"json",
"typescript",
"typescriptreact"
]
["INFO" - 1:48:56 PM] Formatting /home/tobias/projects/vscode-prettier-test/file.rb
["INFO" - 1:48:56 PM] Using ignore file (if present) at /home/tobias/projects/vscode-prettier-test/.prettierignore
["INFO" - 1:48:56 PM] Loaded module 'prettier@1.19.1' from '/home/tobias/projects/vscode-prettier-test/node_modules/prettier'
["INFO" - 1:48:56 PM] File Info:
{
"ignored": false,
"inferredParser": "ruby"
}
["INFO" - 1:48:56 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 1:48:56 PM] Prettier Options:
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"filepath": "/home/tobias/projects/vscode-prettier-test/file.rb",
"parser": "ruby"
}
["ERROR" - 1:48:56 PM] Error formatting document.
["INFO" - 1:48:56 PM] Formatting completed in 123.969153ms.
Additional information
Running yarn format
works without issue
Prettier Version:
Tried two configurations: prettier@1.19.1 @prettier/plugin-ruby@0.17.0
and
prettier@2.0.5 @prettier/plugin-ruby@0.18.2
VS Code Version:
Version: 1.45.0 Commit: d69a79b73808559a91206d73d7717ff5f798f23c Date: 2020-05-07T16:10:24.511Z Electron: 7.2.4 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Linux x64 5.4.0-29-generic snap
Prettier Extension Version:
4.6.0
Also tried 3.2
OS and version: Kubuntu 20.04
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How do I auto format Ruby or .erb files in VS Code?
I press ⌥ + ⇧ + F in Visual Studio Code for macOS, the shortcut to Format Document, to format a file called...
Read more >How to format .erb and .rb files in VSCode - Hi, I'm Aleksandar
In simple words, what can often happen in VSCode is that the default ruby formatter tries to (unsuccessfully) format the .erb files. Due...
Read more >FAQ: How to format your code - RStudio Community
Click the </> button! The code formatting button automatically adds special Markdown formatting symbols to whatever you selected. If you check ...
Read more >Automatically format and lint code with pre-commit - Interrupt
How to use pre-commit for automated linting, formatting, ... You'll probably want to add a .clang-format file to the base of your repo...
Read more >VS Code - You don't need a formatting extension (Prettier and ...
If you want to configure the default formatter for a JavaScript file that is open, right-click inside and select the option "Format document ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this was a very helpful change. my full log now tells me that my ruby version manager (i use asdf) doesn’t know which version to use. i assume this is because there is no
.tool-versions
file in the CWD of pretter-vscode:If you wanted to control which ruby version your extension uses, you could provide a
.tool-versions
file with the required version (and an.rbenv
file as well i suppose). For myself, the problem had a simple fix: setting the required ruby version globally with$ asdf global ruby 2.7.1
. Since my problem is now solved, i’m also fine with just closing the issue 👍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.