Skip to content
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

Refactor/remove cop patching #708

Merged
merged 3 commits into from
Apr 11, 2020
Merged
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
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ Style/FrozenStringLiteralComment:
Layout/LineLength:
Max: 140

# We only permit it in this one area which is internal code testing. Never exposed to users
Security/Eval:
Exclude:
- spec/support/helpers/reporting.rb

inherit_from: .rubocop_todo.yml
46 changes: 37 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-01-03 13:39:27 +0100 using RuboCop version 0.78.0.
# on 2020-04-11 12:33:09 +0200 using RuboCop version 0.79.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Exclude:
- 'lib/aruba/api/core.rb'

# Offense count: 2
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'lib/aruba/api/core.rb'

# Offense count: 7
Lint/AmbiguousBlockAssociation:
Exclude:
Expand All @@ -23,39 +36,43 @@ Lint/Void:
- 'lib/aruba/platforms/announcer.rb'
- 'lib/aruba/platforms/unix_environment_variables.rb'

# Offense count: 29
# Offense count: 27
Metrics/AbcSize:
Max: 116

# Offense count: 74
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 587
Max: 593

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 152
Max: 153

# Offense count: 20
# Offense count: 5
Metrics/CyclomaticComplexity:
Max: 12

# Offense count: 27
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 22
Max: 47

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 175
Max: 171

# Offense count: 3
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 8

# Offense count: 4
# Offense count: 5
Metrics/PerceivedComplexity:
Max: 10
Max: 13

# Offense count: 1
Naming/ConstantName:
Expand Down Expand Up @@ -89,6 +106,17 @@ Naming/MethodParameterName:
- 'lib/aruba/platforms/unix_platform.rb'
- 'lib/aruba/tasks/docker_helpers.rb'

# Offense count: 1
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# ForbiddenPrefixes: is_, has_, have_
# AllowedMethods: is_a?
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicateName:
Exclude:
- 'spec/**/*'
- 'lib/aruba/matchers/base/base_matcher.rb'

# Offense count: 1
Performance/Caller:
Exclude:
Expand Down
3 changes: 0 additions & 3 deletions lib/aruba/api/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def close_input

private

# rubocop:disable Metrics/MethodLength
def prepare_command(cmd, opts)
exit_timeout = opts[:exit_timeout].nil? ? aruba.config.exit_timeout : opts[:exit_timeout]
io_wait_timeout = opts[:io_wait_timeout].nil? ? aruba.config.io_wait_timeout : opts[:io_wait_timeout]
Expand Down Expand Up @@ -256,8 +255,6 @@ def prepare_command(cmd, opts)
)
end

# rubocop:enable Metrics/MethodLength

def start_command(command)
aruba.config.before(:command, self, command)

Expand Down
16 changes: 4 additions & 12 deletions lib/aruba/api/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def in_current_directory(&block)
# @example Run code in directory
# result = cd('some-dir') { Dir.getwd }
#
# rubocop:disable Metrics/MethodLength
def cd(dir, &block)
if block_given?
begin
Expand Down Expand Up @@ -96,8 +95,6 @@ def cd(dir, &block)

self
end
# rubocop:enable Metrics/MethodLength

# Expand file name
#
# @param [String] file_name
Expand Down Expand Up @@ -134,19 +131,16 @@ def cd(dir, &block)
# # => /foo/bar
# expand_path('/foo/bar')
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def expand_path(file_name, dir_string = nil)
message = "Filename #{file_name} needs to be a string. It cannot be nil or empty either. "\
"Please use `expand_path('.')` if you want the current directory to be expanded."

fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?

# rubocop:disable Layout/LineLength
fail %(Aruba's working directory does not exist. Maybe you forgot to run `setup_aruba` before using its API.) unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory)
unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory)
fail %(Aruba's working directory does not exist. Maybe you forgot to run `setup_aruba` before using its API.)
end

# rubocop:enable Layout/LineLength

prefix = file_name[0]
rest = file_name[2..-1]
Expand Down Expand Up @@ -187,9 +181,7 @@ def expand_path(file_name, dir_string = nil)
end
end
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity


# Run block with environment
#
Expand Down
4 changes: 2 additions & 2 deletions lib/aruba/api/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def touch(*args)
# @param [String] destination
# A file or directory name. If multiple sources are given the destination
# needs to be a directory
def copy(*args) # rubocop:disable Metrics/CyclomaticComplexity
def copy(*args)
args = args.flatten
destination = args.pop
source = args
Expand Down Expand Up @@ -210,7 +210,7 @@ def copy(*args) # rubocop:disable Metrics/CyclomaticComplexity
# @param [String] destination
# A file or directory name. If multiple sources are given the destination
# needs to be a directory
def move(*args) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
def move(*args)
args = args.flatten
destination = args.pop
source = args
Expand Down
2 changes: 0 additions & 2 deletions lib/aruba/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Aruba
class Console
# Start the aruba console
#
# rubocop:disable Metrics/MethodLength
def start
# Start IRB with current context:
# http://stackoverflow.com/questions/4189818/how-to-run-irb-start-in-context-of-current-class
Expand Down Expand Up @@ -63,6 +62,5 @@ def inspect
IRB.irb_at_exit
end
end
# rubocop:enable Metrics/MethodLength
end
end
8 changes: 3 additions & 5 deletions lib/aruba/event_bus/name_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def camel_case(underscored_name)

# Thanks ActiveSupport
# (Only needed to support Ruby 1.9.3 and JRuby)
# rubocop:disable Metrics/CyclomaticComplexity
def constantize(camel_cased_word)
names = camel_cased_word.split('::')

Expand Down Expand Up @@ -49,7 +48,6 @@ def constantize(camel_cased_word)
end
end
end
# rubocop:enable Metrics/CyclomaticComplexity
end

# @private
Expand Down Expand Up @@ -148,9 +146,9 @@ def initialize(default_namespace)
def transform(event_id)
resolvers.find { |r| r.match? event_id }.new.transform(default_namespace, event_id)
rescue => e
# rubocop:disable Layout/LineLength
raise EventNameResolveError, %(Transforming "#{event_id}" into an event class failed. Supported types are: #{@resolvers.map(&:supports).flatten.join(', ')}. #{e.message}.\n\n#{e.backtrace.join("\n")})
# rubocop:enable Layout/LineLength
types = @resolvers.map(&:supports).flatten.join(', ')
message = %(Transforming "#{event_id}" into an event class failed. Supported types are: #{types}. #{e.message}.)
raise EventNameResolveError, message, cause: e
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/aruba/matchers/base/base_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ def failure_message_when_negated
end

# @private
# rubocop:disable Naming/PredicateName
def self.has_default_failure_messages?(matcher)
matcher.method(:failure_message).owner == self &&
matcher.method(:failure_message_when_negated).owner == self
rescue NameError
false
end
# rubocop:enable Naming/PredicateName
end

include DefaultFailureMessages
Expand Down
3 changes: 0 additions & 3 deletions lib/aruba/matchers/base/object_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def self.format(object)
prepare_for_inspection(object).inspect
end

# rubocop:disable Metrics/CyclomaticComplexity

# @private
# Prepares the provided object to be formatted by wrapping it as needed
# in something that, when `inspect` is called on it, will produce the
Expand Down Expand Up @@ -46,7 +44,6 @@ def self.prepare_for_inspection(object)

InspectableItem.new(inspection)
end
# rubocop:enable Metrics/CyclomaticComplexity

# @private
def self.prepare_hash(input)
Expand Down
8 changes: 2 additions & 6 deletions lib/aruba/processes/spawn_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ def initialize(cmd, exit_timeout, io_wait_timeout, working_directory,
# @yield [SpawnProcess]
# Run code for process which was started
#
# rubocop:disable Metrics/MethodLength
def start
# rubocop:disable Layout/LineLength
if started?
error_message = %(Command "#{commandline}" has already been started. Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.\n#{caller.join("\n")})
error_message = "Command \"#{commandline}\" has already been started." \
' Please `#stop` the command first and `#start` it again. Alternatively use `#restart`.'
fail CommandAlreadyStartedError, error_message
end

# rubocop:enable Layout/LineLength

@started = true

@process = ChildProcess.build(*command_string.to_a)
Expand Down Expand Up @@ -113,7 +110,6 @@ def start

yield self if block_given?
end
# rubocop:enable Metrics/MethodLength

# Access to stdin of process
def stdin
Expand Down
2 changes: 0 additions & 2 deletions lib/aruba/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def working_directory(clobber = true)
Aruba.platform.chdir runtime.config.root_directory
end

# rubocop:disable Metrics/MethodLength
def events
runtime.event_bus.register(
:command_started,
Expand Down Expand Up @@ -87,6 +86,5 @@ def events
proc { |event| runtime.announcer.announce :configuration, event.entity[:changed][:name], event.entity[:changed][:value] }
)
end
# rubocop:enable Metrics/MethodLength
end
end
10 changes: 7 additions & 3 deletions spec/aruba/api/filesystem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,13 @@

before(:each) { create_test_files(source) }

# rubocop:disable Layout/LineLength
it { expect { @aruba.copy source, destination }.to raise_error ArgumentError, %(same file: #{File.expand_path(File.join(@aruba.aruba.current_directory, source))} and #{File.expand_path(File.join(@aruba.aruba.current_directory, destination))}) }
# rubocop:enable Layout/LineLength
it 'raises an appropriate error' do
src_path = File.expand_path(File.join(@aruba.aruba.current_directory, source))
dest_path = File.expand_path(File.join(@aruba.aruba.current_directory, destination))
expected_message = %(same file: #{src_path} and #{dest_path})
expect { @aruba.copy source, destination }
.to raise_error ArgumentError, expected_message
end
end

context 'when a fixture is destination' do
Expand Down
2 changes: 0 additions & 2 deletions spec/support/helpers/reporting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def capture(stream)
stream = stream.to_s
captured_stream = Tempfile.new(stream)

# rubocop:disable Security/Eval
stream_io = eval("$#{stream}")
# rubocop:enable Security/Eval

origin_stream = stream_io.dup
stream_io.reopen(captured_stream)
Expand Down