diff --git a/README.md b/README.md index 584ebd7..9962a22 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,19 @@ Place `rubocopfmt.el` somewhere into you `load-path` and require it. For example With `rubocopfmt-mode` enabled, Ruby buffer will automatically be formatted with RuboCop on save. +### Unsafe Cops + +RuboCop no longer runs auto-corrections for unsafe cops. To enable unsafe cops, +set `rubocopfmt-include-unsafe-cops` to `t`. If you're using use-package: + +```elisp +(use-package rubocopfmt + :hook + (ruby-mode . rubocopfmt-mode) + :custom + (rubocopfmt-include-unsafe-cops t)) +``` + ## Commands - `rubocopfmt` - Format current buffer with RuboCop. diff --git a/rubocopfmt.el b/rubocopfmt.el index d43ed41..b43deb0 100644 --- a/rubocopfmt.el +++ b/rubocopfmt.el @@ -69,7 +69,7 @@ "Lint/UnusedMethodArgument" ; Don't rename unused method arguments. "Style/EmptyMethod" ; Don't remove blank line in empty methods. ) - "A list of RuboCop cops to disable during auto-correction. + "List of RuboCop cops to disable during auto-correction. These cops are disabled because they cause confusion during interactive use within a text-editor." :type '(repeat string) @@ -89,6 +89,12 @@ inside a `before-save-hook'." (const :tag "None" nil)) :group 'rubocopfmt) +(defcustom rubocopfmt-include-unsafe-cops nil + "When t include unsafe cops when auto-correcting. +Determines if --auto-correct or --auto-correct-all will be passed to rubocop." + :type 'boolean + :group 'rubocopfmt) + (defcustom rubocopfmt-major-modes '(ruby-mode enh-ruby-mode) "List of major modes to format on save when rubocopfmt-mode is enabled." :type '(repeat symbol) @@ -245,8 +251,10 @@ If FILE is not found in DIRECTORY, the parent of DIRECTORY will be searched." (src-dir (file-name-directory buffer-file)) (src-file (file-name-nondirectory buffer-file)) (fmt-command rubocopfmt-rubocop-command) + (auto-correct-flag (if rubocopfmt-include-unsafe-cops + "--auto-correct-all" "--auto-correct")) (fmt-args (list "--stdin" src-file - "--auto-correct" + auto-correct-flag "--format" "emacs"))) (if (and rubocopfmt-use-bundler-when-possible