Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 6e546c9

Browse files
committed
Retire 1.8-induced RuboCop settings
1 parent ea6ada6 commit 6e546c9

11 files changed

+32
-46
lines changed

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ Metrics/AbcSize:
2626
# Over time we'd like to get this down, but this is what we're at now.
2727
Metrics/PerceivedComplexity:
2828
Max: 9
29+
30+
# TODO: turn on cops below sometimes later
31+
32+
Style/FrozenStringLiteralComment:
33+
Enabled: false
34+
35+
Performance/UnfreezeString:
36+
Enabled: false

.rubocop_rspec_base.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,12 @@ CyclomaticComplexity:
3939
Documentation:
4040
Enabled: false
4141

42-
# We still support 1.8.7 which requires trailing dots
43-
DotPosition:
44-
EnforcedStyle: trailing
45-
4642
DoubleNegation:
4743
Enabled: false
4844

49-
# each_with_object is unavailable on 1.8.7 so we have to disable this one.
50-
EachWithObject:
51-
Enabled: false
52-
5345
FormatString:
5446
EnforcedStyle: percent
5547

56-
# As long as we support ruby 1.8.7 we have to use hash rockets.
57-
HashSyntax:
58-
EnforcedStyle: hash_rockets
59-
60-
# We can't use the new lambda syntax, since we still support 1.8.7.
61-
Lambda:
62-
Enabled: false
63-
6448
# Over time we'd like to get this down, but this is what we're at now.
6549
LineLength:
6650
Max: 100
@@ -90,11 +74,6 @@ PercentLiteralDelimiters:
9074
PredicateName:
9175
Enabled: false
9276

93-
# On 1.8 `proc` is `lambda`, so we use `Proc.new` to ensure we get real procs on all supported versions.
94-
# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/
95-
Proc:
96-
Enabled: false
97-
9877
# Exceptions should be rescued with `Support::AllExceptionsExceptOnesWeMustNotRescue`
9978
RescueException:
10079
Enabled: true

lib/rspec/support.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def self.failure_notifier=(callable)
6767
end
6868

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

7272
# @api private
7373
def self.failure_notifier
@@ -94,7 +94,7 @@ class << self
9494
end
9595

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

9999
# @api private
100100
def self.warning_notifier

lib/rspec/support/differ.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def color?
6666

6767
def initialize(opts={})
6868
@color = opts.fetch(:color, false)
69-
@object_preparer = opts.fetch(:object_preparer, lambda { |string| string })
69+
@object_preparer = opts.fetch(:object_preparer, ->(string) { string })
7070
end
7171

7272
private
@@ -177,7 +177,7 @@ def object_to_string(object)
177177
when Array
178178
PP.pp(ObjectFormatter.prepare_for_inspection(object), "".dup)
179179
when String
180-
object =~ /\n/ ? object : object.inspect
180+
object.match?(/\n/) ? object : object.inspect
181181
else
182182
PP.pp(object, "".dup)
183183
end

lib/rspec/support/encoded_string.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def to_s
4848
end
4949
alias :to_str :to_s
5050

51+
def self.pick_encoding(source_a, source_b)
52+
Encoding.compatible?(source_a, source_b) || Encoding.default_external
53+
end
54+
5155
private
5256

5357
# Encoding Exceptions:
@@ -98,14 +102,14 @@ def matching_encoding(string)
98102
# 'invalid: :replace' also replaces an invalid byte sequence
99103
#
100104
# For example:
101-
# "\x80".force_encoding("Emacs-Mule").encode(:invalid => :replace).bytes.to_a # =>
105+
# "\x80".force_encoding("Emacs-Mule").encode(invalid: :replace).bytes.to_a
102106
# => 63 # '?'
103107
#
104-
string.encode(@encoding, :invalid => :replace, :undef => :replace, :replace => REPLACE)
108+
string.encode(@encoding, invalid: :replace, undef: :replace, replace: REPLACE)
105109
rescue Encoding::ConverterNotFoundError
106110
# Originally defined as a constant to avoid uneeded allocations, this hash must
107111
# be defined inline (without {}) to avoid warnings on Ruby 2.7
108-
string.dup.force_encoding(@encoding).encode(:invalid => :replace, :replace => REPLACE)
112+
string.dup.force_encoding(@encoding).encode(invalid: :replace, replace: REPLACE)
109113
end
110114

111115
def remove_invalid_bytes(string)
@@ -115,10 +119,6 @@ def remove_invalid_bytes(string)
115119
def detect_source_encoding(string)
116120
string.encoding
117121
end
118-
119-
def self.pick_encoding(source_a, source_b)
120-
Encoding.compatible?(source_a, source_b) || Encoding.default_external
121-
end
122122
end
123123
end
124124
end

lib/rspec/support/method_signature_verifier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Support
88
# keyword args of a given method.
99
#
1010
# @private
11-
class MethodSignature # rubocop:disable ClassLength
11+
class MethodSignature
1212
attr_reader :min_non_kw_args, :max_non_kw_args, :optional_kw_args, :required_kw_args
1313

1414
def initialize(method)
@@ -219,7 +219,7 @@ def initialize(signature, args=[])
219219
@arbitrary_kw_args = @unlimited_args = false
220220
end
221221

222-
def with_expectation(expectation) # rubocop:disable MethodLength, Metrics/PerceivedComplexity
222+
def with_expectation(expectation)
223223
return self unless MethodSignatureExpectation === expectation
224224

225225
if expectation.empty?

lib/rspec/support/object_formatter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ def prepare_array(array)
7373

7474
def prepare_hash(input_hash)
7575
with_entering_structure(input_hash) do
76-
sort_hash_keys(input_hash).inject({}) do |output_hash, key_and_value|
76+
sort_hash_keys(input_hash).each_with_object({}) do |key_and_value, output_hash|
7777
key, value = key_and_value.map { |element| prepare_element(element) }
7878
output_hash[key] = value
79-
output_hash
8079
end
8180
end
8281
end

lib/rspec/support/source/token.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class Source
77
# A wrapper for Ripper token which is generated with `Ripper.lex`.
88
class Token
99
CLOSING_TYPES_BY_OPENING_TYPE = {
10-
:on_lbracket => :on_rbracket,
11-
:on_lparen => :on_rparen,
12-
:on_lbrace => :on_rbrace,
13-
:on_heredoc_beg => :on_heredoc_end
10+
on_lbracket: :on_rbracket,
11+
on_lparen: :on_rparen,
12+
on_lbrace: :on_rbrace,
13+
on_heredoc_beg: :on_heredoc_end
1414
}.freeze
1515

1616
CLOSING_KEYWORDS_BY_OPENING_KEYWORD = {

lib/rspec/support/spec/library_wide_checks.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module WhitespaceChecks
99
def check_for_tab_characters(filename)
1010
failing_lines = []
1111
File.readlines(filename).each_with_index do |line, number|
12-
failing_lines << number + 1 if line =~ /\t/
12+
failing_lines << number + 1 if line.match?(/\t/)
1313
end
1414

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

2626
return if failing_lines.empty?

lib/rspec/support/spec/stderr_splitter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def to_io
3636
# To work around JRuby error:
3737
# TypeError: $stderr must have write method, RSpec::StdErrSplitter given
3838
def write(line)
39-
return if line =~ %r{^\S+/gems/\S+:\d+: warning:} # http://rubular.com/r/kqeUIZOfPG
39+
return if line.match?(%r{^\S+/gems/\S+:\d+: warning:}) # http://rubular.com/r/kqeUIZOfPG
4040

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

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

5050
@orig_stderr.write(line)
5151
@output_tracker.write(line)

lib/rspec/support/spec/with_isolated_directory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
end
1010

1111
RSpec.configure do |c|
12-
c.include_context "isolated directory", :isolated_directory => true
12+
c.include_context "isolated directory", isolated_directory: true
1313
end

0 commit comments

Comments
 (0)