question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to format .rb files fails with "Error formatting document"

See original GitHub issue

Summary

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:

  1. Check out
  2. Run yarn in repository
  3. Install prettier-vscode
  4. 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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tobilencommented, Jul 2, 2020

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:

["INFO" - 8:42:53 AM] Extension Name: esbenp.prettier-vscode.
["INFO" - 8:42:53 AM] Extension Version: 5.1.2.
["INFO" - 8:42:53 AM] Loaded module 'prettier@1.19.1' from '/home/tobias/projects/vscode-prettier-test/node_modules/prettier'
["INFO" - 8:42:53 AM] Enabling prettier for languages
[
  "css",
  "graphql",
  "html",
  "javascript",
  "javascriptreact",
  "json",
  "json5",
  "jsonc",
  "less",
  "markdown",
  "mdx",
  "mongo",
  "postcss",
  "ruby",
  "scss",
  "typescript",
  "typescriptreact",
  "vue",
  "yaml"
]
["INFO" - 8:42:53 AM] Enabling prettier for range supported languages
[
  "graphql",
  "javascript",
  "javascriptreact",
  "json",
  "typescript",
  "typescriptreact"
]
["INFO" - 8:43:11 AM] Formatting /home/tobias/projects/vscode-prettier-test/file.rb
["INFO" - 8:43:11 AM] Using ignore file (if present) at /home/tobias/projects/vscode-prettier-test/.prettierignore
["INFO" - 8:43:11 AM] Loaded module 'prettier@1.19.1' from '/home/tobias/projects/vscode-prettier-test/node_modules/prettier'
["INFO" - 8:43:11 AM] File Info:
{
  "ignored": false,
  "inferredParser": "ruby"
}
["INFO" - 8:43:11 AM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration
["INFO" - 8:43:11 AM] 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" - 8:43:11 AM] Error formatting document.
"Error: asdf: No version set for command ruby\nyou might want to add one of the following in your .tool-versions file:\n\nruby 2.7.0\nruby 2.7.1\n\n\tat Object.module.exports [as parse] (/home/tobias/projects/vscode-prettier-test/node_modules/@prettier/plugin-ruby/src/parse.js:14:11)\n\tat Object.parse (/home/tobias/projects/vscode-prettier-test/node_modules/prettier/index.js:9739:19)\n\tat coreFormat (/home/tobias/projects/vscode-prettier-test/node_modules/prettier/index.js:13252:23)\n\tat format (/home/tobias/projects/vscode-prettier-test/node_modules/prettier/index.js:13510:73)\n\tat formatWithCursor (/home/tobias/projects/vscode-prettier-test/node_modules/prettier/index.js:13526:12)\n\tat /home/tobias/projects/vscode-prettier-test/node_modules/prettier/index.js:44207:15\n\tat Object.format (/home/tobias/projects/vscode-prettier-test/node_modules/prettier/index.js:44226:12)\n\tat t.default.<anonymous> (/home/tobias/.vscode/extensions/esbenp.prettier-vscode-5.1.2/dist/extension.js:1:58519)\n\tat Generator.next (<anonymous>)\n\tat s (/home/tobias/.vscode/extensions/esbenp.prettier-vscode-5.1.2/dist/extension.js:1:53437)"
["INFO" - 8:43:11 AM] Formatting completed in 182.714893ms.

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 👍

0reactions
github-actions[bot]commented, Sep 30, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found