Sha256: c44dfffec9460ab1d6ff36289d761ce41bbbb0660c8ebae28478232e347c6c15

Contents?: true

Size: 911 Bytes

Versions: 4

Compression:

Stored size: 911 Bytes

Contents

require 'simplabs/excellent/checks/base'

module Simplabs

  module Excellent

    module Checks

      # This check reports code that uses +for+ loops as in:
      #
      #  for user in @users
      #    do_something(user)
      #  end
      #
      # The use of for loops in Ruby is contrary to the language's basic concept of iterators. The above statement would better be written as:
      #
      #  @users.each do |user|
      #    do_something(user)
      #  end
      #
      # ==== Applies to
      #
      # * +for+ loops
      class ForLoopCheck < Base

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

        def evaluate(context) #:nodoc:
          add_warning(context, 'For loop used.')
        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/for_loop_check.rb
excellent-2.1.0 lib/simplabs/excellent/checks/for_loop_check.rb
excellent-2.0.1 lib/simplabs/excellent/checks/for_loop_check.rb
excellent-2.0.0 lib/simplabs/excellent/checks/for_loop_check.rb