diff --git a/.rubocop.yml b/.rubocop.yml index 159329b9e..cc0a16e19 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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. @@ -154,8 +261,6 @@ RSpec/ClassCheck: Enabled: true RSpec/ContainExactly: Enabled: true -RSpec/UndescriptiveLiteralsDescription: - Enabled: true RSpec/DuplicatedMetadata: Enabled: true RSpec/EmptyMetadata: @@ -198,5 +303,7 @@ RSpec/SpecFilePathSuffix: Enabled: true RSpec/SubjectDeclaration: Enabled: true +RSpec/UndescriptiveLiteralsDescription: + Enabled: true RSpec/VerifiedDoubleReference: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9cb073ce1..eef920c77 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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' diff --git a/lib/rubocop/cop/rspec/expect_actual.rb b/lib/rubocop/cop/rspec/expect_actual.rb index 68ed5e560..7a15aa25d 100644 --- a/lib/rubocop/cop/rspec/expect_actual.rb +++ b/lib/rubocop/cop/rspec/expect_actual.rb @@ -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 diff --git a/lib/rubocop/cop/rspec/leaky_constant_declaration.rb b/lib/rubocop/cop/rspec/leaky_constant_declaration.rb index dbab968fa..907b97dea 100644 --- a/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +++ b/lib/rubocop/cop/rspec/leaky_constant_declaration.rb @@ -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 diff --git a/lib/rubocop/cop/rspec/multiple_describes.rb b/lib/rubocop/cop/rspec/multiple_describes.rb index 4c231dedc..69199a592 100644 --- a/lib/rubocop/cop/rspec/multiple_describes.rb +++ b/lib/rubocop/cop/rspec/multiple_describes.rb @@ -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) diff --git a/lib/rubocop/cop/rspec/multiple_expectations.rb b/lib/rubocop/cop/rspec/multiple_expectations.rb index 794d2ef3d..2d51f218d 100644 --- a/lib/rubocop/cop/rspec/multiple_expectations.rb +++ b/lib/rubocop/cop/rspec/multiple_expectations.rb @@ -72,7 +72,7 @@ class MultipleExpectations < Base MSG = 'Example has too many expectations [%d/%d].' ANYTHING = ->(_node) { true } - TRUE = lambda(&:true_type?) + TRUE_NODE = lambda(&:true_type?) # @!method aggregate_failures?(node) def_node_matcher :aggregate_failures?, <<~PATTERN @@ -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) diff --git a/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb b/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb index 0e68102bf..e386c5c68 100644 --- a/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +++ b/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb @@ -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) diff --git a/lib/rubocop/cop/rspec/named_subject.rb b/lib/rubocop/cop/rspec/named_subject.rb index 5bd80924c..f69480051 100644 --- a/lib/rubocop/cop/rspec/named_subject.rb +++ b/lib/rubocop/cop/rspec/named_subject.rb @@ -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) diff --git a/lib/rubocop/cop/rspec/predicate_matcher.rb b/lib/rubocop/cop/rspec/predicate_matcher.rb index 29e34160c..560b00600 100644 --- a/lib/rubocop/cop/rspec/predicate_matcher.rb +++ b/lib/rubocop/cop/rspec/predicate_matcher.rb @@ -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 diff --git a/lib/rubocop/cop/rspec/sort_metadata.rb b/lib/rubocop/cop/rspec/sort_metadata.rb index c01407573..f34f0ade1 100644 --- a/lib/rubocop/cop/rspec/sort_metadata.rb +++ b/lib/rubocop/cop/rspec/sort_metadata.rb @@ -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 diff --git a/lib/rubocop/cop/rspec/stubbed_mock.rb b/lib/rubocop/cop/rspec/stubbed_mock.rb index e67e4b753..0b7d0a0a7 100644 --- a/lib/rubocop/cop/rspec/stubbed_mock.rb +++ b/lib/rubocop/cop/rspec/stubbed_mock.rb @@ -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 diff --git a/lib/rubocop/cop/rspec/subject_stub.rb b/lib/rubocop/cop/rspec/subject_stub.rb index a54267af4..273e4fea9 100644 --- a/lib/rubocop/cop/rspec/subject_stub.rb +++ b/lib/rubocop/cop/rspec/subject_stub.rb @@ -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) diff --git a/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb b/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb index 4d1a82d48..f130fdb4d 100644 --- a/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +++ b/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb @@ -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 diff --git a/spec/project/default_config_spec.rb b/spec/project/default_config_spec.rb index a53b8cc66..41b556826 100644 --- a/spec/project/default_config_spec.rb +++ b/spec/project/default_config_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c80a7d18..b39d1e6fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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