Class: RuboCop::Cop::Legion::Extension::LlmAskKwargs
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::Extension::LlmAskKwargs
- Defined in:
- lib/rubocop/cop/legion/extension/llm_ask_kwargs.rb
Overview
Detects calls to ‘Legion::LLM.ask` with extra keyword arguments beyond `message:`. The method signature is `ask(message:)` with no splat — extra kwargs raise `ArgumentError` at runtime.
Constant Summary collapse
- RESTRICT_ON_SEND =
%i[ask].freeze
- MSG =
'`Legion::LLM.ask` only accepts `message:` keyword. ' \ 'Remove extra keyword arguments.'
Instance Method Summary collapse
Instance Method Details
#legion_llm_ask?(node) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/rubocop/cop/legion/extension/llm_ask_kwargs.rb', line 24 def_node_matcher :legion_llm_ask?, <<~PATTERN (send (const (const nil? :Legion) :LLM) :ask ...) PATTERN |
#on_send(node) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/legion/extension/llm_ask_kwargs.rb', line 31 def on_send(node) return unless legion_llm_ask?(node) hash_arg = node.arguments.find(&:hash_type?) return unless hash_arg extra_keys = hash_arg.pairs.reject do |pair| pair.key.sym_type? && pair.key.value == :message end add_offense(node) if extra_keys.any? end |