• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Emacs Lisp
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Emacs interface for RuboCop

RuboCop.el

Synopsis

A simple Emacs interface for RuboCop.

It doesn't aim to compete with general-purpose packages providing lint integration, but rather to provide the simplest way to leverage the essential RuboCop functionality like:

  • checking code style
  • auto-formatting code
  • auto-correcting code

Most of the package's commands are meant to be used on demand (when needed), but you can also enable automatic code correction on save.

Installation

Please, note that the current version of RuboCop.el requires RuboCop 0.9.0 or later.

MELPA

If you're an package.el user, you can install rubocop.el from the MELPA and MELPA Stable repositories.

Manual

Just drop rubocop.el somewhere in your load-path. I favour the folder ~/.emacs.d/vendor:

(add-to-list 'load-path "~/.emacs.d/vendor")
(require 'rubocop)

Usage

Command Description RuboCop mode binding
M-x rubocop-check-project Runs RuboCop on the entire project C-c C-r p
M-x rubocop-check-directory Prompts from a directory on which to run RuboCop C-c C-r d
M-x rubocop-check-current-file Runs RuboCop on the currently visited file C-c C-r f
M-x rubocop-autocorrect-project Runs auto-correct on the entire project C-c C-r P
M-x rubocop-autocorrect-directory Prompts for a directory on which to run auto-correct C-c C-r D
M-x rubocop-autocorrect-current-file Runs auto-correct on the currently visited file. C-c C-r F
M-x rubocop-format-project Runs format on the entire project C-c C-r X
M-x rubocop-format-directory Prompts for a directory on which to run format C-c C-r y
M-x rubocop-format-current-file Runs format on the currently visited file. C-c C-r x

If you use them often you might want to enable rubocop-mode which will added some keybindings for them:

(add-hook 'ruby-mode-hook #'rubocop-mode)

By default rubocop-mode uses the prefix C-c C-r for its commands, but you can change this if you wish:

(setq rubocop-keymap-prefix (kbd "C-c C-x"))

Configuration

There are a couple of configuration variables that you can use to adjust RuboCop.el's behavior.

The variable rubocop-autocorrect-on-save controls whether to auto-correct automatically files on save when rubocop-mode is active. It's disabled by default, but you can easily change this:

(setq rubocop-autocorrect-on-save t)

Alternatively you can enable only automatic code formatting on save (effectively that's a subset of the full auto-correct):

(setq rubocop-format-on-save t)

Note: Generally you shouldn't enable rubocop-format-on-save if rubocop-autocorrect-on-save is enabled.

You can change the shell command used by rubocop-check-* commands via rubocop-check-command:

;; let's run only lint cops
(setq rubocop-check-command "rubocop --lint --format emacs")

You can change the shell command used by rubocop-autocorrect-* commands via rubocop-autocorrect-command:

;; let's run all auto-corrections possible (by default it's only the safe ones)
(setq rubocop-autocorrect-command "rubocop -A --format emacs")

You can change the shell command used by rubocop-format-* commands via rubocop-format-command.

You can run rubocop inside a chroot via schroot by setting:

(setq rubocop-run-in-chroot t)

Alternatives

Flycheck and Flymake (Emacs built-in) provide more sophisticated integration with various lint tools, including RuboCop.

There's also rubocopfmt, which provides functionality similar to RuboCop.el, but is focused exclusively on the auto-correction side of things.

Known issues

Check out the project's issue list a list of unresolved issues. By the way - feel free to fix any of them and send me a pull request. :-)

Contributors

Here's a list of all the people who have contributed to the development of RuboCop.el.

Bugs & Improvements

Bug reports and suggestions for improvements are always welcome. GitHub pull requests are even better! :-)

Cheers,
Bozhidar

More Repositories

1

ruby-style-guide

A community-driven Ruby coding style guide
16,439
star
2

rubocop

A Ruby static code analyzer and formatter, based on the community Ruby style guide.
Ruby
12,608
star
3

rails-style-guide

A community-driven Ruby on Rails style guide
6,469
star
4

rspec-style-guide

Best practices for writing your specs!
952
star
5

rubocop-rspec

Code style checking for RSpec files.
Ruby
804
star
6

rubocop-rails

A RuboCop extension focused on enforcing Rails best practices and coding conventions.
Ruby
799
star
7

rubocop-performance

An extension of RuboCop focused on code performance checks.
Ruby
665
star
8

guard-rubocop

Guard plugin for RuboCop
Ruby
262
star
9

rubocop-minitest

Code style checking for Minitest files.
Ruby
140
star
10

rubocop-ast

RuboCop's AST extensions and NodePattern functionality
Ruby
99
star
11

rubocop-rake

A RuboCop plugin for Rake
Ruby
75
star
12

rubocop-md

RuboCop for Markdown code snippets
Ruby
73
star
13

minitest-style-guide

Best practices for writing your tests
68
star
14

rubocop-jp

A place for RuboCop discussions in Japanese
55
star
15

vscode-rubocop

The official VS Code extension for the RuboCop linter and code formatter.
TypeScript
50
star
16

rubocop-extension-generator

A generator of RuboCop's custom cops gem.
Ruby
48
star
17

rubocop-factory_bot

Code style checking for factory_bot files.
Ruby
44
star
18

rubocop-capybara

Code style checking for Capybara files.
Ruby
39
star
19

rubocop-sequel

Code style checking for Sequel
Ruby
28
star
20

rubocop-rubycw

Wrap ruby -cw by RuboCop
Ruby
26
star
21

rubocop-rspec_rails

Code style checking for Rails-related RSpec files.
Ruby
14
star
22

blog.rubystyle.guide

A companion blog to the community Ruby, Rails and RSpec guides
HTML
7
star
23

packaging-style-guide

Best practices for writing downstream compatible code!
6
star
24

docs.rubocop.org

RuboCop's documentation site
Handlebars
4
star
25

circleci-ruby-snapshot-image

Builds a Ruby nightly image and publishes it to Docker Hub
Ruby
3
star
26

.github

2
star
27

capybara-style-guide

A community-driven Capybara coding style guide
1
star