Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

LoranKloeze/vscode-ruby-rubocop-revived

 
 

Repository files navigation

Maintenance mode

Unfortunately, I don't have the time anymore to support or maintain this extension. Feel free to fork the extension and publish your own version of the extension.

Rubocop for Visual Studio Code - revived

It seems the original extension is no longer being maintained. Let's pick it up from here.

Don't forget to give the extension a review in the marketplace.

Marketplace: https://marketplace.visualstudio.com/items?itemName=LoranKloeze.ruby-rubocop-revived

Docs

This extension provides interfaces to rubocop for vscode. All versions of Rubcop >= 1.30.0 are supported.

rubocop is a code analyzer for ruby.

exec on save

Rubocop Quick Fix Tooltip - Correctable

Rubocop Quick Fix List - Correctable

Rubocop Quick Fix Tooltip - Uncorrectable

Rubocop Quick Fix List - Uncorrectable

Rubocop Quick Fixes Demo

Problems

This extension may have problems when using a rvm or chruby environment. We recommend vscode-ruby. It can also lint ruby code.

When autoCorrect is enabled, the history of changing file is broken.

Features

  • lint by executing the command "Ruby: lint by rubocop" (cmd+shift+p and type command)
  • auto correct when saving a file
  • auto correct command "Ruby: autocorrect by rubocop"
  • quick fixes so you can fix or ignore an error PR with explanation

Exclude file

The extension forces rubocop's force-exclusion option.

If you do not want rubocop to be executed on some file, you can add AllCops/Exclude in rubocop.yml. The file can be saved without executing rubocop.

Installation

Installation of ruby and rubocop is required.

gem install rubocop
  • Type F1 (or Command + Shift + P)
  • execute "Extensions: install extension"
  • type rubocop and execute ext install ruby-rubocop

If VSCode market place is not configured in your FLOSS distribution of code (you have Open VSX instead):

  1. Go on VSCode Marketplace and click on the Download Extension button.
  2. Install the extension manually from the CLI: code --install-extension LoranKloeze.ruby-rubocop-revived-0.9.5.vsix

ChangeLog

ChangeLog

Configuration

Specify configuration (via navigating to File > Preferences > Workspace Settings and editing file settings.json):

{
  // If not specified searches for 'rubocop' executable available on PATH (default and recommended)
  "ruby.rubocop.executePath": "",

  // You can use specific path
  // "ruby.rubocop.executePath": "/Users/you/.rbenv/shims/"
  // "ruby.rubocop.executePath": "/Users/you/.rvm/gems/ruby-2.3.2/bin/"
  // "ruby.rubocop.executePath": "D:/bin/Ruby22-x64/bin/"

  // Set to "--autocorrect-all" to enable "unsafe" auto-corrections
  "ruby.rubocop.autocorrectArg": "--autocorrect",

  // If not specified, it assumes a null value by default.
  "ruby.rubocop.configFilePath": "/path/to/config/.rubocop.yml",

  // default true
  "ruby.rubocop.onSave": true

  // use the --server option when running Rubocop - default false
  "ruby.rubocop.useServer": true

  // If "true", it hides all the Disable/Ignore options, nudging to prefer fixing violations
  "ruby.rubocop.hideDisableSuggestions": false
}

Keybindings

You can change the keybinding (via editing keybindings.json)

{ "key": "ctrl+alt+l",          "command": "ruby.rubocopAutocorrect",
                                "when": "editorLangId == 'ruby'" }

todo

  • more configurable command line options (like -R)
  • integration with rbenv
  • testing & CI support

Contribute with this extension

Please install packages with yarn.

yarn install

You could install TSLint extension for .ts files.

Please format code using prettier.

yarn prettier src/* test/* --write

License

このソフトウェアは MIT ライセンスの元で公開されています。LICENSE.txt をご覧下さい。

This software is released under the MIT License, see LICENSE.txt.