Skip to content

Commit

Permalink
Fix deprecated ERB and BigDecimal instances (#15189)
Browse files Browse the repository at this point in the history
  • Loading branch information
roaksoax authored Jul 18, 2023
1 parent 5d6aa10 commit d95a0bb
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ AllCops:
##### Enabled Cops #####
Lint/DeprecatedClassMethods:
Enabled: true
Lint/ErbNewArguments:
Enabled: true
Lint/BigDecimalNew:
Enabled: true

#################### Layout ###########################
##### Enabled Cops #####
Expand Down
2 changes: 1 addition & 1 deletion lib/pluginmanager/proxy_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def configure_proxy
FileUtils.mkdir_p(SETTINGS_TARGET)
target = ::File.join(SETTINGS_TARGET, "settings.xml")
template = ::File.read(SETTINGS_TEMPLATE)
template_content = ERB.new(template, 3).result(ProxyTemplateData.new(proxies).get_binding)
template_content = ERB.new(template).result(ProxyTemplateData.new(proxies).get_binding)

if ::File.exist?(target)
if template_content != ::File.read(target)
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/spec/logstash/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
# BigDecimal is now natively converted by JRuby, see https://github.com/elastic/logstash/pull/4838
it "should set BigDecimal" do
e = LogStash::Event.new()
e.set("[foo]", BigDecimal.new(1))
e.set("[foo]", BigDecimal(1))
expect(e.get("foo")).to be_kind_of(BigDecimal)
expect(e.get("foo")).to eq(BigDecimal.new(1))
expect(e.get("foo")).to eq(BigDecimal(1))
end

it "should set RubyInteger" do
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/spec/logstash/legacy_ruby_timestamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@

context "with BigDecimal epoch" do
it "should convert to correct date" do
expect(LogStash::Timestamp.at(BigDecimal.new("946702800.123456789")).to_iso8601).to eq("2000-01-01T05:00:00.123456789Z")
expect(LogStash::Timestamp.at(BigDecimal("946702800.123456789")).to_iso8601).to eq("2000-01-01T05:00:00.123456789Z")
end

it "should return usec with a minimum of millisec precision" do
expect(LogStash::Timestamp.at(BigDecimal.new("946702800.123456789")).usec).to be_within(1000).of(123456)
expect(LogStash::Timestamp.at(BigDecimal("946702800.123456789")).usec).to be_within(1000).of(123456)
end
end

Expand Down
2 changes: 1 addition & 1 deletion qa/integration/framework/fixture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def config(node = "root", options = nil)
end

if options != nil
ERB.new(config, nil, "-").result(TemplateContext.new(options).get_binding)
ERB.new(config, trim_mode: "-").result(TemplateContext.new(options).get_binding)
else
config
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def extension

private
def read_template(file)
ERB.new(::File.read(file), nil, "-")
ERB.new(::File.read(file), trim_mode: "-")
end

def post_process!(context, erb)
Expand Down
2 changes: 1 addition & 1 deletion tools/logstash-docgen/lib/logstash/docgen/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def generate
.sort
.collect { |file| ::File.basename(file, ASCIIDOC_EXTENSION) }

template = ERB.new(TEMPLATES[type.to_sym], nil, "-")
template = ERB.new(TEMPLATES[type.to_sym], trim_mode: "-")
save(type, template.result(IndexContext.new(type, plugins).get_binding))
end
end
Expand Down
2 changes: 1 addition & 1 deletion x-pack/lib/monitoring/monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def generate_pipeline_config(settings)

template_path = ::File.join(::File.dirname(__FILE__), "..", "template.cfg.erb")
template = ::File.read(template_path)
ERB.new(template, 3).result(data.get_binding)
ERB.new(template).result(data.get_binding)
end

private
Expand Down

0 comments on commit d95a0bb

Please sign in to comment.