https://github.com/rubocop/rubocop-emacs
An Emacs interface for RuboCop
https://github.com/rubocop/rubocop-emacs
emacs emacs-lisp rubocop
Last synced: 20 days ago
JSON representation
An Emacs interface for RuboCop
- Host: GitHub
- URL: https://github.com/rubocop/rubocop-emacs
- Owner: rubocop
- Created: 2013-04-14T12:59:31.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-08-17T19:36:53.000Z (9 months ago)
- Last Synced: 2025-03-27T02:11:33.933Z (about 1 month ago)
- Topics: emacs, emacs-lisp, rubocop
- Language: Emacs Lisp
- Size: 48.8 KB
- Stars: 128
- Watchers: 14
- Forks: 30
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RuboCop.el
## Synopsis
A simple Emacs interface for [RuboCop](https://github.com/rubocop-hq/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 codeMost 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](http://melpa.org/) and
[MELPA Stable](http://stable.melpa.org/) repositories.### Manual
Just drop `rubocop.el` somewhere in your `load-path`. I
favour the folder `~/.emacs.d/vendor`:```lisp
(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:
```lisp
(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:
``` emacs-lisp
(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:``` emacs-lisp
(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):``` emacs-lisp
(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`:
``` emacs-lisp
;; 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`:
``` emacs-lisp
;; 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:
``` emacs-lisp
(setq rubocop-run-in-chroot t)
```## Alternatives
[Flycheck](https://www.flycheck.org) and Flymake (Emacs built-in) provide more sophisticated integration with various lint tools, including RuboCop.
There's also [rubocopfmt](https://github.com/jimeh/rubocopfmt.el), 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](https://github.com/rubocop-hq/rubocop-emacs/issues?sort=created&direction=desc&state=open)
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](https://github.com/rubocop-hq/rubocop-emacs/contributors) 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](http://twitter.com/bbatsov)