Skip to content

Commit

Permalink
Mark ActiveRecordAliases as unsafe autocorrect
Browse files Browse the repository at this point in the history
We faced an issue where our custom `update_attributes` method call was changed to `update` but the method name remained same in the method definition.

```ruby
def update_attributes
end

update_attributes
```

```ruby
def update_attributes
end

update
```

So the cop is not safe for auto correct.
  • Loading branch information
prathamesh-sonpatki committed Jul 30, 2019
1 parent aedb97c commit d1b5fcf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#98](https://github.com/rubocop-hq/rubocop-rails/issues/78): Mark `Rails/ActiveRecordAliases` as `SafeAutoCorrect` false and disable autocorrect by default. ([@prathames-sonpatki][])
* [#78](https://github.com/rubocop-hq/rubocop-rails/issues/78): Add new `Rails/EnumHash` cop. ([@fedeagripa][], [@brunvez][], [@santib][])

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Rails/ActiveRecordAliases:
Use `update!` instead of `update_attributes!`.
Enabled: true
VersionAdded: '0.53'
SafeAutoCorrect: false
AutoCorrect: false

Rails/ActiveRecordOverride:
Description: >-
Expand Down
8 changes: 7 additions & 1 deletion manual/cops_rails.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Include | `app/controllers/**/*.rb` | Array

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
--- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.53 | -
Enabled | Yes | Yes (Unsafe) | 0.53 | -

Checks that ActiveRecord aliases are not used. The direct method names
are more clear and easier to read.
Expand All @@ -66,6 +66,12 @@ Book.update_attributes!(author: 'Alice')
Book.update!(author: 'Alice')
```

### Configurable attributes

Name | Default value | Configurable values
--- | --- | ---
AutoCorrect | `false` | Boolean

## Rails/ActiveRecordOverride

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
Expand Down

0 comments on commit d1b5fcf

Please sign in to comment.