lib/yardcheck/observation.rb in yardcheck-0.0.1 vs lib/yardcheck/observation.rb in yardcheck-0.0.2

- old
+ new

@@ -3,11 +3,11 @@ module Yardcheck class Observation include Concord.new(:documentation, :event) def violations - param_violations + return_violations + param_violations + return_violations + raise_violations end def source_code documentation.source end @@ -34,14 +34,22 @@ def documented_return_type documentation.return_type end + def documented_raise_type + documentation.raise_type + end + def actual_return_type event.return_value.type end + def actual_raise_type + event.exception.type + end + def documentation_warnings documentation.warnings end private @@ -57,16 +65,34 @@ Violation::Param.new(key, self) end end def return_violations - invalid_return_type? ? [Violation::Return.new(self)] : [] + invalid_return? ? [Violation::Return.new(self)] : [] end - def invalid_return_type? - documentation.return_type && + def raise_violations + invalid_raise? ? [Violation::Raise.new(self)] : [] + end + + def invalid_raise? + documentation.raise_type && + event.raise? && + !documentation.raise_type.match?(event.exception) + end + + def invalid_return? + documentation.return_type && + event.return? && !documentation.return_type.match?(event.return_value) && - !event.raised? && - !event.initialize? + !event.initialize? && + !documentation.predicate_method? && + !possible_tracepoint_bug? + end + + def possible_tracepoint_bug? + return false unless event.return_value.is?(nil) + + documentation.processed_source.tracepoint_bug_candidate? end end # Observation end # Yardcheck