Skip to content

Commit

Permalink
[Fix #832] Mark some Rails cops as unsafe autocorrection
Browse files Browse the repository at this point in the history
Fixes #832.

This commit marks `Rails/ActionControllerFlashBeforeRender`, `Rails/ActionControllerTestCase`,
and `Rails/RootPathnameMethods` cops as unsafe autocorrection to resolve unexpected behaviors.

## Before

Behave as a safe autocorrection (`-a`).

```consle
% echo "File.open(Rails.root.join('db', 'schema.rb'))" |
bundle exec rubocop --stdin example.rb -a --enable-pending-cops --require=rubocop-rails --only Rails/RootPathnameMethods
Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Corrected] Rails/RootPathnameMethods: Rails.root is a Pathname so you can just append #open.
File.open(Rails.root.join('db', 'schema.rb'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
====================
Rails.root.join('db', 'schema.rb').open
```

## After

Behave as an unsafe autocorrection (`-A`).

```console
% echo "File.open(Rails.root.join('db', 'schema.rb'))" |
bundle exec rubocop --stdin example.rb -a --enable-pending-cops --require=rubocop-rails --only Rails/RootPathnameMethods
Inspecting 1 file
C

Offenses:

example.rb:1:1: C: [Correctable] Rails/RootPathnameMethods: Rails.root is a Pathname so you can just append #open.
File.open(Rails.root.join('db', 'schema.rb'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 more offense can be corrected with `rubocop -A`
====================
File.open(Rails.root.join('db', 'schema.rb'))
```
  • Loading branch information
koic committed Oct 25, 2022
1 parent 41a5571 commit 487463c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ Rails/ActionControllerFlashBeforeRender:
StyleGuide: 'https://rails.rubystyle.guide/#flash-before-render'
Reference: 'https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html'
Enabled: 'pending'
SafeAutocorrect: false
SafeAutoCorrect: false
VersionAdded: '2.16'

Rails/ActionControllerTestCase:
Description: 'Use `ActionDispatch::IntegrationTest` instead of `ActionController::TestCase`.'
StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
Enabled: 'pending'
SafeAutocorrect: false
SafeAutoCorrect: false
VersionAdded: '2.14'
Include:
- '**/test/**/*.rb'
Expand Down Expand Up @@ -873,7 +873,7 @@ Rails/RootJoinChain:
Rails/RootPathnameMethods:
Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
Enabled: pending
SafeAutocorrect: false
SafeAutoCorrect: false
VersionAdded: '2.16'

Rails/RootPublicPath:
Expand Down

0 comments on commit 487463c

Please sign in to comment.