# This is the configuration used to check the rubocop source code.

inherit_from: .rubocop_todo.yml

plugins:
  - rubocop-internal_affairs
  - rubocop-performance
  - rubocop-rake
  - rubocop-rspec

AllCops:
  NewCops: enable
  # Opt into the project-wide rubydex index when the gem is available
  # (Ruby 3.2+ on supported MRI platforms). Older Rubies, JRuby, and
  # environments without the gem fall back to file-local analysis with
  # a one-time warning, so this stays a no-op there.
  UseProjectIndex: true
  Exclude:
    - 'vendor/**/*'
    - 'spec/fixtures/**/*'
    - 'tmp/**/*'
    - '.git/**/*'
    - 'bin/*'
  TargetRubyVersion: 2.7
  SuggestExtensions: false

Naming/PredicateMethod:
  AllowedPatterns:
    - !ruby/regexp /\Aon_/ # ignore Node#on_* methods

Naming/PredicatePrefix:
  # Method define macros for dynamically generated method.
  MethodDefinitionMacros:
    - define_method
    - define_singleton_method
    - def_node_matcher
    - def_node_search

Style/FormatStringToken:
  # Because we parse a lot of source codes from strings. Percent arrays
  # look like unannotated format string tokens to this cop.
  Exclude:
    - spec/**/*

Style/InverseMethods:
  InverseMethods:
    # RuboCop AST defines common inverse methods. They are listed below:
    :single_line?: :multiline?

Style/IpAddresses:
  # The test for this cop includes strings that would cause offenses
  Exclude:
    - spec/rubocop/cop/style/ip_addresses_spec.rb

Style/OneClassPerFile:
  Exclude:
    - lib/rubocop/rspec/cop_helper.rb
    - tasks/spec_runner.rake

Style/ReturnNilInPredicateMethodDefinition:
  AllowedMethods:
    - on_defined? # rubocop-ast node handler

Layout/EndOfLine:
  EnforcedStyle: lf

Layout/ClassStructure:
  Enabled: true

Layout/RedundantLineBreak:
  Enabled: true

Layout/TrailingWhitespace:
  AllowInHeredoc: false

# The deprecated module itself is under test there; whether the reference
# resolves depends on rubydex availability, so an inline disable would be
# flagged as redundant in environments without the index.
Lint/DeprecatedReference:
  Exclude:
    - 'spec/rubocop/cop/mixin/enforce_superclass_spec.rb'

Lint/AmbiguousBlockAssociation:
  Exclude:
    - 'spec/**/*.rb'

Layout/HashAlignment:
  EnforcedHashRocketStyle:
    - key
    - table
  EnforcedColonStyle:
    - key
    - table

Layout/LineLength:
  Max: 100
  AllowedPatterns:
    - !ruby/regexp /\A +(it|describe|context|shared_examples|include_examples|it_behaves_like) ["']/
    - !ruby/regexp /\A +register_cop :/

Lint/InterpolationCheck:
  Exclude:
    - 'spec/**/*.rb'

Lint/UselessAccessModifier:
  MethodCreatingMethods:
    - 'def_matcher'
    - 'def_node_matcher'

Lint/EmptyFile:
  Exclude:
    # This file is intentionally empty to catch rubocop cops failing on empty files.
    - spec/rubocop/intentionally_empty_file.rb

Metrics/BlockLength:
  Exclude:
    - 'Rakefile'
    - '**/*.rake'
    - 'spec/**/*.rb'

Metrics/ClassLength:
  Exclude:
    - lib/rubocop/config_obsoletion.rb
    - lib/rubocop/lsp/routes.rb
    - lib/rubocop/options.rb

Metrics/ModuleLength:
  Exclude:
    - 'spec/**/*.rb'
    # Department modules are generated lists of `register_cop` directives.
    - lib/rubocop/cop/layout.rb
    - lib/rubocop/cop/lint.rb
    - lib/rubocop/cop/style.rb

Naming/InclusiveLanguage:
  Enabled: true
  CheckStrings: true
  FlaggedTerms:
    ' a offense':
      Suggestions:
        - an offense
    ' and offense':
      Suggestions:
        - ' an offense'
    accept:
      Regex: !ruby/regexp /\Aaccept /
      Suggestions:
        - 'accepts '
    auto-correct:
      Suggestions:
        - autocorrect
    auto_correct:
      Suggestions:
        - autocorrect
    behaviour:
      Suggestions:
        - behavior
    offence:
      Suggestions:
        - offense
    'does not registers':
      Suggestions:
        - does not register
    'register no offense':
      Suggestions:
        - registers no offense
    'register an offense':
      Regex: !ruby/regexp /\Aregister an offense/
      Suggestions:
        - registers an offense
    'register an error':
      Suggestions:
        - register an offense
    'registers an error':
      Suggestions:
        - registers an offense
    'registers offense':
      Regex: !ruby/regexp /registers offense(?!\(|s)/
      Suggestions:
        - registers an offense
    'does not register and corrects':
      Suggestions:
        does not register
    'does not register an offense and corrects':
      Suggestions:
        does not register an offense
  Exclude:
    - lib/rubocop/cop/naming/inclusive_language.rb
    - lib/rubocop/cop/mixin/auto_corrector.rb
    - spec/rubocop/cop/naming/inclusive_language_spec.rb

RSpec:
  Language:
    Expectations:
      - expect_autocorrect_options_for_autocorrect
      - expect_autocorrect_options_for_autocorrect_all
      - expect_autocorrect_options_for_fix_layout
      - expect_correction
      - expect_feature_loader
      - expect_no_offenses
      - expect_offense

RSpec/Dialect:
  Enabled: true
  PreferredMethods:
    shared_examples_for: shared_examples

RSpec/ExampleWithoutDescription:
  EnforcedStyle: single_line_only

RSpec/PredicateMatcher:
  # Also consider `be(true)` and `be(false)` as offenses, instead of only `be_truthy` and `be_falsy`
  Strict: false

RSpec/SpecFilePathFormat:
  CustomTransform:
    GitHubActionsFormatter: github_actions_formatter
    JUnitFormatter: junit_formatter
    OnSendWithoutOnCSend: on_send_without_on_csend
    RedundantLetRuboCopConfigNew: redundant_let_rubocop_config_new
  Exclude:
    - spec/rubocop/cop/mixin/enforce_superclass_spec.rb
    - spec/rubocop/cop/mixin/project_index_help_spec.rb

RSpec/MessageSpies:
  EnforcedStyle: receive

RSpec/NestedGroups:
  Max: 7

RSpec/MultipleMemoizedHelpers:
  Enabled: false

Performance/CollectionLiteralInLoop:
  Exclude:
    - 'Rakefile'
    - 'spec/**/*.rb'

Performance/EndWith:
  SafeMultiline: false

Performance/StartWith:
  SafeMultiline: false

RSpec/StubbedMock:
  Enabled: false

InternalAffairs/UndefinedConfig:
  Exclude:
    - 'lib/rubocop/cop/correctors/**/*.rb'
    - 'lib/rubocop/cop/mixin/**/*.rb'

InternalAffairs/StyleDetectedApiUse:
  Exclude:
    - 'lib/rubocop/cop/mixin/percent_array.rb'

InternalAffairs/ItblockHandler:
  Exclude:
    - 'lib/rubocop/cop/internal_affairs/*.rb'

InternalAffairs/NumblockHandler:
  Exclude:
    - 'lib/rubocop/cop/internal_affairs/*.rb'

InternalAffairs/OnSendWithoutOnCSend:
  Exclude:
    - 'lib/rubocop/cop/bundler/**/*.rb'
    - 'lib/rubocop/cop/gemspec/**/*.rb'
    - 'lib/rubocop/cop/mixin/**/*.rb'

    # `send` method is an operator call
    - 'lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb'
    - 'lib/rubocop/cop/internal_affairs/method_name_equal.rb'
    - 'lib/rubocop/cop/internal_affairs/node_type_predicate.rb'
    - 'lib/rubocop/cop/internal_affairs/single_line_comparison.rb'
    - 'lib/rubocop/cop/layout/space_after_not.rb'
    - 'lib/rubocop/cop/layout/space_around_operators.rb'
    - 'lib/rubocop/cop/layout/space_before_brackets.rb'
    - 'lib/rubocop/cop/layout/space_in_lambda_literal.rb'
    - 'lib/rubocop/cop/layout/space_inside_reference_brackets.rb'
    - 'lib/rubocop/cop/lint/ambiguous_operator_precedence.rb'
    - 'lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb'
    - 'lib/rubocop/cop/lint/identity_comparison.rb'
    - 'lib/rubocop/cop/lint/literal_as_condition.rb'
    - 'lib/rubocop/cop/lint/multiple_comparison.rb'
    - 'lib/rubocop/cop/style/array_join.rb'
    - 'lib/rubocop/cop/style/bitwise_predicate.rb'
    - 'lib/rubocop/cop/style/case_equality.rb'
    - 'lib/rubocop/cop/style/conditional_assignment.rb'
    - 'lib/rubocop/cop/style/double_negation.rb'
    - 'lib/rubocop/cop/style/even_odd.rb'
    - 'lib/rubocop/cop/style/float_division.rb'
    - 'lib/rubocop/cop/style/nil_comparison.rb'
    - 'lib/rubocop/cop/style/non_nil_check.rb'
    - 'lib/rubocop/cop/style/not.rb'
    - 'lib/rubocop/cop/style/operator_method_call.rb'
    - 'lib/rubocop/cop/style/stabby_lambda_parentheses.rb'
    - 'lib/rubocop/cop/style/string_concatenation.rb'
    - 'lib/rubocop/cop/style/yoda_condition.rb'
    - 'lib/rubocop/cop/style/yoda_expression.rb'

    # `send` receiver is constant / self / literal
    - 'lib/rubocop/cop/lint/big_decimal_new.rb'
    - 'lib/rubocop/cop/lint/debugger.rb'
    - 'lib/rubocop/cop/lint/deprecated_class_methods.rb'
    - 'lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb'
    - 'lib/rubocop/cop/lint/erb_new_arguments.rb'
    - 'lib/rubocop/cop/lint/format_parameter_mismatch.rb'
    - 'lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb'
    - 'lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb'
    - 'lib/rubocop/cop/lint/inherit_exception.rb'
    - 'lib/rubocop/cop/lint/non_atomic_file_operation.rb'
    - 'lib/rubocop/cop/lint/redundant_dir_glob_sort.rb'
    - 'lib/rubocop/cop/lint/send_with_mixin_argument.rb'
    - 'lib/rubocop/cop/lint/shared_mutable_default.rb'
    - 'lib/rubocop/cop/lint/data_define_override.rb'
    - 'lib/rubocop/cop/lint/struct_new_override.rb'
    - 'lib/rubocop/cop/lint/symbol_conversion.rb'
    - 'lib/rubocop/cop/lint/to_enum_arguments.rb'
    - 'lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb'
    - 'lib/rubocop/cop/lint/uri_escape_unescape.rb'
    - 'lib/rubocop/cop/lint/uri_regexp.rb'
    - 'lib/rubocop/cop/metrics/collection_literal_length.rb'
    - 'lib/rubocop/cop/security/io_methods.rb'
    - 'lib/rubocop/cop/security/json_load.rb'
    - 'lib/rubocop/cop/security/marshal_load.rb'
    - 'lib/rubocop/cop/security/open.rb'
    - 'lib/rubocop/cop/security/yaml_load.rb'
    - 'lib/rubocop/cop/style/auto_resource_cleanup.rb'
    - 'lib/rubocop/cop/style/class_equality_comparison.rb'
    - 'lib/rubocop/cop/style/comparable_clamp.rb'
    - 'lib/rubocop/cop/style/dir.rb'
    - 'lib/rubocop/cop/style/dir_empty.rb'
    - 'lib/rubocop/cop/style/empty_literal.rb'
    - 'lib/rubocop/cop/style/env_home.rb'
    - 'lib/rubocop/cop/style/expand_path_arguments.rb'
    - 'lib/rubocop/cop/style/fetch_env_var.rb'
    - 'lib/rubocop/cop/style/file_empty.rb'
    - 'lib/rubocop/cop/style/file_read.rb'
    - 'lib/rubocop/cop/style/file_touch.rb'
    - 'lib/rubocop/cop/style/file_write.rb'
    - 'lib/rubocop/cop/style/format_string.rb'
    - 'lib/rubocop/cop/style/hash_conversion.rb'
    - 'lib/rubocop/cop/style/nested_file_dirname.rb'
    - 'lib/rubocop/cop/style/random_with_offset.rb'
    - 'lib/rubocop/cop/style/redundant_array_constructor.rb'
    - 'lib/rubocop/cop/style/redundant_format.rb'
    - 'lib/rubocop/cop/style/redundant_freeze.rb'
    - 'lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb'
    - 'lib/rubocop/cop/style/redundant_regexp_constructor.rb'
    - 'lib/rubocop/cop/style/redundant_self.rb'
    - 'lib/rubocop/cop/style/stderr_puts.rb'
    - 'lib/rubocop/cop/style/yaml_file_read.rb'

    # `send` is a keyword / macro / has no receiver
    - 'lib/rubocop/cop/internal_affairs/create_empty_file.rb'
    - 'lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb'
    - 'lib/rubocop/cop/internal_affairs/example_description.rb'
    - 'lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb'
    - 'lib/rubocop/cop/internal_affairs/node_matcher_directive.rb'
    - 'lib/rubocop/cop/internal_affairs/node_pattern_groups.rb'
    - 'lib/rubocop/cop/internal_affairs/offense_location_keyword.rb'
    - 'lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb'
    - 'lib/rubocop/cop/internal_affairs/redundant_expect_offense_arguments.rb'
    - 'lib/rubocop/cop/internal_affairs/redundant_location_argument.rb'
    - 'lib/rubocop/cop/internal_affairs/redundant_message_argument.rb'
    - 'lib/rubocop/cop/internal_affairs/style_detected_api_use.rb'
    - 'lib/rubocop/cop/internal_affairs/undefined_config.rb'
    - 'lib/rubocop/cop/layout/def_end_alignment.rb'
    - 'lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb'
    - 'lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb'
    - 'lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb'
    - 'lib/rubocop/cop/layout/space_around_keyword.rb'
    - 'lib/rubocop/cop/lint/constant_reassignment.rb'
    - 'lib/rubocop/cop/lint/duplicate_methods.rb'
    - 'lib/rubocop/cop/lint/duplicate_require.rb'
    - 'lib/rubocop/cop/lint/lambda_without_literal_block.rb'
    - 'lib/rubocop/cop/lint/raise_exception.rb'
    - 'lib/rubocop/cop/lint/rand_one.rb'
    - 'lib/rubocop/cop/lint/redundant_require_statement.rb'
    - 'lib/rubocop/cop/lint/redundant_string_coercion.rb'
    - 'lib/rubocop/cop/lint/refinement_import_methods.rb'
    - 'lib/rubocop/cop/lint/require_relative_self_path.rb'
    - 'lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb'
    - 'lib/rubocop/cop/lint/useless_ruby2_keywords.rb'
    - 'lib/rubocop/cop/naming/method_name.rb'
    - 'lib/rubocop/cop/naming/predicate_prefix.rb'
    - 'lib/rubocop/cop/security/eval.rb'
    - 'lib/rubocop/cop/style/access_modifier_declarations.rb'
    - 'lib/rubocop/cop/style/alias.rb'
    - 'lib/rubocop/cop/style/attr.rb'
    - 'lib/rubocop/cop/style/class_vars.rb'
    - 'lib/rubocop/cop/style/document_dynamic_eval_definition.rb'
    - 'lib/rubocop/cop/style/eval_with_location.rb'
    - 'lib/rubocop/cop/style/implicit_runtime_error.rb'
    - 'lib/rubocop/cop/style/mixin_usage.rb'
    - 'lib/rubocop/cop/style/raise_args.rb'
    - 'lib/rubocop/cop/style/redundant_current_directory_in_path.rb'
    - 'lib/rubocop/cop/style/redundant_exception.rb'
    - 'lib/rubocop/cop/style/redundant_file_extension_in_require.rb'
    - 'lib/rubocop/cop/style/redundant_return.rb'
    - 'lib/rubocop/cop/style/require_order.rb'
    - 'lib/rubocop/cop/style/signal_exception.rb'
    - 'lib/rubocop/cop/style/top_level_method_definition.rb'

    # not valid or plausible for safe navigation
    - 'lib/rubocop/cop/internal_affairs/cop_enabled.rb'
    - 'lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb'
    - 'lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb'
    - 'lib/rubocop/cop/lint/it_without_arguments_in_block.rb'
    - 'lib/rubocop/cop/lint/safe_navigation_chain.rb'
    - 'lib/rubocop/cop/lint/useless_times.rb'
    - 'lib/rubocop/cop/style/collection_querying.rb'
    - 'lib/rubocop/cop/style/colon_method_call.rb'
    - 'lib/rubocop/cop/style/numeric_predicate.rb'
    - 'lib/rubocop/cop/style/single_argument_dig.rb'

Gemspec/DependencyVersion:
  Enabled: true

Style/RequireOrder:
  Enabled: true
