Skip to content

Instantly share code, notes, and snippets.

@leonchangzhy
Created December 12, 2022 06:19
Show Gist options
  • Save leonchangzhy/20900af7a77228e5af6912da7d2f65d1 to your computer and use it in GitHub Desktop.
Save leonchangzhy/20900af7a77228e5af6912da7d2f65d1 to your computer and use it in GitHub Desktop.
.devcontainer configuration for ruby on rails linting and formatting

VScode devcontainer for coding Ruby on Rails Project

How to use

  1. Clone the gist
  2. Move the cloned folder to the root of your project
  3. rename the folder to .devcontainer
  4. Place the .devcontainer folder at the root dir of your project
  5. Make sure your VScode installed the Remote Development Plugin
  6. Click on the left bottom corner of your vscode to open the menu of Remote Development Plugin
  7. Click Reopen in Container
  8. After the successful build, you can start coding!
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/ruby-rails
{
"name": "Ruby on Rails (Community)",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update 'VARIANT' to pick a Ruby version: 3, 3.1, 3.0, 2, 2.7, 2.6, 2.5
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3-bullseye",
"NODE_VERSION": "16"
}
},
// Mount the .gitignore_global
"mounts": [
"source=${localEnv:HOME}/.gitignore_global,target=/home/vscode/.gitignore_global,type=bind,consistency=cached"
],
// Prevent mount failure, create a new file when file doesn't exist.
"runArgs": ["--network=host"],
"postAttachCommand": "bundle install --gemfile=.devcontainer/Gemfile",
// Set *default* container specific settings.json values on container create.
"settings": {
"ruby.lint": {
"rubocop": {
"lint": true,
"rails": true,
"configFilePath": ".rubocop.yml"
}
},
"ruby.format": "rubocop",
"files.associations": {
"Gemfile": "ruby"
},
"[ruby]": {
"editor.defaultFormatter": "misogi.ruby-rubocop",
"editor.formatOnSave": true
},
"[yaml, yml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"prettier": {
"configPath": ".devcontainer/prettierrc.yaml"
},
"cSpell.enableFiletypes": ["ruby", "slim"],
"cSpell.ignorePaths": [".devcontainer"],
"cSpell.ignoreRegExpList": ["/gkc_hash_code.*/g"]
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"rebornix.ruby",
"wingrunr21.vscode-ruby",
"castwide.solargraph",
"misogi.ruby-rubocop",
"hridoy.rails-snippets",
"ninoseki.vscode-gem-lens",
"eamodio.gitlens",
"kaiwood.endwise",
"esbenp.prettier-vscode",
"sianglim.slim",
"streetsidesoftware.code-spell-checker",
"GitHub.vscode-pull-request-github",
"karunamurti.rspec-snippets",
"2gua.rainbow-brackets",
"oderwat.indent-rainbow",
"GitHub.copilot"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"git": "latest"
}
}
# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
ARG VARIANT=2-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
# Install Rails
RUN gem install rails webdrivers
# RUN bundle install
# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
# The value is a comma-separated list of allowed domains
ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev"
# [Choice] Node.js version: lts/*, 16, 14, 12, 10
ARG NODE_VERSION="lts/*"
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"
# frozen_string_literal: true
source "https://rubygems.org"
gem "rubocop", "1.39.0"
gem "rubocop-performance", "1.15.1"
gem "rubocop-rails", "2.17.2"
gem "solargraph"
gem "slim_lint"
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.2)
backport (1.2.0)
benchmark (0.2.0)
concurrent-ruby (1.1.10)
diff-lcs (1.5.0)
e2mmap (0.1.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
json (2.6.2)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
minitest (5.16.3)
nokogiri (1.13.9-aarch64-linux)
racc (~> 1.4)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
racc (1.6.0)
rack (3.0.0)
rainbow (3.1.1)
regexp_parser (2.6.1)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.5)
rubocop (1.39.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.23.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.23.0)
parser (>= 3.1.1.0)
rubocop-performance (1.15.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.17.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.11.0)
slim (4.1.0)
temple (>= 0.7.6, < 0.9)
tilt (>= 2.0.6, < 2.1)
slim_lint (0.22.1)
rubocop (>= 0.78.0)
slim (>= 3.0, < 5.0)
solargraph (0.47.2)
backport (~> 1.2)
benchmark
bundler (>= 1.17.2)
diff-lcs (~> 1.4)
e2mmap
jaro_winkler (~> 1.5)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
parser (~> 3.0)
reverse_markdown (>= 1.0.5, < 3)
rubocop (>= 0.52)
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
temple (0.8.2)
thor (1.2.1)
tilt (2.0.11)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.3.0)
webrick (1.7.0)
yard (0.9.28)
webrick (~> 1.7.0)
PLATFORMS
aarch64-linux
DEPENDENCIES
rubocop (= 1.39.0)
rubocop-performance (= 1.15.1)
rubocop-rails (= 2.17.2)
slim_lint
solargraph
BUNDLED WITH
2.2.33
singleQuote: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment