Skip to content

Commit

Permalink
Merge pull request #1879 from rubocop/enable-newer-cops
Browse files Browse the repository at this point in the history
Enable pending cops up to RuboCop v1.63
  • Loading branch information
bquorning authored May 19, 2024
2 parents 28bf477 + dcd50c6 commit 5d2ec84
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 40 deletions.
145 changes: 126 additions & 19 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,131 @@ RSpec/SpecFilePathFormat:
Exclude:
- spec/rubocop/cop/rspec/mixin/**/*.rb

# Enable some of RuboCop's pending cops.

Layout/LineContinuationSpacing:
Enabled: true
Layout/LineEndStringConcatenationIndentation:
Enabled: true
Lint/AmbiguousOperatorPrecedence:
Enabled: true
Lint/NonAtomicFileOperation:
Enabled: true
Style/EmptyHeredoc:
Enabled: true
Style/RedundantHeredocDelimiterQuotes:
Enabled: true
Style/RedundantStringEscape:
Enabled: true
Style/ReturnNilInPredicateMethodDefinition:
Style/NumberedParameters:
Enabled: true
EnforcedStyle: disallow

# Enable RuboCop's pending cops up to v1.63

Gemspec/DeprecatedAttributeAssignment: {Enabled: true}
Gemspec/DevelopmentDependencies: {Enabled: true}
Gemspec/RequireMFA: {Enabled: true}
Layout/LineContinuationLeadingSpace: {Enabled: true}
Layout/LineContinuationSpacing: {Enabled: true}
Layout/LineEndStringConcatenationIndentation: {Enabled: true}
Layout/SpaceBeforeBrackets: {Enabled: true}
Lint/AmbiguousAssignment: {Enabled: true}
Lint/AmbiguousOperatorPrecedence: {Enabled: true}
Lint/AmbiguousRange: {Enabled: true}
Lint/ConstantOverwrittenInRescue: {Enabled: true}
Lint/DeprecatedConstants: {Enabled: true}
Lint/DuplicateBranch: {Enabled: true}
Lint/DuplicateMagicComment: {Enabled: true}
Lint/DuplicateMatchPattern: {Enabled: true}
Lint/DuplicateRegexpCharacterClassElement: {Enabled: true}
Lint/EmptyBlock: {Enabled: true}
Lint/EmptyClass: {Enabled: true}
Lint/EmptyInPattern: {Enabled: true}
Lint/IncompatibleIoSelectWithFiberScheduler: {Enabled: true}
Lint/ItWithoutArgumentsInBlock: {Enabled: true}
Lint/LambdaWithoutLiteralBlock: {Enabled: true}
Lint/LiteralAssignmentInCondition: {Enabled: true}
Lint/MixedCaseRange: {Enabled: true}
Lint/NonAtomicFileOperation: {Enabled: true}
Lint/NoReturnInBeginEndBlocks: {Enabled: true}
Lint/NumberedParameterAssignment: {Enabled: true}
Lint/OrAssignmentToConstant: {Enabled: true}
Lint/RedundantDirGlobSort: {Enabled: true}
Lint/RedundantRegexpQuantifiers: {Enabled: true}
Lint/RefinementImportMethods: {Enabled: true}
Lint/RequireRangeParentheses: {Enabled: true}
Lint/RequireRelativeSelfPath: {Enabled: true}
Lint/SymbolConversion: {Enabled: true}
Lint/ToEnumArguments: {Enabled: true}
Lint/TripleQuotes: {Enabled: true}
Lint/UnexpectedBlockArity: {Enabled: true}
Lint/UnmodifiedReduceAccumulator: {Enabled: true}
Lint/UselessRescue: {Enabled: true}
Lint/UselessRuby2Keywords: {Enabled: true}
Metrics/CollectionLiteralLength: {Enabled: true}
Naming/BlockForwarding: {Enabled: true}
Performance/AncestorsInclude: {Enabled: true}
Performance/BigDecimalWithNumericArgument: {Enabled: true}
Performance/BlockGivenWithExplicitBlock: {Enabled: true}
Performance/CollectionLiteralInLoop: {Enabled: true}
Performance/ConcurrentMonotonicTime: {Enabled: true}
Performance/ConstantRegexp: {Enabled: true}
Performance/MapCompact: {Enabled: true}
Performance/MapMethodChain: {Enabled: true}
Performance/MethodObjectAsBlock: {Enabled: true}
Performance/RedundantEqualityComparisonBlock: {Enabled: true}
Performance/RedundantSortBlock: {Enabled: true}
Performance/RedundantSplitRegexpArgument: {Enabled: true}
Performance/RedundantStringChars: {Enabled: true}
Performance/ReverseFirst: {Enabled: true}
Performance/SortReverse: {Enabled: true}
Performance/Squeeze: {Enabled: true}
Performance/StringIdentifierArgument: {Enabled: true}
Performance/StringInclude: {Enabled: true}
Performance/Sum: {Enabled: true}
Security/CompoundHash: {Enabled: true}
Security/IoMethods: {Enabled: true}
Style/ArgumentsForwarding: {Enabled: true}
Style/ArrayIntersect: {Enabled: true}
Style/CollectionCompact: {Enabled: true}
Style/ComparableClamp: {Enabled: true}
Style/ConcatArrayLiterals: {Enabled: true}
Style/DataInheritance: {Enabled: true}
Style/DirEmpty: {Enabled: true}
Style/DocumentDynamicEvalDefinition: {Enabled: true}
Style/EmptyHeredoc: {Enabled: true}
Style/EndlessMethod: {Enabled: true}
Style/EnvHome: {Enabled: true}
Style/ExactRegexpMatch: {Enabled: true}
Style/FetchEnvVar: {Enabled: true}
Style/FileEmpty: {Enabled: true}
Style/FileRead: {Enabled: true}
Style/FileWrite: {Enabled: true}
Style/HashConversion: {Enabled: true}
Style/HashExcept: {Enabled: true}
Style/IfWithBooleanLiteralBranches: {Enabled: true}
Style/InPatternThen: {Enabled: true}
Style/MagicCommentFormat: {Enabled: true}
Style/MapCompactWithConditionalBlock: {Enabled: true}
Style/MapIntoArray: {Enabled: true}
Style/MapToHash: {Enabled: true}
Style/MapToSet: {Enabled: true}
Style/MinMaxComparison: {Enabled: true}
Style/MultilineInPatternThen: {Enabled: true}
Style/NegatedIfElseCondition: {Enabled: true}
Style/NestedFileDirname: {Enabled: true}
Style/NilLambda: {Enabled: true}
Style/NumberedParametersLimit: {Enabled: true}
Style/ObjectThen: {Enabled: true}
Style/OpenStructUse: {Enabled: true}
Style/OperatorMethodCall: {Enabled: true}
Style/QuotedSymbols: {Enabled: true}
Style/RedundantArgument: {Enabled: true}
Style/RedundantArrayConstructor: {Enabled: true}
Style/RedundantConstantBase: {Enabled: true}
Style/RedundantCurrentDirectoryInPath: {Enabled: true}
Style/RedundantDoubleSplatHashBraces: {Enabled: true}
Style/RedundantEach: {Enabled: true}
Style/RedundantFilterChain: {Enabled: true}
Style/RedundantHeredocDelimiterQuotes: {Enabled: true}
Style/RedundantInitialize: {Enabled: true}
Style/RedundantLineContinuation: {Enabled: true}
Style/RedundantRegexpArgument: {Enabled: true}
Style/RedundantRegexpConstructor: {Enabled: true}
Style/RedundantSelfAssignmentBranch: {Enabled: true}
Style/RedundantStringEscape: {Enabled: true}
Style/ReturnNilInPredicateMethodDefinition: {Enabled: true}
Style/SelectByRegexp: {Enabled: true}
Style/SingleLineDoEndBlock: {Enabled: true}
Style/StringChars: {Enabled: true}
Style/SuperWithArgsParentheses: {Enabled: true}
Style/SwapValues: {Enabled: true}
Style/YAMLFileRead: {Enabled: true}

# Enable our own pending cops.

Expand All @@ -154,8 +261,6 @@ RSpec/ClassCheck:
Enabled: true
RSpec/ContainExactly:
Enabled: true
RSpec/UndescriptiveLiteralsDescription:
Enabled: true
RSpec/DuplicatedMetadata:
Enabled: true
RSpec/EmptyMetadata:
Expand Down Expand Up @@ -198,5 +303,7 @@ RSpec/SpecFilePathSuffix:
Enabled: true
RSpec/SubjectDeclaration:
Enabled: true
RSpec/UndescriptiveLiteralsDescription:
Enabled: true
RSpec/VerifiedDoubleReference:
Enabled: true
6 changes: 5 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-offense-counts --no-auto-gen-timestamp`
# using RuboCop version 1.36.0.
# using RuboCop version 1.63.4.
# 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.

Lint/ToEnumArguments:
Exclude:
- 'lib/rubocop/cop/rspec/multiple_expectations.rb'

Rake/MethodDefinitionInTask:
Exclude:
- 'tasks/cut_release.rake'
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/expect_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def simple_literal?(node)

def complex_literal?(node)
COMPLEX_LITERALS.include?(node.type) &&
node.each_child_node.all?(&method(:literal?))
node.each_child_node.all? { |child_node| literal?(child_node) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/leaky_constant_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def on_module(node)
private

def inside_describe_block?(node)
node.each_ancestor(:block).any?(&method(:spec_group?))
node.each_ancestor(:block).any? { |ancestor| spec_group?(ancestor) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/multiple_describes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MultipleDescribes < Base

def on_top_level_group(node)
top_level_example_groups =
top_level_groups.select(&method(:example_group?))
top_level_groups.select { |group| example_group?(group) }

return if top_level_example_groups.one?
return unless top_level_example_groups.first.equal?(node)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/multiple_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MultipleExpectations < Base
MSG = 'Example has too many expectations [%<total>d/%<max>d].'

ANYTHING = ->(_node) { true }
TRUE = lambda(&:true_type?)
TRUE_NODE = lambda(&:true_type?)

# @!method aggregate_failures?(node)
def_node_matcher :aggregate_failures?, <<~PATTERN
Expand Down Expand Up @@ -110,7 +110,7 @@ def example_with_aggregate_failures?(example_node)
node_with_aggregate_failures = find_aggregate_failures(example_node)
return false unless node_with_aggregate_failures

aggregate_failures?(node_with_aggregate_failures, TRUE)
aggregate_failures?(node_with_aggregate_failures, TRUE_NODE)
end

def find_aggregate_failures(example_node)
Expand Down
6 changes: 2 additions & 4 deletions lib/rubocop/cop/rspec/multiple_memoized_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ def on_new_investigation
attr_reader :example_group_memoized_helpers

def all_helpers(node)
[
*helpers(node),
*node.each_ancestor(:block).flat_map(&method(:helpers))
]
helpers(node) +
node.each_ancestor(:block).flat_map { |ancestor| helpers(ancestor) }
end

def helpers(node)
Expand Down
7 changes: 5 additions & 2 deletions lib/rubocop/cop/rspec/named_subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
private

def ignored_shared_example?(node)
cop_config['IgnoreSharedExamples'] &&
node.each_ancestor(:block).any?(&method(:shared_example?))
return false unless cop_config['IgnoreSharedExamples']

node.each_ancestor(:block).any? do |ancestor|
shared_example?(ancestor)
end
end

def check_explicit_subject(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/predicate_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def uncorrectable_matcher?(node, matcher)

def heredoc_argument?(matcher)
matcher.arguments.select do |arg|
%i[str dstr xstr].include?(arg.type)
arg.str_type? || arg.dstr_type? || arg.xstr_type?
end.any?(&:heredoc?)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/sort_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sort_pairs(pairs)

def sort_symbols(symbols)
symbols.sort_by do |symbol|
if %i[str sym].include?(symbol.type)
if symbol.str_type? || symbol.sym_type?
symbol.value.to_s.downcase
else
symbol.source.downcase
Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/rspec/stubbed_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class StubbedMock < Base
RESTRICT_ON_SEND = %i[to].freeze

def on_send(node)
expectation(node, &method(:on_expectation))
expectation(node) do |expectation, method_name, matcher|
on_expectation(expectation, method_name, matcher)
end
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/subject_stub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class SubjectStub < Base
PATTERN

def on_top_level_group(node)
@explicit_subjects = find_all_explicit(node, &method(:subject?))
@subject_overrides = find_all_explicit(node, &method(:let?))
@explicit_subjects = find_all_explicit(node) { |n| subject?(n) }
@subject_overrides = find_all_explicit(node) { |n| let?(n) }

find_subject_expectations(node) do |stub|
add_offense(stub)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def deep_dup(object)
when Array
object.map { |item| deep_dup(item) }
when Hash
object.transform_values(&method(:deep_dup))
object.transform_values { |value| deep_dup(value) }
else
object # only collections undergo modifications and need duping
end
Expand Down
4 changes: 2 additions & 2 deletions spec/project/default_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def cop_configuration(config_key)
end
end

it 'is expected that all cops documented with `@safety` are `Safe: false`' \
' or `SafeAutoCorrect: false`' do
it 'is expected that all cops documented with `@safety` are `Safe: false` ' \
'or `SafeAutoCorrect: false`' do
unsafe_cop_names.each do |cop_name|
unsafe = default_config[cop_name]['Safe'] == false ||
default_config[cop_name]['SafeAutoCorrect'] == false
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module SpecHelper
Dir
.glob(File.expand_path(spec_helper_glob, __dir__))
.sort
.each(&method(:require))
.each { |path| require path }

RSpec.configure do |config|
# Set metadata so smoke tests are run on all cop specs
Expand Down

0 comments on commit 5d2ec84

Please sign in to comment.