Skip to content

Commit

Permalink
Suppress 'warning: literal string will be frozen in the future'
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Aug 15, 2024
1 parent c575bfa commit eede534
Show file tree
Hide file tree
Showing 101 changed files with 348 additions and 147 deletions.
4 changes: 3 additions & 1 deletion lib/fluent/command/ctl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -67,7 +69,7 @@ def initialize(argv = ARGV)
end

def help_text
text = "\n"
text = +"\n"
if Fluent.windows?
text << "Usage: #{$PROGRAM_NAME} COMMAND [PID_OR_SVCNAME]\n"
else
Expand Down
12 changes: 7 additions & 5 deletions lib/fluent/command/plugin_config_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -79,7 +81,7 @@ def call
private

def dump_txt(dumped_config)
dumped = ""
dumped = +""
plugin_helpers = dumped_config.delete(:plugin_helpers)
if plugin_helpers && !plugin_helpers.empty?
dumped << "helpers: #{plugin_helpers.join(',')}\n"
Expand All @@ -101,7 +103,7 @@ def dump_txt(dumped_config)
end

def dump_section_txt(base_section, level = 0)
dumped = ""
dumped = +""
indent = " " * level
if base_section[:section]
sections = []
Expand Down Expand Up @@ -135,10 +137,10 @@ def dump_section_txt(base_section, level = 0)
end

def dump_markdown(dumped_config)
dumped = ""
dumped = +""
plugin_helpers = dumped_config.delete(:plugin_helpers)
if plugin_helpers && !plugin_helpers.empty?
dumped = "## Plugin helpers\n\n"
dumped = +"## Plugin helpers\n\n"
plugin_helpers.each do |plugin_helper|
dumped << "* #{plugin_helper_markdown_link(plugin_helper)}\n"
end
Expand All @@ -156,7 +158,7 @@ def dump_markdown(dumped_config)
end

def dump_section_markdown(base_section, level = 0)
dumped = ""
dumped = +""
if base_section[:section]
sections = []
params = base_section
Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/compat/formatter_utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/compat/output.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/compat/record_filter_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand All @@ -21,7 +23,7 @@ def filter_record(tag, time, record)
end

def format_stream(tag, es)
out = ''
out = +''
es.each {|time,record|
tag_temp = tag.dup
filter_record(tag_temp, time, record)
Expand Down
6 changes: 4 additions & 2 deletions lib/fluent/config/element.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -141,7 +143,7 @@ def check_not_fetched(&block)
def to_s(nest = 0)
indent = " " * nest
nindent = " " * (nest + 1)
out = ""
out = +""
if @arg.nil? || @arg.empty?
out << "#{indent}<#{@name}>\n"
else
Expand Down Expand Up @@ -230,7 +232,7 @@ def dump_value(k, v, nindent)
end

def self.unescape_parameter(v)
result = ''
result = +''
v.each_char { |c| result << LiteralParser.unescape_char(c) }
result
end
Expand Down
10 changes: 6 additions & 4 deletions lib/fluent/config/literal_parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -228,8 +230,8 @@ def scan_json(is_array)
# Yajl does not raise ParseError for incomplete json string, like '[1', '{"h"', '{"h":' or '{"h1":1'
# This is the reason to use JSON module.

buffer = (is_array ? "[" : "{")
line_buffer = ""
buffer = +(is_array ? "[" : "{")
line_buffer = +""

until result
char = getch
Expand All @@ -252,7 +254,7 @@ def scan_json(is_array)
# ignore comment char
end
buffer << line_buffer + "\n"
line_buffer = ""
line_buffer = +""
else
# '#' is a char in json string
line_buffer << char
Expand All @@ -263,7 +265,7 @@ def scan_json(is_array)

if char == "\n"
buffer << line_buffer + "\n"
line_buffer = ""
line_buffer = +""
next
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/config/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def self.enum_value(val, opts = {}, name = nil)
value
else
case type
when :string then value.to_s.force_encoding(Encoding::UTF_8)
when :string then (+(value.to_s)).force_encoding(Encoding::UTF_8)
when :integer then INTEGER_TYPE.call(value, opts, name)
when :float then FLOAT_TYPE.call(value, opts, name)
when :size then Config.size_value(value, opts, name)
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/config/yaml_parser/fluent_value.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -30,7 +32,7 @@ def to_element

StringValue = Struct.new(:val, :context) do
def to_s
context.instance_eval("\"#{val}\"")
context.instance_eval("\"#{val}\"").freeze
rescue Fluent::SetNil => _
''
rescue Fluent::SetDefault => _
Expand Down
6 changes: 4 additions & 2 deletions lib/fluent/log.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -205,7 +207,7 @@ def format=(fmt)
@format = :text
@formatter = Proc.new { |type, time, level, msg|
r = caller_line(type, time, @depth_offset, level)
r << msg
r += msg
r
}
when :json
Expand Down Expand Up @@ -550,7 +552,7 @@ def get_worker_id(type)

def event(level, args)
time = Time.now
message = @optional_header ? @optional_header.dup : ''
message = @optional_header ? @optional_header.dup : +''
map = @optional_attrs ? @optional_attrs.dup : {}
args.each {|a|
if a.is_a?(Hash)
Expand Down
8 changes: 5 additions & 3 deletions lib/fluent/match.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -43,7 +45,7 @@ def initialize(pat)
end

stack = []
regex = ['']
regex = [+'']
escape = false
dot = false

Expand Down Expand Up @@ -105,15 +107,15 @@ def initialize(pat)
elsif c == "{"
# or
stack.push []
regex.push ''
regex.push(+'')

elsif c == "}" && !stack.empty?
stack.last << regex.pop
regex.last << Regexp.union(*stack.pop.map {|r| Regexp.new(r) }).to_s

elsif c == "," && !stack.empty?
stack.last << regex.pop
regex.push ''
regex.push(+'')

elsif /[a-zA-Z0-9_]/.match?(c)
regex.last << c
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand All @@ -24,7 +26,7 @@ class Buffer
class FileChunk < Chunk
class FileChunkError < StandardError; end

BUFFER_HEADER = "\xc1\x00".force_encoding(Encoding::ASCII_8BIT).freeze
BUFFER_HEADER = (+"\xc1\x00").force_encoding(Encoding::ASCII_8BIT).freeze

### buffer path user specified : /path/to/directory/user_specified_prefix.*.log
### buffer chunk path : /path/to/directory/user_specified_prefix.b513b61c9791029c2513b61c9791029c2.log
Expand Down
6 changes: 4 additions & 2 deletions lib/fluent/plugin/buffer/memory_chunk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand All @@ -22,7 +24,7 @@ class Buffer
class MemoryChunk < Chunk
def initialize(metadata, compress: :text)
super
@chunk = ''.force_encoding(Encoding::ASCII_8BIT)
@chunk = (+'').force_encoding(Encoding::ASCII_8BIT)
@chunk_bytes = 0
@adding_bytes = 0
@adding_size = 0
Expand Down Expand Up @@ -68,7 +70,7 @@ def empty?

def purge
super
@chunk = ''.force_encoding("ASCII-8BIT")
@chunk = (+'').force_encoding("ASCII-8BIT")
@chunk_bytes = @size = @adding_bytes = @adding_size = 0
true
end
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/compressable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -57,7 +59,7 @@ def decompress(compressed_data = nil, output_io: nil, input_io: nil)
def string_decompress(compressed_data)
io = StringIO.new(compressed_data)

out = ''
out = +''
loop do
gz = Zlib::GzipReader.new(io)
out << gz.read
Expand Down
8 changes: 5 additions & 3 deletions lib/fluent/plugin/formatter_csv.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -50,13 +52,13 @@ def configure(conf)
end

@generate_opts = {col_sep: @delimiter, force_quotes: @force_quotes, headers: @fields,
row_sep: @add_newline ? :auto : "".force_encoding(Encoding::ASCII_8BIT)}
row_sep: @add_newline ? :auto : (+"").force_encoding(Encoding::ASCII_8BIT)}
# Cache CSV object per thread to avoid internal state sharing
@cache = {}
end

def format(tag, time, record)
csv = (@cache[Thread.current] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
csv = (@cache[Thread.current] ||= CSV.new((+"").force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
line = (csv << record).string.dup
# Need manual cleanup because CSV writer doesn't provide such method.
csv.rewind
Expand All @@ -65,7 +67,7 @@ def format(tag, time, record)
end

def format_with_nested_fields(tag, time, record)
csv = (@cache[Thread.current] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
csv = (@cache[Thread.current] ||= CSV.new((+"").force_encoding(Encoding::ASCII_8BIT), **@generate_opts))
values = @accessors.map { |a| a.call(record) }
line = (csv << values).string.dup
# Need manual cleanup because CSV writer doesn't provide such method.
Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/plugin/formatter_json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/formatter_ltsv.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -31,7 +33,7 @@ class LabeledTSVFormatter < Formatter
config_param :add_newline, :bool, default: true

def format(tag, time, record)
formatted = ""
formatted = +""
record.each do |label, value|
formatted << @delimiter if formatted.length.nonzero?
formatted << "#{label}#{@label_delimiter}#{value.to_s.gsub(@delimiter, @replacement)}"
Expand Down
4 changes: 3 additions & 1 deletion lib/fluent/plugin/formatter_out_file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -43,7 +45,7 @@ def configure(conf)
end

def format(tag, time, record)
header = ''
header = +''
header << "#{@timef.format(time)}#{@delimiter}" if @output_time
header << "#{tag}#{@delimiter}" if @output_tag
"#{header}#{Yajl.dump(record)}#{@newline}"
Expand Down
10 changes: 6 additions & 4 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#
# Fluentd
#
Expand Down Expand Up @@ -56,7 +58,7 @@ class HttpInput < Input

helpers :parser, :compat_parameters, :event_loop, :server

EMPTY_GIF_IMAGE = "GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;".force_encoding("UTF-8")
EMPTY_GIF_IMAGE = (+"GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;").force_encoding("UTF-8")

desc 'The port to listen to.'
config_param :port, :integer, default: 9880
Expand Down Expand Up @@ -375,7 +377,7 @@ def on_read(data)
end

def on_message_begin
@body = ''
@body = +''
end

def on_headers_complete(headers)
Expand Down Expand Up @@ -602,7 +604,7 @@ def send_response(code, header, body)
header['Content-Length'] ||= body.bytesize
header['Content-Type'] ||= 'text/plain'.freeze

data = %[HTTP/1.1 #{code}\r\n]
data = +"HTTP/1.1 #{code}\r\n"
header.each_pair {|k,v|
data << "#{k}: #{v}\r\n"
}
Expand All @@ -613,7 +615,7 @@ def send_response(code, header, body)
end

def send_response_nobody(code, header)
data = %[HTTP/1.1 #{code}\r\n]
data = +"HTTP/1.1 #{code}\r\n"
header.each_pair {|k,v|
data << "#{k}: #{v}\r\n"
}
Expand Down
Loading

0 comments on commit eede534

Please sign in to comment.