Open5

【VSCode環境構築】Rubyに一から入門してみる

tf63tf63

Dockerfile & Dev Container

ベースイメージ

  • 安定のdebian slimで

https://hub.docker.com/_/ruby

Dockerfile

  • 必要なパッケージが分からないので最小限
  • 必要に応じて拡張

https://github.com/tf63/ruby-playground/blob/main/Dockerfile

VSCode Dev Container

  • あとで.vscode/extensionsをこっちに移しておく
  • (devcontainer.jsonから.vscode/extensions読み込めたら嬉しいんだけどね)

https://github.com/tf63/ruby-playground/blob/main/.devcontainer/devcontainer.json

tf63tf63

Formatter

RubyわからないのでStandardを使う

選択肢A. Rubocop

  • デファクトなlinter & formatterっぽい

https://zenn.dev/razokulover/articles/c49ca1cb566ddb

選択肢B. Standard

  • rubocop上で動作する設定不要のlinter & formatter
  • ruby-lspが自動で読み込んでくれるらしい (CodeActionが動作する)

If you don't see your preferred editor above, Standard Ruby also offers robust language server support, in two ways, both included with the standard gem:

  1. A Ruby LSP add-on, which (if the standard gem is in your Gemfile) will be loaded automatically

https://github.com/standardrb/standard

tf63tf63

Rake

  • Ruby DSLで書けるmakeみたいなビルドツール
  • Rakefileにコマンドを登録する

https://github.com/ruby/rake

Standardを実行

  • Rakefileに追記
  • rake standard, rake standard:fix, rake standard:fix_unsafelyとかで実行できる
require "standard/rake"

npmスクリプトを実行

  • rake formatを登録
task :format do
  sh "npm run format"
end

最終形

  • 面倒なのでstandardはshで実行
  • rake -Tで登録されているコマンドを確認できる

https://github.com/tf63/ruby-playground/blob/main/Rakefile