Class: RuboCop::Cop::Yattho::NoTagMemoize
- Inherits:
-
Cop
- Object
- Cop
- RuboCop::Cop::Yattho::NoTagMemoize
- Defined in:
- lib/rubocop/cop/yattho/no_tag_memoize.rb
Overview
This cop ensures that tags are not set with ||=
bad @system_arguments ||= :h1
good @system_arguments = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
good @system_arguments = :h2
Constant Summary collapse
- INVALID_MESSAGE =
<<~STR Avoid `[:tag] ||=`. Instead, try one of the following: - Don't allow consumers to update the tag by having a fixed tag (e.g. `system_arguments[:tag] = :div`) - Use the `fetch_or_fallback` helper to only allow a tag from a restricted list. STR
Instance Method Summary collapse
Instance Method Details
#on_or_asgn(node) ⇒ Object
37 38 39 |
# File 'lib/rubocop/cop/yattho/no_tag_memoize.rb', line 37 def on_or_asgn(node) add_offense(node, message: INVALID_MESSAGE) if tag_memoized?(node) end |