Sha256: 4aa8f4a2ca17dd79302a832561174c4055b0fc3c39a5b4a37b39b615478e00ef

Contents?: true

Size: 917 Bytes

Versions: 2

Compression:

Stored size: 917 Bytes

Contents

# encoding: utf-8

module Pelusa
  module Lint
    class EvalUsage

      def initialize
        @violations = Set.new
      end

      def check(klass)
        iterate_lines!(klass)

        if @violations.empty?
          SuccessfulAnalysis.new(name)
        else
          FailedAnalysis.new(name, @violations) do |violations|
            "There are #{violations.length} eval statement in lines #{violations.to_a.join(', ')}"
          end
        end
      end

      private

      def name
        "Doesn't use eval statement"
      end

      def iterate_lines!(klass)
        iterator = Iterator.new do |node|
          @violations << node.line if eval_violation?(node)
        end
        Array(klass).each(&iterator)
      end

      def eval_violation?(node)
        node.is_a?(Rubinius::AST::SendWithArguments) && node.name == :eval && node.receiver.is_a?(Rubinius::AST::Self)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pelusa-0.2.2 lib/pelusa/lint/eval_usage.rb
pelusa-0.2.1 lib/pelusa/lint/eval_usage.rb