Skip to content

Commit

Permalink
Merge branch 'rubocop:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
RDeckard authored Oct 28, 2024
2 parents 63b1218 + 1d7f0c4 commit 9fce1cf
Show file tree
Hide file tree
Showing 72 changed files with 2,276 additions and 656 deletions.
4 changes: 0 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ AllCops:
InternalAffairs/NodeMatcherDirective:
Enabled: false

# FIXME: Workaround for a false positive caused by this cop when using `bundle exec rake`.
InternalAffairs/UndefinedConfig:
Enabled: false

Naming/InclusiveLanguage:
Enabled: true
CheckStrings: true
Expand Down
68 changes: 68 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,71 @@

## master (unreleased)

## 2.27.0 (2024-10-26)

### Bug fixes

* [#1377](https://github.com/rubocop/rubocop-rails/issues/1377): Fix an error for `Rails/EnumSyntax` when positional arguments are used and options are not passed as keyword arguments. ([@koic][])
* [#1367](https://github.com/rubocop/rubocop-rails/pull/1367): Fix `Rails/TimeZone` should not report offense on `String#to_time` with timezone specifier. ([@armandmgt][])

### Changes

* [#727](https://github.com/rubocop/rubocop-rails/issues/727): Disable `Rails/TransactionExitStatement` on Rails >= 7.2. ([@earlopain][])
* [#1374](https://github.com/rubocop/rubocop-rails/pull/1374): Change `Rails/EnvLocal` to handle negated conditions. ([@fatkodima][])
* [#1195](https://github.com/rubocop/rubocop-rails/issues/1195): Change `Rails/SelectMap` to handle safe navigation operators. ([@fatkodima][])

## 2.26.2 (2024-09-21)

### Bug fixes

* [#1362](https://github.com/rubocop/rubocop-rails/issues/1362): Fix false positives for `Rails/EnumSyntax` when using Ruby 2.7. ([@koic][])
* [#1269](https://github.com/rubocop/rubocop-rails/issues/1269): Fix false positives for `Rails/ActionControllerFlashBeforeRender` in combination with implicit returns. ([@earlopain][])
* [#1326](https://github.com/rubocop/rubocop-rails/pull/1326): Fix wrong autocorrect for `Rails/FilePath` when passing an array to `File.join`. ([@earlopain][])

### Changes

* [#1359](https://github.com/rubocop/rubocop-rails/pull/1359): Support `filter` in `Rails/CompactBlank`. ([@masato-bkn][])

## 2.26.1 (2024-09-07)

### Bug fixes

* [#1343](https://github.com/rubocop/rubocop-rails/issues/1343): Fix false negatives for `Rails/EnumSyntax` for non-literal mappings. ([@earlopain][])
* [#1340](https://github.com/rubocop/rubocop-rails/issues/1340): Fix a false positive for `Rails/WhereEquals`, `Rails/WhereNot`, and `Rails/WhereRange` when qualifying the database name. ([@earlopain][])

### Changes

* [#1342](https://github.com/rubocop/rubocop-rails/issues/1342): Change `Rails/ApplicationRecord` to ignore migrations. ([@fatkodima][])
* [#1350](https://github.com/rubocop/rubocop-rails/pull/1350): Change `Rails/EnumSyntax` to autocorrect underscored options. ([@fatkodima][])

## 2.26.0 (2024-08-24)

### New features

* [#1238](https://github.com/rubocop/rubocop-rails/issues/1238): Add new `Rails/EnumSyntax` cop. ([@maxprokopiev][], [@koic][])
* [#1309](https://github.com/rubocop/rubocop-rails/pull/1309): Support Rails 7 syntax for `Rails/EnumHash` cop. ([@ytjmt][])
* [#1298](https://github.com/rubocop/rubocop-rails/pull/1298): Support Rails 7 syntax for `Rails/EnumUniqueness` cop. ([@ytjmt][])

### Bug fixes

* [#1335](https://github.com/rubocop/rubocop-rails/pull/1335): Fix an error for `Rails/BulkChangeTable` when the block for `change_table` is empty. ([@earlopain][])
* [#1325](https://github.com/rubocop/rubocop-rails/pull/1325): Fix an error for `Rails/RenderPlainText` when the content type is passed as a constant. ([@earlopain][])
* [#1337](https://github.com/rubocop/rubocop-rails/pull/1337): Fix an error for `Rails/Validation` when passing no arguments. ([@earlopain][])
* [#1330](https://github.com/rubocop/rubocop-rails/pull/1330): Fix an error for `Rails/WhereNot` when using placeholder without second argument. ([@earlopain][])
* [#1311](https://github.com/rubocop/rubocop-rails/pull/1311): Fix false negatives for `Rails/ActionControllerFlashBeforeRender` when using implicit render or rescue blocks. ([@tldn0718][])
* [#1313](https://github.com/rubocop/rubocop-rails/pull/1313): Fix false positives for `Rails/CompactBlank` when using `collection.reject!`. ([@koic][])
* [#1319](https://github.com/rubocop/rubocop-rails/issues/1319): Fix a false positive for `Rails/RedundantPresenceValidationOnBelongsTo` when removing `presence` would leave other non-validation options like `allow_blank` without validations. ([@earlopain][])
* [#1306](https://github.com/rubocop/rubocop-rails/pull/1306): Make `Rails/PluralizationGrammar` aware of byte methods. ([@earlopain][])
* [#1302](https://github.com/rubocop/rubocop-rails/pull/1302): Allow `params` receiver by default for `Style/CollectionMethods`. ([@koic][])
* [#1321](https://github.com/rubocop/rubocop-rails/pull/1321): Fix an error for `Rails/WhereEquals` when the second argument is not yet typed (`where("foo = ?", )`). ([@earlopain][])

### Changes

* [#1308](https://github.com/rubocop/rubocop-rails/issues/1308): Change `Rails/CompactBlank` to handle `select(&:present?)`. ([@fatkodima][])
* [#1303](https://github.com/rubocop/rubocop-rails/pull/1303): Change `Rails/IgnoredSkipActionFilterOption` to handle multiple callbacks. ([@fatkodima][])
* [#1199](https://github.com/rubocop/rubocop-rails/issues/1199): Make `Rails/WhereEquals` aware of `where.not(...)`. ([@earlopain][])
* [#1003](https://github.com/rubocop/rubocop-rails/pull/1003): Change `Rails/RootPathnameMethods` to detect offenses on `Dir.[]`. ([@r7kamura][])

## 2.25.1 (2024-06-29)

### Bug fixes
Expand Down Expand Up @@ -1098,3 +1163,6 @@
[@lukasfroehlich1]: https://github.com/lukasfroehlich1
[@ChaelCodes]: https://github.com/ChaelCodes
[@fwolfst]: https://github.com/fwolfst
[@maxprokopiev]: https://github.com/maxprokopiev
[@ytjmt]: https://github.com/ytjmt
[@armandmgt]: https://github.com/armandmgt
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ gem 'prism'
gem 'rake'
gem 'rspec'
gem 'rubocop', github: 'rubocop/rubocop'
gem 'rubocop-performance', '~> 1.21.0'
gem 'rubocop-rspec', '~> 3.0.0'
gem 'rubocop-performance', '~> 1.22.0'
gem 'rubocop-rspec', '~> 3.1.0'
gem 'simplecov'
gem 'test-queue'
gem 'yard', '~> 0.9'
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,29 @@ RuboCop::RakeTask.new do |task|
end
```

## RuboCop Rails configuration

The following settings specific to RuboCop Rails can be configured in `.rubocop.yml`.

### `AllCops: TargetRailsVersion`

What version of Rails is the inspected code using? If a value is specified
for `TargetRailsVersion` then it is used. Acceptable values are specified
as a float (e.g., 7.2); the patch version of Rails should not be included.

```yaml
AllCops:
TargetRailsVersion: 7.2
```

If `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or
gems.locked file to find the version of Rails that has been bound to the
application. If neither of those files exist, RuboCop will use Rails 5.0
as the default.

## Rails configuration tip

If you are using Rails 6.1 or newer, add the following `config.generators.after_generate` setting to
In Rails 6.1+, add the following `config.generators.after_generate` setting to
your `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.

```ruby
Expand All @@ -84,6 +104,20 @@ It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsaf
`rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.

In Rails 7.2+, it is recommended to use `config.generators.apply_rubocop_autocorrect_after_generate!` instead of the above setting:

```diff
# config/environments/development.rb
Rails.application.configure do
(snip)
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
- # config.generators.apply_rubocop_autocorrect_after_generate!
+ config.generators.apply_rubocop_autocorrect_after_generate!
end
```

You only need to uncomment.

## The Cops

All cops are located under
Expand Down
1 change: 0 additions & 1 deletion changelog/change_compact_blank_to_handle_select_present.md

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/fix_false_positive_for_rails_compact_blank.md

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/fix_make_pluralization_grammar_aware_of_bytes.md

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion changelog/fix_where_equals_error.md

This file was deleted.

This file was deleted.

26 changes: 18 additions & 8 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ AllCops:
# Enable checking Active Support extensions.
# See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
ActiveSupportExtensionsEnabled: true
# What version of Rails is the inspected code using? If a value is specified
# for TargetRailsVersion then it is used. Acceptable values are specified
# as a float (i.e. 5.1); the patch version of Rails should not be included.
# If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
# What version of Rails is the inspected code using? If a value is specified
# for `TargetRailsVersion` then it is used. Acceptable values are specified
# as a float (e.g., 7.2); the patch version of Rails should not be included.
# If `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or
# gems.locked file to find the version of Rails that has been bound to the
# application. If neither of those files exist, RuboCop will use Rails 5.0
# application. If neither of those files exist, RuboCop will use Rails 5.0
# as the default.
TargetRailsVersion: ~

Expand Down Expand Up @@ -212,7 +212,9 @@ Rails/ApplicationRecord:
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.49'
VersionChanged: '2.5'
VersionChanged: '2.26'
Exclude:
- db/**/*.rb

Rails/ArelStar:
Description: 'Enforces `Arel.star` instead of `"*"` for expanded columns.'
Expand Down Expand Up @@ -425,6 +427,14 @@ Rails/EnumHash:
Include:
- app/models/**/*.rb

Rails/EnumSyntax:
Description: 'Use positional arguments over keyword arguments when defining enums.'
Enabled: pending
Severity: warning
VersionAdded: '2.26'
Include:
- app/models/**/*.rb

Rails/EnumUniqueness:
Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.'
Enabled: true
Expand Down Expand Up @@ -1187,12 +1197,12 @@ Rails/Validation:
- app/models/**/*.rb

Rails/WhereEquals:
Description: 'Pass conditions to `where` as a hash instead of manually constructing SQL.'
Description: 'Pass conditions to `where` and `where.not` as a hash instead of manually constructing SQL.'
StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
Enabled: 'pending'
SafeAutoCorrect: false
VersionAdded: '2.9'
VersionChanged: '2.10'
VersionChanged: '2.26'

Rails/WhereExists:
Description: 'Prefer `exists?(...)` over `where(...).exists?`.'
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
* xref:cops_rails.adoc#railsdynamicfindby[Rails/DynamicFindBy]
* xref:cops_rails.adoc#railseagerevaluationlogmessage[Rails/EagerEvaluationLogMessage]
* xref:cops_rails.adoc#railsenumhash[Rails/EnumHash]
* xref:cops_rails.adoc#railsenumsyntax[Rails/EnumSyntax]
* xref:cops_rails.adoc#railsenumuniqueness[Rails/EnumUniqueness]
* xref:cops_rails.adoc#railsenvlocal[Rails/EnvLocal]
* xref:cops_rails.adoc#railsenvironmentcomparison[Rails/EnvironmentComparison]
Expand Down
Loading

0 comments on commit 9fce1cf

Please sign in to comment.