Class: RuboCop::Cop::Legion::Framework::NoInlineSettingDefaults
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::Framework::NoInlineSettingDefaults
- Defined in:
- lib/rubocop/cop/legion/framework/no_inline_setting_defaults.rb
Overview
Detects ‘Legion::Settings` reads combined with inline literal fallbacks (`|| <literal>`) or shadow-default patterns (`x = N unless x.positive?`). Per G13, all defaults belong in `settings.rb` — inline fallbacks are dead code after `register_defaults!` merge.
No auto-correct is provided because the fix requires moving the literal into the appropriate ‘*_defaults` group in settings.rb.
Constant Summary collapse
- MSG_OR =
'Inline default `%<default>s` after `Legion::Settings` read. ' \ 'Move the default into `settings.rb` instead.'
- MSG_SHADOW =
'Shadow-default pattern after `Legion::Settings` read. ' \ 'Move the default into `settings.rb` instead.'
Instance Method Summary collapse
Instance Method Details
#on_if(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/legion/framework/no_inline_setting_defaults.rb', line 42 def on_if(node) cond = node.condition return unless cond&.send_type? receiver = cond.receiver return unless receiver&.lvar_type? method_name = cond.method_name return unless %i[positive? nil? zero? empty? blank?].include?(method_name) var_name = receiver.children.first return unless preceded_by_settings_read?(node, var_name) add_offense(node, message: MSG_SHADOW) end |
#on_or(node) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rubocop/cop/legion/framework/no_inline_setting_defaults.rb', line 33 def on_or(node) left = node.children.first right = node.children.last return unless settings_read?(left) return unless right && literal?(right) add_offense(node, message: format(MSG_OR, default: right.source)) end |