Skip to content

Catch more offenses in Cop/StaticTranslationDefinition

What does this MR do and why?

This MR improves this cop rule to catch more translation definitions in static scope.

The new implementation has a more pessimistic approach and only considers certain cases to be allowed.

The following cases are now banned:

class Record
  validates :foo, message: _('An error')

  included do # or prepended or class_methods
    self.error_message = _('Something went wrong.')
  end
end

This 👮 is disabled for HAML lint to reduce false positives because we consider all translation definitions in HAML files to be dynamic.

Closes #348693 (closed).

Refs !89833 (comment 985700149)

How to set up and validate locally

bundle exec rubocop --only Cop/StaticTranslationDefinition

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading