Skip to content

Commit

Permalink
Merge pull request #1360 from presidentbeef/get_rid_of_nil_lines
Browse files Browse the repository at this point in the history
Avoid assigning nil line numbers to Sexps
  • Loading branch information
presidentbeef committed Jun 5, 2019
2 parents 59c8941 + a84f666 commit 3b0017f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/brakeman/processors/alias_processor.rb
Expand Up @@ -602,7 +602,7 @@ def process_hash exp
if node_type? exp, :hash
if exp.any? { |e| node_type? e, :kwsplat and node_type? e.value, :hash }
kwsplats, rest = exp.partition { |e| node_type? e, :kwsplat and node_type? e.value, :hash }
exp = Sexp.new.concat(rest).line(exp)
exp = Sexp.new.concat(rest).line(exp.line)

kwsplats.each do |e|
exp = process_hash_merge! exp, e.value
Expand Down
8 changes: 4 additions & 4 deletions lib/brakeman/processors/controller_processor.rb
Expand Up @@ -192,8 +192,8 @@ def add_fake_filter exp

filter_name = ("fake_filter" + rand.to_s[/\d+$/]).to_sym
args = exp.block_call.arglist
args.insert(1, Sexp.new(:lit, filter_name))
before_filter_call = make_call(nil, :before_filter, args)
args.insert(1, Sexp.new(:lit, filter_name).line(exp.line))
before_filter_call = make_call(nil, :before_filter, args).line(exp.line)

if exp.block_args.length > 1
block_variable = exp.block_args[1]
Expand All @@ -210,9 +210,9 @@ def add_fake_filter exp
#Build Sexp for filter method
body = Sexp.new(:lasgn,
block_variable,
Sexp.new(:call, Sexp.new(:const, @current_class.name), :new))
Sexp.new(:call, Sexp.new(:const, @current_class.name).line(exp.line), :new).line(exp.line)).line(exp.line)

filter_method = Sexp.new(:defn, filter_name, Sexp.new(:args), body).concat(block_inner).line(exp.line)
filter_method = Sexp.new(:defn, filter_name, Sexp.new(:args).line(exp.line), body).concat(block_inner).line(exp.line)

vis = @visibility
@visibility = :private
Expand Down
2 changes: 1 addition & 1 deletion lib/brakeman/processors/haml_template_processor.rb
Expand Up @@ -179,7 +179,7 @@ def get_pushed_value exp, default = :output
clauses = [get_pushed_value(exp.then_clause), get_pushed_value(exp.else_clause)].compact

if clauses.length > 1
s(:or, *clauses)
s(:or, *clauses).line(exp.line)
else
clauses.first
end
Expand Down
4 changes: 2 additions & 2 deletions lib/brakeman/processors/template_processor.rb
Expand Up @@ -61,9 +61,9 @@ def normalize_output arg
branches = [arg.then_clause, arg.else_clause].compact

if branches.empty?
s(:nil)
s(:nil).line(arg.line)
elsif branches.length == 2
Sexp.new(:or, *branches)
Sexp.new(:or, *branches).line(arg.line)
else
branches.first
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_parser/bm_sexp.rb
Expand Up @@ -40,7 +40,7 @@ def deep_clone line = nil
s.line(line)
else
s.original_line = self.original_line
s.line(self.line)
s.line(self.line) if self.line
end

s
Expand Down

0 comments on commit 3b0017f

Please sign in to comment.