New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When NewCops: enable
, Rails/UnusedIgnoredColumns reports error reading model which has self.ignored_columns
#692
Comments
This error is related to schema definition. Can you provide the schema definition of db/schema.rb for the reproduction model? |
Thank you for your quick response. The app uses a database which is externally managed and I can't make changes to it. because of that, I don't have a schema definition. This is my db/schema.rb. # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 0) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
end |
NewCops: enabled
, Rails/UnusedIgnoredColumns reports error with model witch have self.ignored_columns
NewCops: enabled
, Rails/UnusedIgnoredColumns reports error reading model which has self.ignored_columns
Hm, I've placed the model and db/schema.rb, but the error cannot be reproduced. % bundle exec rubocop -V
1.27.0 (using Parser 3.1.1.0, rubocop-ast 1.17.0, running on ruby 3.1.2 x86_64-darwin19)
- rubocop-minitest 0.19.1
- rubocop-performance 1.13.3
- rubocop-rails 2.14.2
- rubocop-rspec 2.2.0
% tree .
.
├── app
│ └── models
│ └── my_model.rb
└── db
└── schema.rb
3 directories, 2 files
% cat app/models/my_model.rb
class MyModel < ApplicationRecord
self.ignored_columns = [:my_column]
end
% cat db/schema.rb
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 0) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
end
% bundle exec rubocop --only Rails/UnusedIgnoredColumns
(snip)
Inspecting 1 file
.
1 file inspected, no offenses detected |
I think you should put |
NewCops: enabled
, Rails/UnusedIgnoredColumns reports error reading model which has self.ignored_columns
NewCops: enable
, Rails/UnusedIgnoredColumns reports error reading model which has self.ignored_columns
root@a0d937df4b8b:/usr/local/app# bundle exec rubocop -V
1.27.0 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.1.2 aarch64-linux)
- rubocop-rails 2.14.2 root@a0d937df4b8b:/usr/local/app# tree .
.
├── Gemfile
├── Gemfile.lock
├── app
│ └── models
│ ├── application_record.rb
│ └── my_model.rb
└── db
└── schema.rb
3 directories, 5 files root@a0d937df4b8b:/usr/local/app# cat app/models/application_record.rb
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end root@a0d937df4b8b:/usr/local/app# cat app/models/my_model.rb
# frozen_string_literal: true
class MyModel < ApplicationRecord
self.ignored_columns = [:model_name]
end root@a0d937df4b8b:/usr/local/app# cat db/schema.rb
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 0) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
end root@a0d937df4b8b:/usr/local/app# cat .rubocop.yml
require:
- rubocop-rails
AllCops:
NewCops: enable root@a0d937df4b8b:/usr/local/apbundle exec rubocop --only Rails/UnusedIgnoredColumnsmns
An error occurred while Rails/UnusedIgnoredColumns cop was inspecting /usr/local/app/app/models/my_model.rb:4:2.
To see the complete backtrace run rubocop -d.
Inspecting 3 files
..An error occurred while Rails/UnusedIgnoredColumns cop was inspecting /usr/local/app/app/models/my_model.rb:4:2.
To see the complete backtrace run rubocop -d.
.
3 files inspected, no offenses detected
1 error occurred:
An error occurred while Rails/UnusedIgnoredColumns cop was inspecting /usr/local/app/app/models/my_model.rb:4:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.27.0 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.1.2 aarch64-linux) |
The error type is different, but I'm able to reproduce it. I will work on it. |
Fixes rubocop#692. This PR fixes an error for `Rails/UnusedIgnoredColumns` when using no tables db/schema.rb.
Thank you for your feedback. I've opened a PR #693 to resolve the issue. |
…ed_columns [Fix #692] Fix an error for `Rails/UnusedIgnoredColumns`
The cop throws an error inspecting my_model.rb that includes
self.ignored_columns = [:any_column]
.rubocop.yml
Expected behavior
rubocop exit without any error.
Actual behavior
It reports an error.
Steps to reproduce the problem
put
.rubocop.yml
withNewCops: enabled
and create model withself.ignore_columns = [:hoge]
, thenbundle exec rubocop
RuboCop version
# bundle exec rubocop -V 1.27.0 (using Parser 3.1.1.0, rubocop-ast 1.17.0, running on ruby 3.1.2 x86_64-linux) - rubocop-rails 2.14.2
The text was updated successfully, but these errors were encountered: