Skip to content

Commit

Permalink
Cut 2.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
koic committed May 17, 2024
1 parent 0576d54 commit 809fd54
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## master (unreleased)

## 2.25.0 (2024-05-17)

### New features

* [#1272](https://github.com/rubocop/rubocop-rails/pull/1272): Add new `Rails/WhereRange` cop. ([@fatkodima][])
Expand Down
4 changes: 2 additions & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ Rails/UnusedIgnoredColumns:
Description: 'Remove a column that does not exist from `ignored_columns`.'
Enabled: false
VersionAdded: '2.11'
VersionChanged: <<next>>
VersionChanged: '2.25'
Include:
- app/models/**/*.rb

Expand Down Expand Up @@ -1226,7 +1226,7 @@ Rails/WhereRange:
Description: 'Use ranges in `where` instead of manually constructing SQL.'
StyleGuide: 'https://rails.rubystyle.guide/#where-ranges'
Enabled: pending
VersionAdded: '<<next>>'
VersionAdded: '2.25'

# Accept `redirect_to(...) and return` and similar cases.
Style/AndOr:
Expand Down
2 changes: 1 addition & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.25'
nav:
- modules/ROOT/nav.adoc
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/cops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ based on the https://rails.rubystyle.guide/[Rails Style Guide].
* xref:cops_rails.adoc#railswheremissing[Rails/WhereMissing]
* xref:cops_rails.adoc#railswherenot[Rails/WhereNot]
* xref:cops_rails.adoc#railswherenotwithmultipleconditions[Rails/WhereNotWithMultipleConditions]
* xref:cops_rails.adoc#railswhererange[Rails/WhereRange]

// END_COP_LIST
101 changes: 91 additions & 10 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2661,13 +2661,17 @@ render json: { foo: 'bar' }, status: 200
render plain: 'foo/bar', status: 304
redirect_to root_url, status: 301
head 200
assert_response 200
assert_redirected_to '/some/path', status: 301
# good
render :foo, status: :ok
render json: { foo: 'bar' }, status: :ok
render plain: 'foo/bar', status: :not_modified
redirect_to root_url, status: :moved_permanently
head :ok
assert_response :ok
assert_redirected_to '/some/path', status: :moved_permanently
----
==== EnforcedStyle: numeric
Expand All @@ -2680,13 +2684,17 @@ render json: { foo: 'bar' }, status: :not_found
render plain: 'foo/bar', status: :not_modified
redirect_to root_url, status: :moved_permanently
head :ok
assert_response :ok
assert_redirected_to '/some/path', status: :moved_permanently
# good
render :foo, status: 200
render json: { foo: 'bar' }, status: 404
render plain: 'foo/bar', status: 304
redirect_to root_url, status: 301
head 200
assert_response 200
assert_redirected_to '/some/path', status: 301
----
=== Configurable attributes
Expand Down Expand Up @@ -3659,13 +3667,25 @@ hash.exclude?(:key)
| 2.20
|===
Checks for add_column call with NOT NULL constraint in migration file.
Checks for add_column calls with a NOT NULL constraint without a default
value.
`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`.
This cop only applies when adding a column to an existing table, since
existing records will not have a value for the new column. New tables
can freely use NOT NULL columns without defaults, since there are no
records that could violate the constraint.
If you need to add a NOT NULL column to an existing table, you must add
it as nullable first, back-fill the data, and then use
`change_column_null`. Alternatively, you could add the column with a
default first to have the database automatically backfill existing rows,
and then use `change_column_default` to remove the default.
`TEXT` cannot have a default value in MySQL.
The cop 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 `TEXT` columns.
=== Examples
Expand All @@ -3674,12 +3694,18 @@ this cop ignores offenses for the `TEXT`.
# bad
add_column :users, :name, :string, null: false
add_reference :products, :category, null: false
change_table :users do |t|
t.string :name, null: false
end
# good
add_column :users, :name, :string, null: true
add_column :users, :name, :string, null: false, default: ''
change_table :users do |t|
t.string :name, null: false, default: ''
end
add_reference :products, :category
add_reference :products, :category, null: false, default: 1
change_column_null :products, :category_id, false
----
=== Configurable attributes
Expand Down Expand Up @@ -3869,6 +3895,10 @@ Using `pluck` followed by `first` creates an intermediate array, which
`pick` avoids. When called on an Active Record relation, `pick` adds a
limit to the query so that only one value is fetched from the database.
Note that when `pick` is added to a relation with an existing limit, it
causes a subquery to be added. In most cases this is undesirable, and
care should be taken while resolving this violation.
=== Safety
This cop is unsafe because `pluck` is defined on both `ActiveRecord::Relation` and `Enumerable`,
Expand Down Expand Up @@ -6612,17 +6642,23 @@ Rails.env == 'production'
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Disabled
| Yes
| No
| 2.11
| -
| 2.25
|===
Suggests you remove a column that does not exist in the schema from `ignored_columns`.
`ignored_columns` is necessary to drop a column from RDBMS, but you don't need it after the migration
to drop the column. You avoid forgetting to remove `ignored_columns` by this cop.
IMPORTANT: This cop can't be used to effectively check for unused columns because the development
and production schema can be out of sync until the migration has been run on production. As such,
this cop can cause `ignored_columns` to be removed even though the production schema still contains
the column, which can lead to downtime when the migration is actually executed. Only enable this cop
if you know your migrations will be run before any of your Rails applications boot with the modified code.
=== Examples
[source,ruby]
Expand Down Expand Up @@ -6729,7 +6765,7 @@ validates :foo, length: true
validates :foo, numericality: true
validates :foo, presence: true
validates :foo, absence: true
validates :foo, size: true
validates :foo, length: true
validates :foo, uniqueness: true
----
Expand Down Expand Up @@ -6984,3 +7020,48 @@ User.where.not('trashed = ? OR role = ?', true, 'admin')
=== References
* https://rails.rubystyle.guide/#where-not-with-multiple-attributes
== Rails/WhereRange
NOTE: Required Ruby version: 2.6
|===
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
| Pending
| Yes
| Always
| 2.25
| -
|===
Identifies places where manually constructed SQL
in `where` can be replaced with ranges.
=== Examples
[source,ruby]
----
# bad
User.where('age >= ?', 18)
User.where.not('age >= ?', 18)
User.where('age < ?', 18)
User.where('age >= ? AND age < ?', 18, 21)
User.where('age >= :start', start: 18)
User.where('users.age >= ?', 18)
# good
User.where(age: 18..)
User.where.not(age: 18..)
User.where(age: ...18)
User.where(age: 18...21)
User.where(users: { age: 18.. })
# good
# There are no beginless ranges in ruby.
User.where('age > ?', 18)
----
=== References
* https://rails.rubystyle.guide/#where-ranges
2 changes: 1 addition & 1 deletion lib/rubocop/rails/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module RuboCop
module Rails
# This module holds the RuboCop Rails version information.
module Version
STRING = '2.24.1'
STRING = '2.25.0'

def self.document_version
STRING.match('\d+\.\d+').to_s
Expand Down
24 changes: 24 additions & 0 deletions relnotes/v2.25.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### New features

* [#1272](https://github.com/rubocop/rubocop-rails/pull/1272): Add new `Rails/WhereRange` cop. ([@fatkodima][])

### Bug fixes

* [#1270](https://github.com/rubocop/rubocop-rails/issues/1270): Fix an incorrect autocorrect for `Rails/Validation` when using `validates_size_of`. ([@koic][])
* [#1278](https://github.com/rubocop/rubocop-rails/issues/1278): Fix a false positive for `Rails/SkipsModelValidations` when using `insert` or `insert!` with a safe navigator. ([@tldn0718][])
* [#1260](https://github.com/rubocop/rubocop-rails/issues/1260): Fix a performance regression caused by `Rails/UnknownEnv` when using Rails 7.1. ([@lukasfroehlich1][])

### Changes

* [#1249](https://github.com/rubocop/rubocop-rails/issues/1249): Disable `Rails/UnusedIgnoredColumns` by default. ([@earlopain][])
* [#1266](https://github.com/rubocop/rubocop-rails/pull/1266): Check `change_table` calls for offenses. ([@ccutrer][])
* [#1267](https://github.com/rubocop/rubocop-rails/pull/1267): Make `Rails/HttpStatus` aware of Rails-specific response assertions. ([@tldn0718][])
* [#1137](https://github.com/rubocop/rubocop-rails/pull/1137): Migrate to `TargetRailsVersion` the new [`requires_gem` API](https://github.com/rubocop/rubocop/pull/12186). ([@amomchilov][])

[@fatkodima]: https://github.com/fatkodima
[@koic]: https://github.com/koic
[@tldn0718]: https://github.com/tldn0718
[@lukasfroehlich1]: https://github.com/lukasfroehlich1
[@earlopain]: https://github.com/earlopain
[@ccutrer]: https://github.com/ccutrer
[@amomchilov]: https://github.com/amomchilov

0 comments on commit 809fd54

Please sign in to comment.