Class: RuboCop::Cop::Decidim::MessageAntipattern
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Decidim::MessageAntipattern
- Defined in:
- lib/decidim/dev/rubocop/cop/decidim/message_antipattern.rb
Constant Summary collapse
- SINGLE_WORD_ANTI_PATTERNS =
%w( successfully problem error warning done complete finished ok okay saved updated created deleted removed published unpublished ).freeze
- MSG =
"Anti-pattern detected: avoid generic single-word text in have_callout/have_admin_callout/have_content. " \ "Use the full admin flash message, e.g. 'Meeting successfully published'. " \ "Exception: when used inside `within` blocks (e.g., for checking `.label` elements)."
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/decidim/dev/rubocop/cop/decidim/message_antipattern.rb', line 32 def on_send(node) return unless [:have_callout, :have_admin_callout, :have_content].include?(node.method_name) return if within_block?(node) first_argument = node.first_argument return unless first_argument if first_argument.nil_type? add_offense(first_argument, message: MSG) return end return unless first_argument.str_type? text = first_argument.value return unless antipattern_text?(text) add_offense(first_argument, message: MSG) end |