Format Ruby with VS Code

Indispensable for writing a program (?). format So, this time I'm talking about formatting what was written in Ruby. (* Since it is operated with mac os and made a note, the shortcut etc. may be slightly different)

Run shortcut

First, click the shortcut normally (alt + shift + F. Not ctrl) スクリーンショット 2020-06-17 13.39.28.png By default ruby doesn't format it.

By the way, I have Prettier installed as a formatter, but it seems that I can only format web languages such as html, js, ts, css and their surroundings (?). [^ a] (I just noticed that this php will also be formatted ...)

[^ a]: There seems to be a ruby version of prettier by volunteers. Maybe I'll try this too

Install ruby formatter

So let's "install the formatter". (It's hard to hit a machete, only "ta" becomes hiragana)

When I look it up, Rufo seems to be good? Then, immediately install something called "Rufo --Ruby formatter". スクリーンショット 2020-06-17 13.49.08.png

Well, as you can see from the details, it seems that you need to install rufo.

install rufo

Just hit "gem install rufo" in the terminal. ... A permission error has occurred. 「While executing gem ... (Gem::FilePermissionError)」 (I restarted the terminal without making a note. Only this one line remains)

Apparently the cause is using ruby of the system. So I use ruby which is not a system.

Reference site: What to do when a permission error occurs in gem install

Then run again with this

% gem install rufo
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

Why isn't it w I thought, I didn't run "rbenv global X.X.X". Let's read in order () When I try to execute it again, the installation is completed successfully! Then restart vscode.

At the end

The number of tabs is 2 ... I'm a little worried about whether to use it.

Recommended Posts

Format Ruby with VS Code
Lombok with VS Code
Docker management with VS Code
Hello World with VS Code!
Spring Boot programming with VS Code
Java build with mac vs code
Getting Started with Docker with VS Code
Prepare Java development environment with VS Code
Try using Spring Boot with VS Code
Writing code Ruby
Using Gradle with VS Code, build Java → run
Create Spring Boot environment with Windows + VS Code
Try debugging a Java program with VS Code
Build a Java development environment with VS Code
Install Ruby 3.0.0 with asdf
Getting Started with Ruby
Automate format with maven-formatter
Format JSON with org.json
11th, Classification with Ruby
Evolve Eevee with Ruby
[Ruby] Basic code list. Keep the basics with examples
Build Java development environment with VS Code on Mac
[Ruby] Generate a concatenated QR code with rqrcode (Knowledge)
Introduce JavaFX 15 and do GUI development with VS Code
[Ruby] Generate a concatenated QR code with rqrcode (Practice)
Build Java development environment with WSL2 Docker VS Code
How to build Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
Beginners create Spring Tools Suite environment with VS Code
Created RSS / Atom format sitemap with Ruby on Rails
Ruby version switching with rbenv
Run VS Code on Docker
Solve Google problems with Ruby
I tried DI with Ruby
GraphQL Client starting with Ruby
Ruby: Send email with Starttls
Leap year judgment with Ruby
Integer check method with ruby
Learn Ruby with AtCoder Beginners Selection [Coins] Answer with short code
[Easy] How to automatically format Ruby erb file with vsCode
Create a VS Code Plugin.
Java web application development environment construction with VS Code (struts2)
Ruby Learning # 8 Working With String
[Rails] Specify format with link_to
Try debugging natural language processing on Windows. with VS Code
[Ruby] problem with if statement
Reduce verbose code with Lombok
Studying with CodeWar (ruby) ⑤ proc
A memo to start Java programming with VS Code (2020-04 version)
Use Ruby with Google Colab
[Ruby] REPL-driven development with pry
Getting Started with Ruby Modules
[ruby] Method call with argument
Make Code Spell Checker compatible with the Ruby language that points out spelling mistakes in VS Code
Summary of steps for developing in Docker container with VS Code
Understand code coverage with Rspec, the Ruby on Rails test framework
Until you run Hello World of JavaFX with VS Code + Gradle
Settings to delete unused Java imports when saving with VS Code
Building a haskell environment with Docker + VS Code on Windows 10 Home
How to open a script file from Ubuntu with VS code
Use PlantUML with Visual Studio Code