Skip to content

Commit

Permalink
Retire 1.8-induced RuboCop settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Nov 12, 2020
1 parent ea6ada6 commit 6e546c9
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 46 deletions.
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ Metrics/AbcSize:
# Over time we'd like to get this down, but this is what we're at now.
Metrics/PerceivedComplexity:
Max: 9

# TODO: turn on cops below sometimes later

Style/FrozenStringLiteralComment:
Enabled: false

Performance/UnfreezeString:
Enabled: false
21 changes: 0 additions & 21 deletions .rubocop_rspec_base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,12 @@ CyclomaticComplexity:
Documentation:
Enabled: false

# We still support 1.8.7 which requires trailing dots
DotPosition:
EnforcedStyle: trailing

DoubleNegation:
Enabled: false

# each_with_object is unavailable on 1.8.7 so we have to disable this one.
EachWithObject:
Enabled: false

FormatString:
EnforcedStyle: percent

# As long as we support ruby 1.8.7 we have to use hash rockets.
HashSyntax:
EnforcedStyle: hash_rockets

# We can't use the new lambda syntax, since we still support 1.8.7.
Lambda:
Enabled: false

# Over time we'd like to get this down, but this is what we're at now.
LineLength:
Max: 100
Expand Down Expand Up @@ -90,11 +74,6 @@ PercentLiteralDelimiters:
PredicateName:
Enabled: false

# On 1.8 `proc` is `lambda`, so we use `Proc.new` to ensure we get real procs on all supported versions.
# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/
Proc:
Enabled: false

# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
RescueException:
Enabled: true
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def self.failure_notifier=(callable)
end

# @private
DEFAULT_FAILURE_NOTIFIER = lambda { |failure, _opts| raise failure }
DEFAULT_FAILURE_NOTIFIER = ->(failure, _opts) { raise failure }

# @api private
def self.failure_notifier
Expand All @@ -94,7 +94,7 @@ class << self
end

# @private
DEFAULT_WARNING_NOTIFIER = lambda { |warning| ::Kernel.warn warning }
DEFAULT_WARNING_NOTIFIER = ->(warning) { ::Kernel.warn warning }

# @api private
def self.warning_notifier
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/support/differ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def color?

def initialize(opts={})
@color = opts.fetch(:color, false)
@object_preparer = opts.fetch(:object_preparer, lambda { |string| string })
@object_preparer = opts.fetch(:object_preparer, ->(string) { string })
end

private
Expand Down Expand Up @@ -177,7 +177,7 @@ def object_to_string(object)
when Array
PP.pp(ObjectFormatter.prepare_for_inspection(object), "".dup)
when String
object =~ /\n/ ? object : object.inspect
object.match?(/\n/) ? object : object.inspect
else
PP.pp(object, "".dup)
end
Expand Down
14 changes: 7 additions & 7 deletions lib/rspec/support/encoded_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def to_s
end
alias :to_str :to_s

def self.pick_encoding(source_a, source_b)
Encoding.compatible?(source_a, source_b) || Encoding.default_external
end

private

# Encoding Exceptions:
Expand Down Expand Up @@ -98,14 +102,14 @@ def matching_encoding(string)
# 'invalid: :replace' also replaces an invalid byte sequence
#
# For example:
# "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a # =>
# "\x80".force_encoding("Emacs-Mule").encode(invalid: :replace).bytes.to_a
# => 63 # '?'
#
string.encode(@encoding, :invalid => :replace, :undef => :replace, :replace => REPLACE)
string.encode(@encoding, invalid: :replace, undef: :replace, replace: REPLACE)
rescue Encoding::ConverterNotFoundError
# Originally defined as a constant to avoid uneeded allocations, this hash must
# be defined inline (without {}) to avoid warnings on Ruby 2.7
string.dup.force_encoding(@encoding).encode(:invalid => :replace, :replace => REPLACE)
string.dup.force_encoding(@encoding).encode(invalid: :replace, replace: REPLACE)
end

def remove_invalid_bytes(string)
Expand All @@ -115,10 +119,6 @@ def remove_invalid_bytes(string)
def detect_source_encoding(string)
string.encoding
end

def self.pick_encoding(source_a, source_b)
Encoding.compatible?(source_a, source_b) || Encoding.default_external
end
end
end
end
4 changes: 2 additions & 2 deletions lib/rspec/support/method_signature_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Support
# keyword args of a given method.
#
# @private
class MethodSignature # rubocop:disable ClassLength
class MethodSignature
attr_reader :min_non_kw_args, :max_non_kw_args, :optional_kw_args, :required_kw_args

def initialize(method)
Expand Down Expand Up @@ -219,7 +219,7 @@ def initialize(signature, args=[])
@arbitrary_kw_args = @unlimited_args = false
end

def with_expectation(expectation) # rubocop:disable MethodLength, Metrics/PerceivedComplexity
def with_expectation(expectation)
return self unless MethodSignatureExpectation === expectation

if expectation.empty?
Expand Down
3 changes: 1 addition & 2 deletions lib/rspec/support/object_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ def prepare_array(array)

def prepare_hash(input_hash)
with_entering_structure(input_hash) do
sort_hash_keys(input_hash).inject({}) do |output_hash, key_and_value|
sort_hash_keys(input_hash).each_with_object({}) do |key_and_value, output_hash|
key, value = key_and_value.map { |element| prepare_element(element) }
output_hash[key] = value
output_hash
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rspec/support/source/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Source
# A wrapper for Ripper token which is generated with `Ripper.lex`.
class Token
CLOSING_TYPES_BY_OPENING_TYPE = {
:on_lbracket => :on_rbracket,
:on_lparen => :on_rparen,
:on_lbrace => :on_rbrace,
:on_heredoc_beg => :on_heredoc_end
on_lbracket: :on_rbracket,
on_lparen: :on_rparen,
on_lbrace: :on_rbrace,
on_heredoc_beg: :on_heredoc_end
}.freeze

CLOSING_KEYWORDS_BY_OPENING_KEYWORD = {
Expand Down
6 changes: 3 additions & 3 deletions lib/rspec/support/spec/library_wide_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module WhitespaceChecks
def check_for_tab_characters(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line, number|
failing_lines << number + 1 if line =~ /\t/
failing_lines << number + 1 if line.match?(/\t/)
end

return if failing_lines.empty?
Expand All @@ -19,8 +19,8 @@ def check_for_tab_characters(filename)
def check_for_extra_spaces(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line, number|
next if line =~ /^\s+#.*\s+\n$/
failing_lines << number + 1 if line =~ /\s+\n$/
next if line.match?(/^\s+#.*\s+\n$/)
failing_lines << number + 1 if line.match?(/\s+\n$/)
end

return if failing_lines.empty?
Expand Down
4 changes: 2 additions & 2 deletions lib/rspec/support/spec/stderr_splitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def to_io
# To work around JRuby error:
# TypeError: $stderr must have write method, RSpec::StdErrSplitter given
def write(line)
return if line =~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG
return if line.match?(%r{^\S+/gems/\S+:\d+: warning:}) # http://rubular.com/r/kqeUIZOfPG

# Ruby 2.7.0 warnings from keyword argments span multiple lines, extend check above
# to look for the next line.
Expand All @@ -45,7 +45,7 @@ def write(line)

# Ruby 2.7.0 complains about hashes used in place of keyword arguments
# Aruba 0.14.2 uses this internally triggering that here
return if line =~ %r{lib/ruby/2\.7\.0/fileutils\.rb:622: warning:}
return if line.match?(%r{lib/ruby/2\.7\.0/fileutils\.rb:622: warning:})

@orig_stderr.write(line)
@output_tracker.write(line)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/support/spec/with_isolated_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
end

RSpec.configure do |c|
c.include_context "isolated directory", :isolated_directory => true
c.include_context "isolated directory", isolated_directory: true
end

0 comments on commit 6e546c9

Please sign in to comment.