Class: Simplabs::Excellent::Checks::CaseMissingElseCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/case_missing_else_check.rb

Overview

This check reports case statements that don’t have an else clause that would be executed when no case matches. If the tested value will never adopt any other values than the ones tested for in the cases, this should be expressed in the code by e.g. throwing an exception in the else clause.

Applies to

  • case statements

Instance Attribute Summary

Attributes inherited from Base

#interesting_files, #interesting_nodes, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_node, #warnings_for

Constructor Details

#initializeCaseMissingElseCheck

:nodoc:



18
19
20
21
22
# File 'lib/simplabs/excellent/checks/case_missing_else_check.rb', line 18

def initialize #:nodoc:
  super
  @interesting_nodes = [:case]
  @interesting_files = [/\.rb$/, /\.erb$/]
end

Instance Method Details

#evaluate(context) ⇒ Object

:nodoc:



24
25
26
# File 'lib/simplabs/excellent/checks/case_missing_else_check.rb', line 24

def evaluate(context) #:nodoc:
  add_warning(context, 'Case statement is missing else clause.') unless context.has_else_clause?
end