diff --git a/CHANGELOG.md b/CHANGELOG.md index 8853920ff1..5cad653264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ ## master (unreleased) +## 2.22.0 (2023-10-27) + ### New features * [#906](https://github.com/rubocop/rubocop-rails/pull/906): Add `Rails/EnvLocal` cop. ([@sambostock][]) diff --git a/config/default.yml b/config/default.yml index d05ea237c9..c20ae180e0 100644 --- a/config/default.yml +++ b/config/default.yml @@ -97,7 +97,7 @@ Rails/ActionFilter: Description: 'Enforces consistent use of action filter methods.' Enabled: false VersionAdded: '0.19' - VersionChanged: '<>' + VersionChanged: '2.22' EnforcedStyle: action SupportedStyles: - action @@ -433,7 +433,7 @@ Rails/EnumUniqueness: Rails/EnvLocal: Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.' Enabled: pending - VersionAdded: '<>' + VersionAdded: '2.22' Rails/EnvironmentComparison: Description: "Favor `Rails.env.production?` over `Rails.env == 'production'`." diff --git a/docs/antora.yml b/docs/antora.yml index 9e0ff48acb..aaeffb2967 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -2,6 +2,6 @@ name: rubocop-rails title: RuboCop Rails # We always provide version without patch here (e.g. 1.1), # as patch versions should not appear in the docs. -version: ~ +version: '2.22' nav: - modules/ROOT/nav.adoc diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 569afede1e..56dfc04e5b 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -54,6 +54,7 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide]. * xref:cops_rails.adoc#railseagerevaluationlogmessage[Rails/EagerEvaluationLogMessage] * xref:cops_rails.adoc#railsenumhash[Rails/EnumHash] * xref:cops_rails.adoc#railsenumuniqueness[Rails/EnumUniqueness] +* xref:cops_rails.adoc#railsenvlocal[Rails/EnvLocal] * xref:cops_rails.adoc#railsenvironmentcomparison[Rails/EnvironmentComparison] * xref:cops_rails.adoc#railsenvironmentvariableaccess[Rails/EnvironmentVariableAccess] * xref:cops_rails.adoc#railsexit[Rails/Exit] diff --git a/docs/modules/ROOT/pages/cops_rails.adoc b/docs/modules/ROOT/pages/cops_rails.adoc index 248bbe4c82..c01f0dd3a1 100644 --- a/docs/modules/ROOT/pages/cops_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rails.adoc @@ -95,11 +95,11 @@ end |=== | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed -| Enabled +| Disabled | Yes | Yes | 0.19 -| - +| 2.22 |=== Enforces the consistent use of action filter methods. @@ -107,6 +107,9 @@ Enforces the consistent use of action filter methods. The cop is configurable and can enforce the use of the older something_filter methods or the newer something_action methods. +IMPORTANT: This cop is deprecated. Because the `*_filter` methods were removed in Rails 4.2, +and that Rals version is no longer supported by RuboCop Rails. This cop will be removed in RuboCop Rails 3.0. + === Examples ==== EnforcedStyle: action (default) @@ -974,7 +977,7 @@ the PostgreSQL (5.2 later) adapter; thus it will automatically detect an adapter from `development` environment in `config/database.yml` or the environment variable `DATABASE_URL` when the `Database` option is not set. -If the adapter is not `mysql2` or `postgresql`, +If the adapter is not `mysql2`, `trilogy`, or `postgresql`, this Cop ignores offenses. === Examples @@ -1395,10 +1398,6 @@ def self.published end ---- -=== References - -* https://rails.rubystyle.guide#avoid-default-scope - == Rails/Delegate |=== @@ -1637,6 +1636,15 @@ has_one :foo # good belongs_to :bar has_one :foo + +# bad +belongs_to :foo, class_name: 'Foo' +belongs_to :bar, class_name: 'Foo' +has_one :baz + +# good +belongs_to :bar, class_name: 'Foo' +has_one :foo ---- === Configurable attributes @@ -1929,6 +1937,32 @@ enum status: [:active, :archived] | Array |=== +== Rails/EnvLocal + +|=== +| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed + +| Pending +| Yes +| Yes +| 2.22 +| - +|=== + +Checks for usage of `Rails.env.development? || Rails.env.test?` which +can be replaced with `Rails.env.local?`, introduced in Rails 7.1. + +=== Examples + +[source,ruby] +---- +# bad +Rails.env.development? || Rails.env.test? + +# good +Rails.env.local? +---- + == Rails/EnvironmentComparison |=== @@ -3619,8 +3653,13 @@ hash.exclude?(:key) | 2.20 |=== -Checks for add_column call with NOT NULL constraint -in migration file. +Checks for add_column call with NOT NULL constraint in migration file. + +`TEXT` can have default values in PostgreSQL, but not in MySQL. +It will automatically detect an adapter from `development` environment +in `config/database.yml` or the environment variable `DATABASE_URL` +when the `Database` option is not set. If the database is MySQL, +this cop ignores offenses for the `TEXT`. === Examples @@ -3642,6 +3681,10 @@ add_reference :products, :category, null: false, default: 1 |=== | Name | Default value | Configurable values +| Database +| `` +| `mysql` + | Include | `+db/**/*.rb+` | Array diff --git a/lib/rubocop/rails/version.rb b/lib/rubocop/rails/version.rb index 9e9f054da0..0fa9f994a5 100644 --- a/lib/rubocop/rails/version.rb +++ b/lib/rubocop/rails/version.rb @@ -4,7 +4,7 @@ module RuboCop module Rails # This module holds the RuboCop Rails version information. module Version - STRING = '2.21.2' + STRING = '2.22.0' def self.document_version STRING.match('\d+\.\d+').to_s diff --git a/relnotes/v2.22.0.md b/relnotes/v2.22.0.md new file mode 100644 index 0000000000..966a44811a --- /dev/null +++ b/relnotes/v2.22.0.md @@ -0,0 +1,28 @@ +### New features + +* [#906](https://github.com/rubocop/rubocop-rails/pull/906): Add `Rails/EnvLocal` cop. ([@sambostock][]) +* [#1128](https://github.com/rubocop/rubocop-rails/issues/1128): Make `Rails/DuplicateAssociation` aware of duplicate `class_name`. ([@koic][]) +* [#1157](https://github.com/rubocop/rubocop-rails/pull/1157): Support some Rails 7.1's new querying methods for `Rails/RedundantActiveRecordAllMethod`. ([@koic][]) +* [#1147](https://github.com/rubocop/rubocop-rails/issues/1147): Support the Trilogy adapter for MySQL. ([@koic][]) + +### Bug fixes + +* [#952](https://github.com/rubocop/rubocop-rails/issues/952): Fix a false positive for `Rails/NotNullColumn` when using `null: false` for MySQL's TEXT type. ([@koic][]) +* [#1041](https://github.com/rubocop/rubocop-rails/issues/1041): Fix a false positive for `Rails/Output` when output method is called with block argument. ([@koic][]) +* [#1143](https://github.com/rubocop/rubocop-rails/issues/1143): Fix an error for `Rails/RedundantActiveRecordAllMethod` when using RuboCop 1.51 or lower. ([@koic][]) +* [#1105](https://github.com/rubocop/rubocop-rails/issues/1105): Fix false positives for `Rails/RedundantPresenceValidationOnBelongsTo` when using `validates` with `:if` or `:unless` options. ([@koic][]) +* [#1158](https://github.com/rubocop/rubocop-rails/issues/1158): `Rails/HasManyOrHasOneDependent` does not add offence when has_many or has_one is called on an explicit receiver. ([@samrjenkins][]) +* [#1160](https://github.com/rubocop/rubocop-rails/issues/1160): Fix `Rails/SaveBang` to ignore parenthesis. ([@fatkodima][]) + +### Changes + +* [#1152](https://github.com/rubocop/rubocop-rails/pull/1152): Add more dangerous column names to `Rails/DangerousColumnNames`. ([@r7kamura][]) +* [#1039](https://github.com/rubocop/rubocop-rails/issues/1039): Deprecate `Rails/ActionFilter` cop; it will be disabled by default. ([@koic][]) +* [#893](https://github.com/rubocop/rubocop-rails/issues/893): Support `local` as an environment for `Rails/UnknownEnv` from Rails 7.1 onward. ([@ghiculescu][]) + +[@sambostock]: https://github.com/sambostock +[@koic]: https://github.com/koic +[@samrjenkins]: https://github.com/samrjenkins +[@fatkodima]: https://github.com/fatkodima +[@r7kamura]: https://github.com/r7kamura +[@ghiculescu]: https://github.com/ghiculescu