Class: Bparity::Formal::Deductive::FragmentChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/bparity/formal/deductive.rb

Constant Summary collapse

FORBIDDEN_NODES =
%i[class_variable_write_node global_variable_write_node instance_variable_write_node
call_and_write_node call_operator_write_node].freeze
FORBIDDEN_CALLS =
%i[eval binding send public_send method_missing define_method rand sleep].freeze

Instance Method Summary collapse

Instance Method Details

#check_file(path, method_name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bparity/formal/deductive.rb', line 29

def check_file(path, method_name)
  result = Prism.parse_file(path)
  return ["syntax error"] unless result.success?

  method = nodes(result.value).find { |node| node.type == :def_node && node.name.to_s == method_name.to_s }
  return ["method #{method_name} was not found"] unless method

  nodes(method).filter_map do |node|
    if FORBIDDEN_NODES.include?(node.type)
      "#{node.type} at line #{node.location.start_line}"
    elsif node.type == :call_node && FORBIDDEN_CALLS.include?(node.name)
      "#{node.name} at line #{node.location.start_line}"
    end
  end
end