提交 45f563e9 编写于 作者: J Justin Collins

Merge branch 'fix_process_defn_in_ruby2ruby'

......@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.executables = ["brakeman"]
s.license = "MIT"
s.add_dependency "ruby_parser", "~>3.1.1"
s.add_dependency "ruby2ruby", "2.0.3"
s.add_dependency "ruby2ruby", "~>2.0.5"
s.add_dependency "terminal-table", "~>1.4"
s.add_dependency "fastercsv", "~>1.5"
s.add_dependency "highline", "~>1.6.19"
......
......@@ -14,7 +14,6 @@ class Brakeman::OutputProcessor < Ruby2Ruby
end
alias process_safely format
alias process_methdef process_defn
def process exp
begin
......@@ -99,6 +98,29 @@ class Brakeman::OutputProcessor < Ruby2Ruby
out
end
def process_defn exp
# Copied from Ruby2Ruby except without the whole
# "convert methods to attr_*" stuff
name = exp.shift
args = process exp.shift
args = "" if args == "()"
exp.shift if exp == s(s(:nil)) # empty it out of a default nil expression
body = []
until exp.empty? do
body << indent(process(exp.shift))
end
body << indent("# do nothing") if body.empty?
body = body.join("\n")
return "def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
end
alias process_methdef process_defn
def process_call_with_block exp
call = process exp[0]
block = process_rlist exp[2..-1]
......
......@@ -191,7 +191,7 @@ module BrakemanTester::RescanTestHelper
output = yield parsed
File.open path, "w" do |f|
f.puts Ruby2Ruby.new.process output
f.puts Brakeman::OutputProcessor.new.process output
end
end
......
......@@ -144,4 +144,21 @@ class OutputProcessorTests < Test::Unit::TestCase
Sexp.new(:args),
Sexp.new(:call, nil, :y))
end
# Ruby2Ruby tries to convert some methods to attr_* calls,
# but it breaks some stuff because of how it accesses nodes.
# So we overwrite it.
def test_output_defn_not_attr
assert_output "def x\n @x\nend",
Sexp.new(:defn,
:x,
Sexp.new(:args),
Sexp.new(:ivar, :@x))
assert_output "def x(y)\n @x = (local y)\nend",
Sexp.new(:methdef,
:x,
Sexp.new(:args, :y),
Sexp.new(:iasgn, :@x, Sexp.new(:lvar, :y)))
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册