Hi all,
After several abortive attempts and wading through lots of different documentation, I am finally getting closer to running Rubocop! I have pasted below the process I followed, for the benefit of anyone else going through this learning curve.
Initial attempts to install on top of the system Ruby (2.6.0 on Mac OS 12.7) failed due to permissions errors. Further research suggested using sudo
to force this was not a good idea, the consensus seems to be don’t mess with the system Ruby; it is better to use a version manager, or at least Homebrew to make a separate Ruby installation.
After initially trying the RVM version manager, I had a better a experience with rbenv. They provide a good comparison of different version managers here: Comparison of version managers · rbenv/rbenv Wiki · GitHub
- install Homebrew; install
.pkg
from Releases · Homebrew/brew · GitHub - install
rbenv
using Homebrew
$ brew install rbenv
- install Ruby Build for rbenv
$ brew install ruby-build
- install Ruby 3.2.2 using ruby-build
$ rbenv install 3.2.2
- Install Rubocop and Rubocop-SketchUp gems using Bundler
$ bundle install
in project dir containing Gemfile
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'rubocop', '>= 0.82', '< 2.0', require: false
gem 'rubocop-sketchup', '~> 1.4.0', require: false
I ended up with the following environment:
$ gem env
- RUBYGEMS VERSION: 3.4.10
- RUBY VERSION: 3.2.2 (2023-03-30 patchlevel 53) [x86_64-darwin21]
- INSTALLATION DIRECTORY: /Users/dave/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0
- USER INSTALLATION DIRECTORY: /Users/dave/.gem/ruby/3.2.0
- RUBY EXECUTABLE: /Users/dave/.rbenv/versions/3.2.2/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/dave/.rbenv/versions/3.2.2/bin
- SPEC CACHE DIRECTORY: /Users/dave/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/dave/.rbenv/versions/3.2.2/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-21
- GEM PATHS:
- /Users/dave/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0
- /Users/dave/.gem/ruby/3.2.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => true
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/dave/.rbenv/versions/3.2.2/bin
- /usr/local/Cellar/rbenv/1.3.2/libexec
- /Users/dave/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/dave/.rvm/bin
Rubocop configuration
In my project directory I have .rubocop.yml
require: rubocop-sketchup
AllCops:
DisabledByDefault: true
SketchupDeprecations:
Enabled: true
SketchupPerformance:
Enabled: true
SketchupRequirements:
Enabled: true
SketchupSuggestions:
Enabled: true
SketchupBugs:
Enabled: true
Run Rubocop
In the project directory;
If rubocop
Gems were installed directly, (eg by gem install rubocop
):
$ rbenv exec rubocop
If rubocop
Gems were installed using Bundler:
$ bundle exec rubocop
So I finally got Rubocop to run, but as I am retrofitting this to a project that has some parts of the code that goes back at least 10 years, I was immediately confronted by several 100 ‘offenses’ …