Skip to content

Commit

Permalink
Rubocop: Enable SpaceBefore cops (elastic#15197)
Browse files Browse the repository at this point in the history
Enables the following cops:

 * Layout/SpaceBeforeBlockBraces
 * Layout/SpaceBeforeBrackets
 * Layout/SpaceBeforeComma
 * Layout/SpaceBeforeComment
 * Layout/SpaceBeforeFirstArg
 * Layout/SpaceBeforeSemicolon
  • Loading branch information
roaksoax authored Jul 19, 2023
1 parent 4255a8f commit 2165d43
Show file tree
Hide file tree
Showing 57 changed files with 147 additions and 147 deletions.
24 changes: 12 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ Layout/SpaceAroundMethodCallOperator:
Enabled: true
Layout/SpaceAroundOperators:
Enabled: true
Layout/SpaceBeforeBlockBraces:
Enabled: true
Layout/SpaceBeforeBrackets:
Enabled: true
Layout/SpaceBeforeComma:
Enabled: true
Layout/SpaceBeforeComment:
Enabled: true
Layout/SpaceBeforeFirstArg:
Enabled: true
Layout/SpaceBeforeSemicolon:
Enabled: true

##### Need review #####
Layout/AccessModifierIndentation:
Expand Down Expand Up @@ -199,18 +211,6 @@ Layout/SpaceAfterMethodName:
Enabled: false
Layout/SpaceAfterNot:
Enabled: false
Layout/SpaceBeforeBlockBraces:
Enabled: false
Layout/SpaceBeforeBrackets:
Enabled: false
Layout/SpaceBeforeComma:
Enabled: false
Layout/SpaceBeforeComment:
Enabled: false
Layout/SpaceBeforeFirstArg:
Enabled: false
Layout/SpaceBeforeSemicolon:
Enabled: false
Layout/SpaceInLambdaLiteral:
Enabled: false
Layout/SpaceInsideArrayLiteralBrackets:
Expand Down
12 changes: 6 additions & 6 deletions lib/pluginmanager/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def initialize
end

def to_s
[sources_to_s, gemspec_to_s, gems_to_s].select{|s| !s.empty?}.join("\n") + "\n"
[sources_to_s, gemspec_to_s, gems_to_s].select {|s| !s.empty?}.join("\n") + "\n"
end

# @return [Gem] found gem or nil if not found
Expand Down Expand Up @@ -180,21 +180,21 @@ def no_constrains?(requirements)

def sources_to_s
return "" if @sources.empty?
@sources.map{|source| "source #{source.inspect}"}.join("\n")
@sources.map {|source| "source #{source.inspect}"}.join("\n")
end

def gems_to_s
return "" if @gems.empty?
@gems.map do |gem|
requirements = gem.requirements.empty? ? nil : gem.requirements.map{|r| r.inspect}.join(", ")
options = gem.options.empty? ? nil : gem.options.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
requirements = gem.requirements.empty? ? nil : gem.requirements.map {|r| r.inspect}.join(", ")
options = gem.options.empty? ? nil : gem.options.map {|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
"gem " + [gem.name.inspect, requirements, options].compact.join(", ")
end.join("\n")
end

def gemspec_to_s
return "" if @gemspec.empty?
options = @gemspec.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
options = @gemspec.map {|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
"gemspec #{options}"
end
end
Expand Down Expand Up @@ -237,7 +237,7 @@ class Gem

def initialize(name, requirements = [], options = {})
@name = name
@requirements = requirements.map{|r| r.to_s.strip}.select{|r| !r.empty?}
@requirements = requirements.map {|r| r.to_s.strip}.select {|r| !r.empty?}
@options = options
end

Expand Down
8 changes: 4 additions & 4 deletions lib/pluginmanager/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def execute

installed_plugin_names = filtered_specs.collect {|spec| spec.name}

filtered_specs.sort_by{|spec| spec.name}.each do |spec|
filtered_specs.sort_by {|spec| spec.name}.each do |spec|
line = "#{spec.name}"
line += " (#{spec.version})" if verbose?
puts(line)
Expand All @@ -63,9 +63,9 @@ def filtered_specs
specs = LogStash::PluginManager.find_plugins_gem_specs

# apply filters
specs = specs.select{|spec| gemfile.find(spec.name)} if installed?
specs = specs.select{|spec| spec_matches_search?(spec) } if plugin
specs = specs.select{|spec| spec.metadata['logstash_group'] == group} if group
specs = specs.select {|spec| gemfile.find(spec.name)} if installed?
specs = specs.select {|spec| spec_matches_search?(spec) } if plugin
specs = specs.select {|spec| spec.metadata['logstash_group'] == group} if group

specs
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pluginmanager/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def update_gems!
# create list of plugins to update
def plugins_to_update(previous_gem_specs_map)
if update_all?
previous_gem_specs_map.values.map{|spec| spec.name}
previous_gem_specs_map.values.map {|spec| spec.name}
else
# If the plugins isn't available in the gemspec or in
# the gemfile defined with a local path, we assume the plugins is not
Expand Down Expand Up @@ -153,7 +153,7 @@ def display_updated_plugins(previous_gem_specs_map)
def find_latest_gem_specs
LogStash::PluginManager.all_installed_plugins_gem_specs(gemfile).inject({}) do |result, spec|
previous = result[spec.name.downcase]
result[spec.name.downcase] = previous ? [previous, spec].max_by{|s| s.version} : spec
result[spec.name.downcase] = previous ? [previous, spec].max_by {|s| s.version} : spec
result
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pluginmanager/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def self.plugin_file?(plugin)
# @return [Array<Gem::Specification>] all local logstash plugin gem specs
def self.find_plugins_gem_specs(name = nil)
specs = name ? ::Gem::Specification.find_all_by_name(name) : ::Gem::Specification.find_all
specs.select{|spec| logstash_plugin_gem_spec?(spec)}
specs.select {|spec| logstash_plugin_gem_spec?(spec)}
end

# list of all locally installed plugins specs specified in the Gemfile.
Expand All @@ -135,7 +135,7 @@ def self.find_plugins_gem_specs(name = nil)
def self.all_installed_plugins_gem_specs(gemfile)
# we start form the installed gemspecs so we can verify the metadata for valid logstash plugin
# then filter out those not included in the Gemfile
find_plugins_gem_specs.select{|spec| !!gemfile.find(spec.name)}
find_plugins_gem_specs.select {|spec| !!gemfile.find(spec.name)}
end

# @param plugin [String] plugin name
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/api/commands/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def pipeline(pipeline_id, options = {})
:config_reload_interval,
:dead_letter_queue_enabled,
:dead_letter_queue_path,
).reject{|_, v| v.nil?}
).reject {|_, v| v.nil?}
if options.fetch(:graph, false)
extended_stats = extract_metrics([:stats, :pipelines, pipeline_id.to_sym, :config], :graph)
decorated_vertices = extended_stats[:graph]["graph"]["vertices"].map { |vertex| decorate_with_cluster_uuids(vertex) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def plugins
end

def find_plugins_gem_specs
@specs ||= ::Gem::Specification.find_all.select{|spec| logstash_plugin_gem_spec?(spec)}
@specs ||= ::Gem::Specification.find_all.select {|spec| logstash_plugin_gem_spec?(spec)}
end

def logstash_plugin_gem_spec?(spec)
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/lib/logstash/compiler/treetop_monkeypatches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def _inspect(indent = "")

indent +
self.class.to_s.sub(/.*:/, '') +
em.map{|m| "+" + m.to_s.sub(/.*:/, '')} * "" +
em.map {|m| "+" + m.to_s.sub(/.*:/, '')} * "" +
" offset=#{interval.first}" +
", #{tv.inspect}" +
im +
(elements && elements.size > 0 ?
":" +
(elements.select { |e| !e.is_a?(LogStash::Config::AST::Whitespace) && e.elements && e.elements.size > 0 } || []).map{|e|
(elements.select { |e| !e.is_a?(LogStash::Config::AST::Whitespace) && e.elements && e.elements.size > 0 } || []).map {|e|
begin
"\n" + e.inspect(indent + " ")
rescue # Defend against inspect not taking a parameter
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/lib/logstash/config/config_ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,13 @@ def _inspect(indent = "")

indent +
self.class.to_s.sub(/.*:/, '') +
em.map{|m| "+" + m.to_s.sub(/.*:/, '')} * "" +
em.map {|m| "+" + m.to_s.sub(/.*:/, '')} * "" +
" offset=#{interval.first}" +
", #{tv.inspect}" +
im +
(elements && elements.size > 0 ?
":" +
(elements.select { |e| !e.is_a?(LogStash::Config::AST::Whitespace) && e.elements && e.elements.size > 0 } || []).map{|e|
(elements.select { |e| !e.is_a?(LogStash::Config::AST::Whitespace) && e.elements && e.elements.size > 0 } || []).map {|e|
begin
"\n" + e.inspect(indent + " ")
rescue # Defend against inspect not taking a parameter
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/filters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def multi_filter(events)
events.each do |event|
unless event.cancelled?
result << event
do_filter(event){|new_event| result << new_event}
do_filter(event) {|new_event| result << new_event}
end
end
result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CGroupResources

def cgroup_available?
# don't cache to ivar, in case the files are mounted after logstash starts??
CRITICAL_PATHS.all?{|path| ::File.exist?(path)}
CRITICAL_PATHS.all? {|path| ::File.exist?(path)}
end

def controller_groups
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/lib/logstash/java_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def start_workers
.map(&:value)
workers_init_elapsed = Time.now - workers_init_start

fail("Some worker(s) were not correctly initialized") if worker_loops.any?{|v| v.nil?}
fail("Some worker(s) were not correctly initialized") if worker_loops.any? {|v| v.nil?}

@logger.info("Pipeline Java execution initialization time", "seconds" => workers_init_elapsed.round(2))

Expand Down Expand Up @@ -475,7 +475,7 @@ def shutdown_workers
@shutdownRequested.set(true)

@worker_threads.each do |t|
@logger.debug("Shutdown waiting for worker thread" , default_logging_keys(:thread => t.inspect))
@logger.debug("Shutdown waiting for worker thread", default_logging_keys(:thread => t.inspect))
t.join
end

Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/modules/settings_merger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def merge(cli_settings, yml_settings)
# union will also coalesce identical hashes
# this "|" operator is provided to Java List by RubyJavaIntegration
union_of_settings = (cli_settings | yml_settings)
grouped_by_name = union_of_settings.group_by{|e| e["name"]}
grouped_by_name = union_of_settings.group_by {|e| e["name"]}
grouped_by_name.each do |_, array|
if array.size == 2
merged << array.last.merge(array.first)
Expand Down
4 changes: 2 additions & 2 deletions logstash-core/lib/logstash/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class LogStash::Runner < Clamp::StrictCommand
:default => LogStash::SETTINGS.get_default('pipeline.ecs_compatibility')

# Data Path Setting
option ["--path.data"] , "PATH",
option ["--path.data"], "PATH",
I18n.t("logstash.runner.flag.datapath"),
:attribute_name => "path.data",
:default => LogStash::SETTINGS.get_default("path.data")

# Plugins Settings
option ["-p", "--path.plugins"] , "PATH",
option ["-p", "--path.plugins"], "PATH",
I18n.t("logstash.runner.flag.pluginpath"),
:multivalued => true, :attribute_name => "path.plugins",
:default => LogStash::SETTINGS.get_default("path.plugins")
Expand Down
8 changes: 4 additions & 4 deletions logstash-core/lib/logstash/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def self.hash_merge_many(*hashes)
def self.normalize(o)
case o
when Java::JavaUtil::LinkedHashMap
o.inject({}){|r, (k, v)| r[k] = normalize(v); r}
o.inject({}) {|r, (k, v)| r[k] = normalize(v); r}
when Java::JavaUtil::ArrayList
o.map{|i| normalize(i)}
o.map {|i| normalize(i)}
else
o
end
Expand All @@ -180,9 +180,9 @@ def self.normalize(o)
def self.stringify_symbols(o)
case o
when Hash
o.inject({}){|r, (k, v)| r[k.is_a?(Symbol) ? k.to_s : k] = stringify_symbols(v); r}
o.inject({}) {|r, (k, v)| r[k.is_a?(Symbol) ? k.to_s : k] = stringify_symbols(v); r}
when Array
o.map{|i| stringify_symbols(i)}
o.map {|i| stringify_symbols(i)}
when Symbol
o.to_s
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def publisher(items, writer)
sleep 0.1
expect { queue.close }.not_to raise_error
sleep 0.1
files = Dir.glob(path + '/*').map{|f| f.sub("#{path}/", '')}
files = Dir.glob(path + '/*').map {|f| f.sub("#{path}/", '')}
if files.count != 2
output_strings << "File count after close mismatch expected: 2 got: #{files.count}"
output_strings.concat files
Expand All @@ -123,7 +123,7 @@ def publisher(items, writer)
queue.close

if output_strings.any?
output_strings << __memoized.reject{|k, v| reject_memo_keys.include?(k)}.inspect
output_strings << __memoized.reject {|k, v| reject_memo_keys.include?(k)}.inspect
end

expect(output_strings).to eq([])
Expand Down
8 changes: 4 additions & 4 deletions logstash-core/spec/logstash/agent/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def mhash(*path_elements)
end

it "increment the pipeline successes" do
expect{ subject.converge_state_and_update }.to change { mval(:stats, :pipelines, pipeline_name, :reloads, :successes) }.by(1)
expect { subject.converge_state_and_update }.to change { mval(:stats, :pipelines, pipeline_name, :reloads, :successes) }.by(1)
end

it "record the `last_success_timestamp`" do
Expand All @@ -213,7 +213,7 @@ def mhash(*path_elements)
end

it "increment the pipeline failures" do
expect{ subject.converge_state_and_update }.to change { mval(:stats, :pipelines, pipeline_name, :reloads, :failures) }.by(1)
expect { subject.converge_state_and_update }.to change { mval(:stats, :pipelines, pipeline_name, :reloads, :failures) }.by(1)
end
end
end
Expand Down Expand Up @@ -252,8 +252,8 @@ def mhash(*path_elements)
# since the pipeline is async, it can actually take some time to have metrics recordings
# so we try a few times
try(20) do
expect { mhash(:stats, :pipelines, :main, :events) }.not_to raise_error , "Events pipeline stats should exist"
expect { mhash(:stats, :pipelines, :main, :flow) }.not_to raise_error , "Events pipeline stats should exist"
expect { mhash(:stats, :pipelines, :main, :events) }.not_to raise_error, "Events pipeline stats should exist"
expect { mhash(:stats, :pipelines, :main, :flow) }.not_to raise_error, "Events pipeline stats should exist"
expect { mhash(:stats, :pipelines, :main, :plugins) }.not_to raise_error, "Plugins pipeline stats should exist"
end

Expand Down
2 changes: 1 addition & 1 deletion logstash-core/spec/logstash/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
after(:each) { $LOAD_PATH.delete(path) }

it "should add the path to $LOAD_PATH" do
expect{subject.add_plugin_path(path)}.to change{$LOAD_PATH.size}.by(1)
expect {subject.add_plugin_path(path)}.to change {$LOAD_PATH.size}.by(1)
expect($LOAD_PATH).to include(path)
end
end
Expand Down
8 changes: 4 additions & 4 deletions logstash-core/spec/logstash/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@
end

it "should consistently handle nil" do
expect{LogStash::Event.from_json(nil)}.to raise_error(TypeError)
expect{LogStash::Event.new(LogStash::Json.load(nil))}.to raise_error # java.lang.ClassCastException
expect {LogStash::Event.from_json(nil)}.to raise_error(TypeError)
expect {LogStash::Event.new(LogStash::Json.load(nil))}.to raise_error # java.lang.ClassCastException
end

it "should consistently handle bare string" do
bare_strings.each do |s|
expect{LogStash::Event.from_json(s)}.to raise_error LogStash::Json::ParserError
expect{LogStash::Event.new(LogStash::Json.load(s))}.to raise_error LogStash::Json::ParserError
expect {LogStash::Event.from_json(s)}.to raise_error LogStash::Json::ParserError
expect {LogStash::Event.new(LogStash::Json.load(s))}.to raise_error LogStash::Json::ParserError
end
end

Expand Down
4 changes: 2 additions & 2 deletions logstash-core/spec/logstash/filter_delegator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def register; end
config_name "super_plugin"
config :host, :validate => :string
def register; end
def flush(options = {}); @events ; end
def flush(options = {}); @events; end

def filter(event)
@events ||= []
Expand Down Expand Up @@ -102,7 +102,7 @@ def filter(event)
config_name "super_plugin"
config :host, :validate => :string
def register; end
def flush(options = {}); @events ; end
def flush(options = {}); @events; end

# naive split filter implementation
def filter(event)
Expand Down
8 changes: 4 additions & 4 deletions logstash-core/spec/logstash/filters/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def filter(event)
subject {LogStash::Filters::Base.new({})}

it "should provide method interfaces to override" do
expect{subject.register}.to raise_error(RuntimeError)
expect{subject.filter(:foo)}.to raise_error(RuntimeError)
expect {subject.register}.to raise_error(RuntimeError)
expect {subject.filter(:foo)}.to raise_error(RuntimeError)
end

it "should provide class public API" do
Expand All @@ -47,8 +47,8 @@ def filter(event)
end

context "multi_filter" do
let(:event1){LogStash::Event.new}
let(:event2){LogStash::Event.new}
let(:event1) {LogStash::Event.new}
let(:event2) {LogStash::Event.new}

it "should multi_filter without new events" do
allow(subject).to receive(:filter) do |event, &block|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

describe "#increment" do
it "increment the counter" do
expect{ subject.increment }.to change { subject.value }.by(1)
expect { subject.increment }.to change { subject.value }.by(1)
end
end

Expand Down
Loading

0 comments on commit 2165d43

Please sign in to comment.