Mike Slinn
Mike Slinn

Rubocop Settings for Visual Studio Code

Published 2023-08-28.
Time to read: 2 minutes.

This page is part of the ruby collection, categorized under Ruby, Visual Studio Code.

Rubocop Visual Studio Plugin

RuboCop is a Ruby code style checker (linter) and formatter based on the community-driven Ruby Style Guide. There is a Rubocop Visual Studio Code plugin that works well.

Rubocop Project Configuration

Copying the following lines into .vscode/settings.json makes Rubocop work in Visual Studio Code.

settings.json
"ruby.rubocop.useBundler": true,
"ruby.rubocop.configFilePath": "./.rubocop.yml"

Rubocop Workspace Configuration

The above settings could also be located in a .code-workspace file:

workspace.code-workspace
{
  "folders": [
    {
      "path": "~/work/myProject"
    },
  ],
  "settings": {
    "ruby.rubocop.useBundler": true,
    "ruby.rubocop.configFilePath": "./.rubocop.yml"
  }
}

Rubocop Settings

Following is the Rubocop configuration file (.rubocop.yml) that I use for this Jekyll website. It should be located within the top-level directory of a Ruby or Jekyll project.

require:
  #  - rubocop-jekyll
  - rubocop-md
  - rubocop-performance
  - rubocop-rake
  - rubocop-rspec

# inherit_gem:
#   rubocop-jekyll: .rubocop.yml

AllCops:
  Exclude:
    - _site/**/*
    - Gemfile*
    - exe/**/*
    - jekyll/**/*
    - vendor/**/*
  NewCops: enable
  TargetRubyVersion: 2.6

Naming/FileName:
  Exclude:
    - _bin/**/*

Layout/HashAlignment:
  EnforcedColonStyle: table
  EnforcedHashRocketStyle: table

Layout/LeadingCommentSpace:
  Exclude:
    - _bin/**/*

Layout/LineLength:
  Max: 150

Layout/FirstHashElementIndentation:
  Enabled: false

Layout/MultilineMethodCallIndentation:
  Enabled: false

Metrics/AbcSize:
  Max: 40

Metrics/BlockLength:
  Max: 50

Metrics/CyclomaticComplexity:
  Max: 15

Metrics/MethodLength:
  Max: 30

Metrics/PerceivedComplexity:
  Max: 20

Style/Alias:
  Exclude:
    - _plugins/symlink_watcher.rb
    - blog/bin/avImport

Style/Documentation:
  Enabled: false

Style/FrozenStringLiteralComment:
  Enabled: false

Style/PercentLiteralDelimiters:
  Enabled: false

Style/RegexpLiteral:
  Enabled: false

Style/StringLiterals:
  Enabled: false

Style/StringLiteralsInInterpolation:
  Enabled: false

Style/TrailingCommaInArrayLiteral:
  Enabled: false

Style/TrailingCommaInHashLiteral:
  EnforcedStyleForMultiline: comma

About the Author

I, Mike Slinn, have been working with Ruby a long time now. Back in 2005 I was the product marketing manager at CodeGear (the company was formerly known as Borland) for their 3rd Rail IDE. 3rd Rail supported Ruby, and Ruby on Rails, at launch.

In 2006, I co-chaired the Silicon Valley Ruby Conference, on behalf of SD Forum in Silicon Valley. As you can see, I have the t-shirt. I was sole chairman of the 2007 Silicon Valley Ruby Conference.

Several court cases have come my way over the years in my capacity as a software expert witness. The court cases featured questions about IP misappropriation for Ruby on Rails programs. You can read about my experience as a software expert if that interests you.

I currently enjoy writing Jekyll plugins in Ruby for this website and others, and Ruby utilities.