• Stars
    star
    128
  • Rank 271,181 (Top 6 %)
  • Language
    Emacs Lisp
  • Created about 11 years ago
  • Updated about 2 years 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,361
star
2

rubocop

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

rails-style-guide

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

rspec-style-guide

Best practices for writing your specs!
942
star
5

rubocop-rspec

Code style checking for RSpec files
Ruby
778
star
6

rubocop-rails

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

rubocop-performance

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

guard-rubocop

Guard plugin for RuboCop
Ruby
261
star
9

rubocop-minitest

Code style checking for Minitest files.
Ruby
121
star
10

rubocop-ast

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

rubocop-rake

A RuboCop plugin for Rake
Ruby
71
star
12

rubocop-md

RuboCop for Markdown code snippets
Ruby
70
star
13

minitest-style-guide

Best practices for writing your tests
66
star
14

rubocop-jp

A place for RuboCop discussions in Japanese
56
star
15

rubocop-extension-generator

A generator of RuboCop's custom cops gem.
Ruby
44
star
16

vscode-rubocop

The official VS Code extension for the RuboCop linter and code formatter.
TypeScript
41
star
17

rubocop-factory_bot

Code style checking for factory_bot files
Ruby
33
star
18

rubocop-capybara

Code style checking for Capybara files.
Ruby
33
star
19

rubocop-sequel

Code style checking for Sequel
Ruby
28
star
20

rubocop-rubycw

Wrap ruby -cw by RuboCop
Ruby
23
star
21

blog.rubystyle.guide

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

packaging-style-guide

Best practices for writing downstream compatible code!
5
star
23

docs.rubocop.org

RuboCop's documentation site
Handlebars
4
star
24

circleci-ruby-snapshot-image

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

.github

2
star
26

capybara-style-guide

A community-driven Capybara coding style guide
1
star