Skip to content
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

Add new Rails/DuplicateIgnoredColumns cop #761

Closed

Conversation

sikachu
Copy link

@sikachu sikachu commented Sep 9, 2022

This cop checks for duplicate calls to ActiveRecord::Base.ignored_columns= as the subsequent calls will override the first call.

Example:

# bad
class User < ApplicationRecord
  self.ignored_columns = %w(profile)
  self.ignored_columns = %w(birthday)
end

# good
class User < ApplicationRecord
  self.ignored_columns = %w(profile birthday)
end

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

This cop checks for duplicate calls to
`ActiveRecord::Base.ignore_columns=` as the subsequent calls will
override the first call.

Example:

    # bad
    class User < ApplicationRecord
      self.ignored_columns = %w(profile)
      self.ignored_columns = %w(birthday)
    end

    # good
    class User < ApplicationRecord
      self.ignored_columns = %w(profile birthday)
    end
@sikachu sikachu force-pushed the avoid-duplicate-ignored-columns-cop branch from dca42fd to 4a71187 Compare September 9, 2022 05:44
@sikachu sikachu changed the title Introduce AvoidDuplicateIgnoredColumns Add new Rails/AvoidDuplicateIgnoredColumns cop Sep 9, 2022
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/avoid_duplicate_ignored_columns.rb Outdated Show resolved Hide resolved
@koic
Copy link
Member

koic commented Sep 9, 2022

I think this cop can be provided an unsafe autocorrection. Do you plan to provide it in this PR?

@sikachu
Copy link
Author

sikachu commented Sep 9, 2022

I think this cop can be provided an unsafe autocorrection. Do you plan to provide it in this PR?

Sounds good! Let me take a look on how to implement it 😇

@sikachu sikachu changed the title Add new Rails/AvoidDuplicateIgnoredColumns cop Add new Rails/DuplicateIgnoredColumns cop Sep 9, 2022
@sikachu
Copy link
Author

sikachu commented Sep 27, 2022

I think I like the proposal in #771 better since it works better with inheritance and it's easier to implement an auto fix for it.

I'm closing this PR, so let's get #771 in. 😄

@sikachu sikachu closed this Sep 27, 2022
@sikachu sikachu deleted the avoid-duplicate-ignored-columns-cop branch September 27, 2022 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants