Class: Skeptic::Rules::MaxNestingDepth
- Inherits:
-
Object
- Object
- Skeptic::Rules::MaxNestingDepth
- Includes:
- SexpVisitor
- Defined in:
- lib/skeptic/rules/max_nesting_depth.rb
Constant Summary collapse
- DESCRIPTION =
'Limit the maximum nesting depth'
Instance Method Summary collapse
- #apply_to(code, tokens, sexp) ⇒ Object
-
#initialize(limit = nil) ⇒ MaxNestingDepth
constructor
A new instance of MaxNestingDepth.
- #name ⇒ Object
- #nestings ⇒ Object
- #violations ⇒ Object
Methods included from SexpVisitor
Constructor Details
#initialize(limit = nil) ⇒ MaxNestingDepth
Returns a new instance of MaxNestingDepth.
8 9 10 11 12 |
# File 'lib/skeptic/rules/max_nesting_depth.rb', line 8 def initialize(limit = nil) env[:scope] = Scope.new @scopes = [] @limit = limit end |
Instance Method Details
#apply_to(code, tokens, sexp) ⇒ Object
14 15 16 17 |
# File 'lib/skeptic/rules/max_nesting_depth.rb', line 14 def apply_to(code, tokens, sexp) visit sexp self end |
#name ⇒ Object
29 30 31 |
# File 'lib/skeptic/rules/max_nesting_depth.rb', line 29 def name "Maximum nesting depth (#@limit)" end |
#nestings ⇒ Object
19 20 21 |
# File 'lib/skeptic/rules/max_nesting_depth.rb', line 19 def nestings @scopes.uniq end |
#violations ⇒ Object
23 24 25 26 27 |
# File 'lib/skeptic/rules/max_nesting_depth.rb', line 23 def violations @scopes.select { |scope| scope.depth > @limit }.map do |scope| "#{scope.location} has #{scope.depth} levels of nesting: #{scope.levels.join(' > ')}" end end |