Sha256: 905ef2e27c6f0411a753a8d57870f6d0ff27f1e1d4053bdd879432283be42450

Contents?: true

Size: 902 Bytes

Versions: 4

Compression:

Stored size: 902 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      # 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
      class CaseMissingElseCheck < Base

        def initialize(options = {}) #:nodoc:
          super
          @interesting_contexts = [Parsing::CaseContext]
          @interesting_files    = [/\.rb$/, /\.erb$/]
        end

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

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
excellent-2.1.1 lib/simplabs/excellent/checks/case_missing_else_check.rb
excellent-2.1.0 lib/simplabs/excellent/checks/case_missing_else_check.rb
excellent-2.0.1 lib/simplabs/excellent/checks/case_missing_else_check.rb
excellent-2.0.0 lib/simplabs/excellent/checks/case_missing_else_check.rb