-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Rails/RedundantPresenceValidationOnBelongsTo detect an offence on validations with custom messages. #620
Comments
I believe that the correct way of setting the message is via I18n files. E.g. for class Foo < ApplicationRecord
belongs_to :bar
validates :bar, presence: { message: 'show me the way to the next whiskey bar' }
end The convention is to: # config/locales/en.yml (or config/locales/activerecord/en.yml depending on your preference)
en:
activerecord:
errors:
models:
foo:
attributes:
name:
required: show me the way to the next whiskey bar I don't particularly agree that the cop should ignore such validation. We've marked the cop as unsafe for autocorrection, see #615, specifically because it affects the wording of the error message. Would you like to send a PR with a clarification regarding error message I18n for |
I think this issue can be divided as follows:
|
Pirj, I wonder how common that is for rails apps unless they are localizing. |
Sounds reasonable 👍 Let's split the job, I can take care of the I18n cop. Would you send a PR with |
I will take it because there are #616 adjustments. |
Should be pretty common: https://rails.rubystyle.guide/#locale-texts |
…lidationOnBelongsTo` Fixes rubocop#620. This PR fixes a false positive for `Rails/RedundantPresenceValidationOnBelongsTo` using presence with a message and reverts rubocop#616 because accept the use case.
…lidationOnBelongsTo` Fixes rubocop#620. This PR fixes a false positive for `Rails/RedundantPresenceValidationOnBelongsTo` using presence with a message.
…ndant_presence_validation_on_belongs_to [Fix #620] Fix a false positive for `Rails/RedundantPresenceValidationOnBelongsTo`
Rails/RedundantPresenceValidationOnBelongsTo detect and offence with a custom message attribute.
Expected behavior
Actual behavior
rubocop raises an offense and will remove the validation on autocorrect.
Steps to reproduce the problem
Add a validation block to a model as above and run rubocop.
RuboCop version
The text was updated successfully, but these errors were encountered: