[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rubocop 6c9c5a9 55/64: Add a bunch of commands for code fo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rubocop 6c9c5a9 55/64: Add a bunch of commands for code formatting |
Date: |
Wed, 11 Aug 2021 10:08:04 -0400 (EDT) |
branch: elpa/rubocop
commit 6c9c5a98beeee0abbae317184b1541d7defde126
Author: Bozhidar Batsov <bozhidar@batsov.com>
Commit: Bozhidar Batsov <bozhidar@batsov.com>
Add a bunch of commands for code formatting
---
README.md | 14 +++++++++++++-
rubocop.el | 33 +++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index bdf5ec5..9335185 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,9 @@ Command | Description
<kbd>M-x rubocop-autocorrect-project</kbd> | Runs auto-correct on the
entire project | `C-c C-r P`
<kbd>M-x rubocop-autocorrect-directory</kbd> | Prompts for a directory on
which to run auto-correct | `C-c C-r D`
<kbd>M-x rubocop-autocorrect-current-file</kbd> | Runs auto-correct on the
currently visited file. | `C-c C-r F`
+<kbd>M-x rubocop-format-project</kbd> | Runs format on the entire
project | `C-c C-r X`
+<kbd>M-x rubocop-format-directory</kbd> | Prompts for a directory on
which to run format | `C-c C-r y`
+<kbd>M-x rubocop-format-current-file</kbd> | 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:
@@ -59,6 +62,13 @@ By default `rubocop-mode` uses the prefix `C-c C-r` for its
commands, but you ca
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)
+```
+
You can change the shell command used by `rubocop-check-*` commands via
`rubocop-check-command`:
``` emacs-lisp
@@ -66,13 +76,15 @@ You can change the shell command used by `rubocop-check-*`
commands via `rubocop
(setq rubocop-check-command "rubocop --lint --format emacs")
```
-You can change the shell command used by `rubocop-autocorrect-*` commands via
`rubocop-autocorrect-command`
+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`.
+
## Known issues
Check out the project's
diff --git a/rubocop.el b/rubocop.el
index 7a65b3a..546c93e 100644
--- a/rubocop.el
+++ b/rubocop.el
@@ -58,6 +58,12 @@
"The command used to run RuboCop's autocorrection."
:type 'string)
+(defcustom rubocop-format-command
+ "rubocop -x --format emacs"
+ "The command used to run RuboCop's code formatting.
+It's basically auto-correction limited to layout cops."
+ :type 'string)
+
(defcustom rubocop-extensions
'()
"A list of extensions to be loaded by RuboCop."
@@ -154,6 +160,12 @@ Alternatively prompt user for directory."
(rubocop-autocorrect-directory (rubocop-project-root)))
;;;###autoload
+(defun rubocop-format-project ()
+ "Run format on current project."
+ (interactive)
+ (rubocop-format-directory (rubocop-project-root)))
+
+;;;###autoload
(defun rubocop-check-directory (&optional directory)
"Run check on DIRECTORY if present.
Alternatively prompt user for directory."
@@ -167,6 +179,12 @@ Alternatively prompt user for directory."
(interactive)
(rubocop--dir-command rubocop-autocorrect-command directory))
+(defun rubocop-format-directory (&optional directory)
+ "Run format on DIRECTORY if present.
+Alternatively prompt user for directory."
+ (interactive)
+ (rubocop--dir-command rubocop-format-command directory))
+
(defun rubocop--file-command (command)
"Run COMMAND on currently visited file."
(rubocop-ensure-installed)
@@ -193,8 +211,16 @@ Alternatively prompt user for directory."
(rubocop--file-command rubocop-autocorrect-command))
(defun rubocop-autocorrect-current-file-silent ()
- (if rubocop-autocorrect-on-save
- (save-window-excursion (rubocop-autocorrect-current-file))))
+ "This command is used by the minor mode to auto-correct on save.
+See also `rubocop-autocorrect-on-save'."
+ (when rubocop-autocorrect-on-save
+ (save-window-excursion (rubocop-autocorrect-current-file))))
+
+;;;###autoload
+(defun rubocop-format-current-file ()
+ "Run format on current file."
+ (interactive)
+ (rubocop--file-command rubocop-format-command))
(defun rubocop-bundled-p ()
"Check if RuboCop has been bundled."
@@ -219,6 +245,9 @@ Alternatively prompt user for directory."
(define-key prefix-map (kbd "P") #'rubocop-autocorrect-project)
(define-key prefix-map (kbd "D") #'rubocop-autocorrect-directory)
(define-key prefix-map (kbd "F") #'rubocop-autocorrect-current-file)
+ (define-key prefix-map (kbd "X") #'rubocop-format-project)
+ (define-key prefix-map (kbd "y") #'rubocop-format-directory)
+ (define-key prefix-map (kbd "x") #'rubocop-format-current-file)
(define-key map rubocop-keymap-prefix prefix-map))
map)
- [nongnu] elpa/rubocop 9097535 46/64: Update the copyright years, (continued)
- [nongnu] elpa/rubocop 9097535 46/64: Update the copyright years, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop b921bec 08/64: Merge pull request #2 from nodo/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 6f4928d 15/64: Merge pull request #4 from arthurnn/patch-1, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop c549052 31/64: Merge pull request #19 from syohex/byte-compile-warning, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop fb20a88 33/64: Tweak some docstrings, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop c0cb592 37/64: Kill the dash.el dependency, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 4fdf643 40/64: Add missing space, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 1285711 44/64: [Fix #22] Add a clean way to load RuboCop extensions, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop d4dad32 48/64: Add missing space, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 080454e 54/64: Add a note about rubocop-keymap-prefix, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 6c9c5a9 55/64: Add a bunch of commands for code formatting,
ELPA Syncer <=
- [nongnu] elpa/rubocop f5fd18a 64/64: Add the ability to format on save, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop b0c5bc2 62/64: Tweak a heading, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 608a3c1 58/64: Release 0.6.0, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 0131536 39/64: Fix a docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 1372ee3 60/64: Tweak some wording, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 2c884cd 25/64: Merge pull request #15 from fap-/load_tramp_dependency, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop f947fb0 30/64: Fix byte-compile warning about unused variable, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 02ad056 35/64: [Fix #17] Consider rubocop installed if bundled, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 676cabe 36/64: Expand the project root path, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop a809fa7 42/64: [Fix #24] Always run RuboCop from the project's root when within a, ELPA Syncer, 2021/08/11