Skip to content

Add frozen_string_literal: true in order to suppress 'warning: literal string will be frozen in the future' #4599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 6 additions & 4 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 All @@ -563,7 +565,7 @@ def event(level, args)
}

map.each_pair {|k,v|
if k == "error".freeze && v.is_a?(Exception) && !map.has_key?("error_class")
if k == "error" && v.is_a?(Exception) && !map.has_key?("error_class")
message << " error_class=#{v.class.to_s} error=#{v.to_s.inspect}"
else
message << " #{k}=#{v.inspect}"
Expand Down Expand Up @@ -598,7 +600,7 @@ def caller_line(type, time, depth, level)
worker_id_part = if type == :default && (@process_type == :worker0 || @process_type == :workers)
@worker_id_part
else
"".freeze
""
end
log_msg = "#{format_time(time)} [#{LEVEL_TEXT[level]}]: #{worker_id_part}"
if @debug_mode
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
10 changes: 6 additions & 4 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 @@ -27,7 +29,7 @@ class CsvFormatter < Formatter
helpers :record_accessor

config_param :delimiter, default: ',' do |val|
['\t', 'TAB'].include?(val) ? "\t".freeze : val.freeze
['\t', 'TAB'].include?(val) ? "\t" : val.freeze
end
config_param :force_quotes, :bool, default: true
# "array" looks good for type of :fields, but this implementation removes tailing comma
Expand All @@ -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
10 changes: 6 additions & 4 deletions 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 @@ -25,13 +27,13 @@ class LabeledTSVFormatter < Formatter

# http://ltsv.org/

config_param :delimiter, :string, default: "\t".freeze
config_param :label_delimiter, :string, default: ":".freeze
config_param :replacement, :string, default: " ".freeze
config_param :delimiter, :string, default: "\t"
config_param :label_delimiter, :string, default: ":"
config_param :replacement, :string, default: " "
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
10 changes: 6 additions & 4 deletions 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 @@ -29,9 +31,9 @@ class OutFileFormatter < Formatter
config_param :output_tag, :bool, default: true
config_param :delimiter, default: "\t" do |val|
case val
when /SPACE/i then ' '.freeze
when /COMMA/i then ','.freeze
else "\t".freeze
when /SPACE/i then ' '
when /COMMA/i then ','
else "\t"
end
end
config_set_default :time_type, :string
Expand All @@ -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
Loading