Skip to content

Commit

Permalink
Use simple method checks from MethInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
presidentbeef committed Jul 13, 2021
1 parent 8a3580f commit ba541af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lib/brakeman/tracker/collection.rb
Expand Up @@ -50,7 +50,7 @@ def add_option name, exp

def add_method visibility, name, src, file_name
meth_info = Brakeman::MethodInfo.new(name, src, self, file_name)
add_simple_method_maybe meth_info
add_simple_method_maybe meth_info

if src.node_type == :defs
@class_methods[name] = meth_info
Expand Down Expand Up @@ -121,28 +121,15 @@ def get_simple_method_return_value type, name

private

def add_simple_method_maybe meth_info
src = meth_info.src

# Simple methods have one (simple) expression in the body and
# no arguments
if src.formal_args.length == 1 # no args
body = src.body
if body.length == 1 # single expression in body
value = body.first

if simple_literal? value or
all_literals? value, :array or
all_literals? value, :hash

add_simple_method meth_info, value
end
end
def add_simple_method_maybe meth_info
if meth_info.very_simple_method?
add_simple_method meth_info
end
end

def add_simple_method meth_info, value
name = meth_info.name
def add_simple_method meth_info
name = meth_info.name
value = meth_info.return_value

case meth_info.src.node_type
when :defn
Expand Down
2 changes: 2 additions & 0 deletions lib/brakeman/tracker/method_info.rb
Expand Up @@ -19,6 +19,8 @@ def initialize name, src, owner, file
else
raise "Expected sexp type: #{src.node_type}"
end

@simple_method = nil
end

# To support legacy code that expected a Hash
Expand Down

0 comments on commit ba541af

Please sign in to comment.