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

[Fix #227] Make Rails/UniqueValidationWithoutIndex aware of updating schema.rb #229

Merged

Conversation

koic
Copy link
Member

@koic koic commented Apr 8, 2020

Fixes #227.

This PR makes Rails/UniqueValidationWithoutIndex aware of updating db/schema.rb

Rails/UniqueValidationWithoutIndex cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior.

This PR ensures that changes to db/schema.rb affect the cache by overriding the following method:

# This method should be overridden when a cop's behavior depends
# on state that lives outside of these locations:
#
#   (1) the file under inspection
#   (2) the cop's source code
#   (3) the config (eg a .rubocop.yml file)
#
# For example, some cops may want to look at other parts of
# the codebase being inspected to find violations. A cop may
# use the presence or absence of file `foo.rb` to determine
# whether a certain violation exists in `bar.rb`.
#
# Overriding this method allows the cop to indicate to RuboCop's
# ResultCache system when those external dependencies change,
# ie when the ResultCache should be invalidated.
def external_dependency_checksum
  nil
end

https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239

See for more details: rubocop/rubocop#7496


Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the make_unique_validation_without_index_aware_schema branch 5 times, most recently from 2822a2f to 418d6c0 Compare April 9, 2020 00:37
…updating schema.rb

Fixes rubocop#227.

This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating
db/schema.rb

`Rails/UniqueValidationWithoutIndex` cop needs to know both model
and db/schema.rb changes to register an offense. However, with
default RuboCop, only changes to the model affect cache behavior.

This PR ensures that changes to db/schema.rb affect the cache by
overriding the following method:

```ruby
# This method should be overridden when a cop's behavior depends
# on state that lives outside of these locations:
#
#   (1) the file under inspection
#   (2) the cop's source code
#   (3) the config (eg a .rubocop.yml file)
#
# For example, some cops may want to look at other parts of
# the codebase being inspected to find violations. A cop may
# use the presence or absence of file `foo.rb` to determine
# whether a certain violation exists in `bar.rb`.
#
# Overriding this method allows the cop to indicate to RuboCop's
# ResultCache system when those external dependencies change,
# ie when the ResultCache should be invalidated.
def external_dependency_checksum
  nil
end
```

https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239

See for more details: rubocop/rubocop#7496
@koic koic force-pushed the make_unique_validation_without_index_aware_schema branch from 418d6c0 to 330f874 Compare April 9, 2020 00:42
@koic koic merged commit 885ecef into rubocop:master Apr 9, 2020
@koic koic deleted the make_unique_validation_without_index_aware_schema branch April 9, 2020 10:24
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.

Rails/UniqueValidationWithoutIndex keeps failing even if the issue has been resolved
1 participant