Class: RubyLint::Analysis::LoopKeywords
- Defined in:
- lib/ruby-lint/analysis/loop_keywords.rb
Overview
Analysis class that checks if certain keywords are used inside a block/loop or not. For example, the following is not valid Ruby code:
next
But the following is valid:
[10, 20].each do |n|
next
end
The following isn't valid either:
def foo
next
end
See KEYWORDS for a list of the keywords that can only be used inside a loop.
Constant Summary collapse
- KEYWORDS =
List of keywords that can only be used inside a loop.
[:next, :break]
- STATEMENTS =
List of statements that do allow the use of the various keywords.
[:while, :until, :for]
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Iterator
#arity_cache, #arity_cache Hash containing the amount of arguments for
Instance Method Summary collapse
Methods inherited from Base
#add_message, #after_initialize, analyze?, #current_scope, #error, #info, #previous_scope, register, #set_current_scope, #set_previous_scope, #warning
Methods included from MethodEvaluation
Methods inherited from Iterator
#execute_callback, #initialize, #iterate, #skip_child_nodes!
Constructor Details
This class inherits a constructor from RubyLint::Iterator
Instance Method Details
#verify_keyword(keyword, node) ⇒ Object
59 60 61 62 63 |
# File 'lib/ruby-lint/analysis/loop_keywords.rb', line 59 def verify_keyword(keyword, node) if current_scope.type != :block and !@allow_keyword error("#{keyword} can only be used inside a loop/block", node) end end |