Skip to content

Commit

Permalink
Suppress a lot of warnings
Browse files Browse the repository at this point in the history
* Do not shadow local variables

test/plugin/test_in_dummy.rb:91: warning: assigned but unused variable - time
lib/fluent/plugin/in_dummy.rb:45: warning: shadowing outer local variable - e
test/test_event.rb:94: warning: shadowing outer local variable - time
test/test_event.rb:142: warning: shadowing outer local variable - time
test/plugin/test_in_stream.rb:20: warning: shadowing outer local variable - time
test/plugin/test_in_stream.rb:35: warning: shadowing outer local variable - time
test/plugin/test_in_stream.rb:51: warning: shadowing outer local variable - time
test/plugin/test_in_stream.rb:68: warning: shadowing outer local variable - time
test/plugin/test_in_stream.rb:84: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:43: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:59: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:75: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:113: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:150: warning: shadowing outer local variable - tag
test/plugin/test_in_http.rb:163: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:184: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:200: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:238: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:262: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:280: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:43: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:59: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:75: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:113: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:150: warning: shadowing outer local variable - tag
test/plugin/test_in_http.rb:163: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:184: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:200: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:238: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:262: warning: shadowing outer local variable - time
test/plugin/test_in_http.rb:280: warning: shadowing outer local variable - time

* Initialize uninitialized instance variables

lib/fluent/test/base.rb:31: warning: instance variable @now not initialized
lib/fluent/test/input_test.rb:121: warning: instance variable @run_post_conditions not initialized
lib/fluent/log.rb:324: warning: instance variable @suppress_repeated_stacktrace not initialized
lib/fluent/config/configure_proxy.rb:183: warning: instance variable @current_description not initialized
lib/fluent/plugin/buf_file.rb:147: warning: instance variable @symlink_path not initialized
lib/fluent/output.rb:212: warning: instance variable @secondary not initialized
lib/fluent/output.rb:220: warning: instance variable @secondary not initialized
lib/fluent/mixin.rb:201: warning: instance variable @localtime not initialized
lib/fluent/mixin.rb:201: warning: instance variable @Timezone not initialized
lib/fluent/mixin.rb:149: warning: instance variable @remove_tag_prefix not initialized
lib/fluent/mixin.rb:150: warning: instance variable @remove_tag_suffix not initialized
test/config/test_system_config.rb:81: warning: instance variable @emit_error_log_interval not initialized
lib/fluent/plugin/in_syslog.rb:111: warning: instance variable @use_default not initialized
lib/fluent/root_agent.rb:89: warning: instance variable @without_source not initialized
lib/fluent/process.rb:488: warning: instance variable @detach_process not initialized

* Define assert_equal_event_time once

lib/fluent/test/base.rb:35: warning: method redefined; discarding old assert_equal_event_time
lib/fluent/test/base.rb:35: warning: previous definition of assert_equal_event_time was here

* Add '_' prefix to unused variables

test/test_parser.rb:1046: warning: assigned but unused variable - time
lib/fluent/test/output_test.rb:91: warning: assigned but unused variable - record
lib/fluent/config/element.rb:138: warning: assigned but unused variable - block

* Remove unused variables

test/test_parser.rb:453: warning: assigned but unused variable - format
test/test_mixin.rb:211: warning: assigned but unused variable - d
test/test_formatter.rb:55: warning: assigned but unused variable - formatter
test/test_buffer.rb:581: warning: assigned but unused variable - e
test/config/test_dsl.rb:164: warning: assigned but unused variable - root
lib/fluent/parser.rb:619: warning: assigned but unused variable - e
lib/fluent/plugin/in_exec.rb:56: warning: assigned but unused variable - localtime
lib/fluent/plugin/in_exec.rb:58: warning: assigned but unused variable - utc
lib/fluent/event_router.rb:105: warning: assigned but unused variable - c

* Rename block parameter

lib/fluent/config/v1_parser.rb:159: warning: shadowing outer local variable - path
lib/fluent/config/parser.rb:84: warning: shadowing outer local variable - path
lib/fluent/plugin/buf_file.rb:175: warning: assigned but unused variable - chunk
lib/fluent/plugin/buf_file.rb:177: warning: assigned but unused variable - timestamp
lib/fluent/plugin/buf_file.rb:181: warning: assigned but unused variable - chunk
lib/fluent/plugin/buf_file.rb:183: warning: assigned but unused variable - timestamp

* Use defined global variable

lib/fluent/plugin.rb:129: warning: global variable `$log' not initialized

* Remove redundant condition

lib/fluent/log.rb:255: warning: instance variable @suppress_repeated_stacktrace not initialized
lib/fluent/log.rb:261: warning: instance variable @suppress_repeated_stacktrace not initialized

* Define instance method once

lib/fluent/plugin/in_tail.rb:457: warning: method redefined; discarding old swap_state
lib/fluent/plugin/in_tail.rb:457: warning: previous definition of swap_state was here
  • Loading branch information
okkez committed Mar 24, 2016
1 parent c13e36c commit 76c3ac2
Show file tree
Hide file tree
Showing 31 changed files with 121 additions and 102 deletions.
1 change: 1 addition & 0 deletions lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def initialize(name, opts = {})
@defaults = {}
@descriptions = {}
@sections = {}
@current_description = nil
end

def required?
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/config/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def secret_param?(key)

param_key = key.to_sym
@corresponding_proxies.each { |proxy|
block, opts = proxy.params[param_key]
_block, opts = proxy.params[param_key]
if opts && opts.has_key?(:secret)
return opts[:secret]
end
Expand Down
8 changes: 4 additions & 4 deletions lib/fluent/config/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def process_include(attrs, elems, uri, allow_include = true)
pattern = path
end

Dir.glob(pattern).sort.each { |path|
basepath = File.dirname(path)
fname = File.basename(path)
File.open(path) { |f|
Dir.glob(pattern).sort.each { |entry|
basepath = File.dirname(entry)
fname = File.basename(entry)
File.open(entry) { |f|
Parser.new(basepath, f.each_line, fname).parse!(allow_include, nil, attrs, elems)
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/fluent/config/v1_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def eval_include(attrs, elems, uri)
pattern = path
end

Dir.glob(pattern).sort.each { |path|
basepath = File.dirname(path)
fname = File.basename(path)
data = File.read(path)
Dir.glob(pattern).sort.each { |entry|
basepath = File.dirname(entry)
fname = File.basename(entry)
data = File.read(entry)
data.force_encoding('UTF-8')
ss = StringScanner.new(data)
V1Parser.new(ss, basepath, fname, @eval_context).parse_element(true, nil, attrs, elems)
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/event_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def match?(tag)

def match(tag)
collector = @match_cache.get(tag) {
c = find(tag) || @default_collector
find(tag) || @default_collector
}
collector
end
Expand Down
8 changes: 4 additions & 4 deletions lib/fluent/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def initialize(out=STDERR, level=LEVEL_TRACE, opts={})
# Fluent::Engine requires Fluent::Log, so we must take that object lazily
@engine = Fluent.const_get('Engine')

if opts.has_key?(:suppress_repeated_stacktrace)
@suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace]
end
@suppress_repeated_stacktrace = opts[:suppress_repeated_stacktrace]
end

attr_accessor :out
Expand Down Expand Up @@ -320,7 +318,9 @@ def initialize(logger)
@logger = logger
@level = @logger.level
@depth_offset = 2
@suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace)
if logger.instance_variable_defined?(:@suppress_repeated_stacktrace)
@suppress_repeated_stacktrace = logger.instance_variable_get(:@suppress_repeated_stacktrace)
end

enable_color @logger.enable_color?
end
Expand Down
20 changes: 14 additions & 6 deletions lib/fluent/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,18 @@ module HandleTagNameMixin
attr_accessor :remove_tag_prefix, :remove_tag_suffix, :add_tag_prefix, :add_tag_suffix
def configure(conf)
super
if remove_tag_prefix = conf['remove_tag_prefix']
@remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
end

if remove_tag_suffix = conf['remove_tag_suffix']
@remove_tag_suffix = Regexp.new(Regexp.escape(remove_tag_suffix) + '$')
end
@remove_tag_prefix = if conf.has_key?('remove_tag_prefix')
Regexp.new('^' + Regexp.escape(conf['remove_tag_prefix']))
else
nil
end

@remove_tag_suffix = if conf.has_key?('remove_tag_suffix')
Regexp.new(Regexp.escape(conf['remove_tag_suffix']) + '$')
else
nil
end

@add_tag_prefix = conf['add_tag_prefix']
@add_tag_suffix = conf['add_tag_suffix']
Expand All @@ -162,6 +167,8 @@ module SetTimeKeyMixin

def configure(conf)
@include_time_key = false
@localtime = false
@timezone = nil

super

Expand Down Expand Up @@ -257,6 +264,7 @@ def self.included(klass)
def configure(conf)
super

@type_converters = nil
@type_converters = parse_types_parameter unless @types.nil?
end

Expand Down
1 change: 1 addition & 0 deletions lib/fluent/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def initialize
@next_retry_time = 0
@num_errors = 0
@num_errors_lock = Mutex.new
@secondary = nil
@secondary_limit = 8
@emit_count = 0
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def self.lookup(format)
# built-in template
begin
Fluent::Plugin.new_parser(format)
rescue ConfigError => e # keep same error message
rescue ConfigError # keep same error message
raise ConfigError, "Unknown format template '#{format}'"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def self.register_impl(kind, registry, type, value)
raise Fluent::ConfigError, "Invalid implementation as #{kind} plugin: '#{type}'. It must be a Class, or callable."
end
registry.register(type, value)
$log.trace "registered #{kind} plugin '#{type}'" if $log
$log.trace "registered #{kind} plugin '#{type}'" if defined?($log)
nil
end

Expand Down
9 changes: 5 additions & 4 deletions lib/fluent/plugin/buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def initialize
super

@uri_parser = URI::Parser.new
@symlink_path = nil
end

desc 'The path where buffer chunks are stored.'
Expand Down Expand Up @@ -171,15 +172,15 @@ def resume
}

map = {}
maps.sort_by {|(timestamp,chunk)|
maps.sort_by {|(timestamp,_chunk)|
timestamp
}.each {|(timestamp,chunk)|
}.each {|(_timestamp,chunk)|
map[chunk.key] = chunk
}

queue = queues.sort_by {|(timestamp,chunk)|
queue = queues.sort_by {|(timestamp,_chunk)|
timestamp
}.map {|(timestamp,chunk)|
}.map {|(_timestamp,chunk)|
chunk
}

Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_dummy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class DummyInput < Input
config_param :dummy, default: [{"message"=>"dummy"}] do |val|
begin
parsed = JSON.parse(val)
rescue JSON::ParserError => e
rescue JSON::ParserError => ex
# Fluent::ConfigParseError, "got incomplete JSON" will be raised
# at literal_parser.rb with --use-v1-config, but I had to
# take care at here for the case of --use-v0-config.
raise Fluent::ConfigError, "#{e.class}: #{e.message}"
raise Fluent::ConfigError, "#{ex.class}: #{ex.message}"
end
dummy = parsed.is_a?(Array) ? parsed : [parsed]
dummy.each_with_index do |e, i|
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def initialize
def configure(conf)
super

if localtime = conf['localtime']
if conf['localtime']
@localtime = true
elsif utc = conf['utc']
elsif conf['utc']
@localtime = false
end

Expand Down
2 changes: 2 additions & 0 deletions lib/fluent/plugin/in_syslog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def initialize
def configure(conf)
super

@use_default = false

if conf.has_key?('format')
@parser = Plugin.new_parser(conf['format'])
@parser.configure(conf)
Expand Down
16 changes: 8 additions & 8 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,16 @@ def on_rotate(io)
@update_watcher.call(@path, swap_state(@pe))
end
end
end

def swap_state(pe)
# Use MemoryPositionEntry for rotated file temporary
mpe = MemoryPositionEntry.new
mpe.update(pe.read_inode, pe.read_pos)
@pe = mpe
@io_handler.pe = mpe # Don't re-create IOHandler because IOHandler has an internal buffer.
def swap_state(pe)
# Use MemoryPositionEntry for rotated file temporary
mpe = MemoryPositionEntry.new
mpe.update(pe.read_inode, pe.read_pos)
@pe = mpe
@io_handler.pe = mpe # Don't re-create IOHandler because IOHandler has an internal buffer.

pe # This pe will be updated in on_rotate after TailWatcher is initialized
end
pe # This pe will be updated in on_rotate after TailWatcher is initialized
end

class TimerWatcher < Coolio::TimerWatcher
Expand Down
4 changes: 4 additions & 0 deletions lib/fluent/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ module DetachProcessMixin
def configure(conf)
super

@detach_process = nil

if detach_process = conf['detach_process']
b3v = Config.bool_value(detach_process)
case b3v
Expand Down Expand Up @@ -461,6 +463,8 @@ def initialize
def configure(conf)
super

@detach_process = nil

if detach_process = conf['detach_process']
b3v = Config.bool_value(detach_process)
case b3v
Expand Down
1 change: 1 addition & 0 deletions lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def initialize(system_config = SystemConfig.new)
@started_inputs = []
@suppress_emit_error_log_interval = 0
@next_emit_error_log_time = nil
@without_source = false

suppress_interval(system_config.emit_error_log_interval) unless system_config.emit_error_log_interval.nil?
@without_source = system_config.without_source unless system_config.without_source.nil?
Expand Down
16 changes: 8 additions & 8 deletions lib/fluent/test/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ def self.setup
@now = n
}
engine.define_singleton_method(:now) {
@now || super()
}

::Test::Unit::Assertions.module_eval {
def assert_equal_event_time(a, b)
assert_equal(a.sec, b.sec)
assert_equal(a.nsec, b.nsec)
end
@now ||= super()
}

nil
Expand Down Expand Up @@ -131,3 +124,10 @@ def logs
end
end
end

Test::Unit::Assertions.module_eval do
def assert_equal_event_time(a, b)
assert_equal(a.sec, b.sec)
assert_equal(a.nsec, b.nsec)
end
end
2 changes: 1 addition & 1 deletion lib/fluent/test/input_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def initialize(klass, &block)
# for checking only the number of emitted records during run
@expected_emits_length = nil
@run_timeout = 5
@run_post_conditions = []
end

def expect_emit(tag, time, record)
Expand Down Expand Up @@ -81,7 +82,6 @@ def records

def register_run_post_condition(&block)
if block
@run_post_conditions ||= []
@run_post_conditions << block
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/test/output_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def run(num_waits = 10, &block)
key = ''
if @instance.respond_to?(:time_slicer)
# this block is only for test_out_file
time, record = @entries.first
time, _record = @entries.first
key = @instance.time_slicer.call(time)
end
chunk = @instance.buffer.new_chunk(key)
Expand Down
2 changes: 1 addition & 1 deletion test/config/test_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def setup
sub_test_case 'with configuration that returns non element on top' do
sub_test_case '.parse' do
test 'does not crash' do
root = Fluent::Config::DSL::Parser.parse(DSL_CONFIG_RETURNS_NON_ELEMENT, 'dsl_config_returns_non_element.rb')
Fluent::Config::DSL::Parser.parse(DSL_CONFIG_RETURNS_NON_ELEMENT, 'dsl_config_returns_non_element.rb')
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/config/test_system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def initialize
@suppress_config_dump = nil
@suppress_repeated_stacktrace = nil
@without_source = nil
@emit_error_log_interval = nil
end
end

Expand Down
Loading

0 comments on commit 76c3ac2

Please sign in to comment.