I’d like to use Rubocop to check the code of a plugin I’m writing. I’ve tried searching this forum, but haven’t found many references to Rubocop and nothing the clarifies for me where or how I should install it.
I’ve downloaded rubocop-sketchup-master.zip from GitHub following a link in one of the few references to Rubocop that I could find on this forum, and extracted it in my Downloads folder to rubocop-sketchup-master.
I expect it has to be copied somewhere (on MacOS Mojave 10.14.6) - but where?
The instructions say only:
gem install rubocop-sketchup
but don’t say where I should run that command.
Tried using that command in the Sketchup Ruby console (SU 2020.1), but it gives an error
> gem install rubocop
Error: #<NameError: undefined local variable or method `rubocop' for main:Object>
<main>:in `<main>'
SketchUp:1:in `eval'
Is there a simple guide to installation and use that I’m just not finding?
but they seem to assume a level of knowledge about this that I just don’t have.
They say I need to have Ruby 2.2+ installed, which I think I already do have on any recent MacOS installation, but I can’t find where it is. Nor am I clear if Rubocop should link to that, or to the SU specific Ruby installed by the SU installer.
Thanks for any link to more specific instructions, or for suggestions on how to get it to work.
Rubocop is not a SketchUp extension, it is a separate program that is used independently from SketchUp and is run from command line (or code editor integration) on a folder path containing ruby files.
You downloaded an archive of source code. Source code can be (compiled if necessary and) run from the directory where ever it is contained.
This is a command to install a release of Rubocop (alternatively to downloading the source code). This is a shell command, that means it needs to be run in a terminal. It looks different from valid Ruby language, that’s why the Ruby Console doesn’t understand it. If technical instructions don’t specifically mention this, one can assume a command is a shell command (often indicated by $ signs that are not part of the command). Shell commands are often shorter and easier to reproduce than describing locations of mouse clicks.
When you open the terminal program (and Ruby and Ruby Gems are installed on the system), you can copy-paste this command and press Enter.
In the terminal you navigate to the folder where you develop the SketchUp extension (edit the path):
It’s the only link to a download that there is on GitHub, and when expanded, I can see it holds a range of directories and files.
I opened a Terminal window, changed directory to the downloaded and unzipped rubocop-sketchup-master folder, and ran
gem install rubocop.
That ran, but raised a permissions error:
Johns-iMac:rubocop-sketchup-master JohnWMcC$ gem install rubocop
Fetching: parallel-1.19.1.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
So I went down the chain of directories, and gave myself (user JohnWMcC) Read & Write permissions as far as the gem folder. just below 2.3.0.
Now when I cd to the rubocop... directory and run gem install rubocop it no longer runs anything but responds with
Johns-iMac:rubocop-sketchup-master JohnWMcC$ Johns-iMac:rubocop-sketchup-master JohnWMcC$ gem install rubocop
-bash: Johns-iMac:rubocop-sketchup-master: command not found
Johns-iMac:rubocop-sketchup-master JohnWMcC$
I’m stuck at this point, but will leave it for now.
What am I doing wrong? Can’t see it myself for the moment.
The thing ending with the dollar sign is called a “prompt” and just tells you some more or less useful info (computer name, current user name and working directory). You accidentially copied it and executed it as if it was a valid shell command.
The instructions don’t say anything about downloading. The gem command (alternative to manual downloading) does the downloading for you. It is also often not a good idea to change permissions of system files. Instead, you can either run a command as root user, or tell this specific command to install into the user directory so that it does not attempt to touch files where it has no permissions to do so.
Try:
You could use homebrew to install the latest Ruby if you want. Then install ruby with: brew install ruby --with-doc
If you just use brew install ruby then ri won’t work. That’s what I did originally and had to uninstall ruby and start again.
You’ll have to add this new ruby to your shell’s path as the homebrew one goes here: /usr/local/opt/ruby/bin/ruby
The Apple installed ruby will still be here:
/usr/bin/ruby
You could mess about with software that manages multiple versions of ruby, but I just use the latest version for trying things out but not using anything that’s not in 2.5.5 for SketchUp.