Skip to content

Commit 53dd7d6

Browse files
TNSelahleTebogo Selahle
andauthored
refactor: use camelCase for buffer methods and symbols (#35)
Co-authored-by: Tebogo Selahle <[email protected]>
1 parent e12ba2d commit 53dd7d6

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/ruby_ast_gen/erb_to_ruby_transformer.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ class ErbToRubyTransformer
55
def initialize
66
@parser = Temple::ERB::Parser.new
77
@in_control_block = false
8-
@output_tmp_var = "self.joern__buffer"
9-
@output_tmp_append_func = "self.joern__buffer_append"
8+
@output_tmp_var = "self.joernBuffer"
9+
@output_tmp_append_func = "self.joernBufferAppend"
10+
@joern_template_out_raw = "joernTemplateOutRaw"
11+
@joern_template_out_escape = "joernTemplateOutEscape"
1012
@in_do_block = false
11-
@inner_buffer = "joern__inner_buffer"
13+
@inner_buffer = "joernInnerBuffer"
1214
@current_counter = 0
1315
@current_lambda_vars = ""
1416
@output = []
@@ -59,9 +61,9 @@ def visit(node)
5961
when :if
6062
if code.strip.start_with?("if") || code.strip.start_with?("unless")
6163
template_call = if escape_enabled
62-
"joern__template_out_raw"
64+
@joern_template_out_raw
6365
else
64-
"joern__template_out_escape"
66+
@joern_template_out_escape
6567
end
6668

6769
if_cond = extract_code_snippet(ast.children[0].location, code)
@@ -81,18 +83,18 @@ def visit(node)
8183
@output << "unless #{if_cond}"
8284
end
8385
template_call = if escape_enabled
84-
"joern__template_out_raw"
86+
@joern_template_out_raw
8587
else
86-
"joern__template_out_escape"
88+
@joern_template_out_escape
8789
end
8890
@output << "#{@output_tmp_append_func}(#{@output_tmp_var}, #{template_call}(#{call}))"
8991
end
9092
@output << "end"
9193
else
9294
template_call = if escape_enabled then
93-
"joern__template_out_raw"
95+
@joern_template_out_raw
9496
else
95-
"joern__template_out_escape"
97+
@joern_template_out_escape
9698
end
9799
@output << "#{@output_tmp_append_func}(#{@inner_buffer}, #{template_call}(#{code}))"
98100
end
@@ -102,16 +104,16 @@ def visit(node)
102104
lower_do_block(code)
103105
elsif @in_do_block
104106
template_call = if escape_enabled then
105-
"joern__template_out_raw"
107+
@joern_template_out_raw
106108
else
107-
"joern__template_out_escape"
109+
@joern_template_out_escape
108110
end
109111
@output << "#{@output_tmp_append_func}(#{@inner_buffer}, #{template_call}(#{code}))"
110112
else
111113
template_call = if escape_enabled then
112-
"joern__template_out_raw"
114+
@joern_template_out_raw
113115
else
114-
"joern__template_out_escape"
116+
@joern_template_out_escape
115117
end
116118
@output << "#{@output_tmp_append_func}(#{@output_tmp_var}, #{template_call}(#{code}))"
117119
end

spec/ruby_ast_gen_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ def foo(a, bar: "default")
162162
file_content = File.read(temp_erb_file.path)
163163
code = RubyAstGen::get_erb_content(file_content)
164164
expected = <<-HEREDOC
165-
self.joern__buffer = ""
166-
self.joern__buffer_append(self.joern__buffer, form_with(url: some_url))
165+
self.joernBuffer = ""
166+
self.joernBufferAppend(self.joernBuffer, form_with(url: some_url))
167167
rails_lambda_0 = lambda do |form|
168-
joern__inner_buffer = ""
169-
self.joern__buffer_append(joern__inner_buffer, joern__template_out_escape( form.text_field :name ))
170-
joern__inner_buffer
168+
joernInnerBuffer = ""
169+
self.joernBufferAppend(joernInnerBuffer, joernTemplateOutEscape( form.text_field :name ))
170+
joernInnerBuffer
171171
end
172-
self.joern__buffer_append(self.joern__buffer, rails_lambda_0.call(form))
172+
self.joernBufferAppend(self.joernBuffer, rails_lambda_0.call(form))
173173
HEREDOC
174174
expect(code).to eq(expected)
175175
end

0 commit comments

Comments
 (0)