# Options available at https://github.com/bbatsov/rubocop/blob/master/config/default.yml

require:
  - rubocop-rails
  - rubocop-rspec
  - ./rubocop/rubocop

inherit_mode:
  merge:
    - Exclude

AllCops:
  NewCops: enable
  TargetRubyVersion: 3.1

Bundler/OrderedGems:
  Enabled: false

I18n/DeprecatedTranslationKey:
    Rules:
      name_with_colon: "Prefer `name` with `mailer.general.metadata_label_indicator` over `name_with_colon`"

Layout/DotPosition:
  EnforcedStyle: leading

Layout/EmptyLinesAroundAttributeAccessor:
  Enabled: false

Layout/FirstArrayElementIndentation:
  EnforcedStyle: consistent

Layout/LineLength:
  Enabled: false

Layout/MultilineMethodCallIndentation:
  EnforcedStyle: indented

Layout/SingleLineBlockChain:
  Enabled: true

Layout/TrailingWhitespace:
  Enabled: false

Lint/AmbiguousBlockAssociation:
  Exclude:
    # Exception for specs where we use change matchers:
    # https://github.com/rubocop-hq/rubocop/issues/4222
    - 'features/step_definitions/**/*.rb'
    - 'spec/**/*.rb'

Lint/AmbiguousRegexpLiteral:
  Enabled: false

Lint/RedundantSafeNavigation:
  Exclude:
    # Take a better safe than sorry approach to safe navigation in admin
    # policies.
    - 'app/policies/*.rb'

Metrics/AbcSize:
  Enabled: false

Metrics/BlockLength:
  Enabled: false

Metrics/ClassLength:
  Enabled: false

Metrics/CyclomaticComplexity:
  Enabled: false

Metrics/MethodLength:
  Enabled: false

Metrics/ModuleLength:
  Enabled: false

Metrics/ParameterLists:
  CountKeywordArgs: false

Metrics/PerceivedComplexity:
  Enabled: false

Migration/LargeTableSchemaUpdate:
  Tables:
    - abuse_reports
    - active_storage_attachments
    - active_storage_blobs
    - active_storage_variant_records
    - admin_activities
    - audits
    - blocks
    - bookmarks
    - chapters
    - comments
    - common_taggings
    - collection_items
    - collection_participants
    - collection_preferences
    - collection_profiles
    - collections
    - creatorships
    - external_works
    - favorite_tags
    - feedbacks
    - filter_counts
    - filter_taggings
    - gifts
    - inbox_comments
    - invitations
    - kudos
    - log_items
    - meta_taggings
    - mutes
    - preferences
    - profiles
    - prompts
    - pseuds
    - readings
    - related_works
    - set_taggings
    - serial_works
    - series
    - skins
    - stat_counters
    - subscriptions
    - tag_nominations
    - tag_set_associations
    - tag_sets
    - taggings
    - tags
    - users
    - works

Naming/VariableNumber:
  AllowedIdentifiers:
    - age_over_13
    - no_age_over_13

Rails/DefaultScope:
  Enabled: true

Rails/DynamicFindBy:
  AllowedMethods:
    # Exceptions for Tag.find_by_name and Tag.find_by_name!
    - find_by_name
    - find_by_name!
    # Exception for Tagging.find_by_tag
    - find_by_tag
    # Exceptions for Work.find_by_*
    - find_by_url
    - find_by_url_cache_key
    - find_by_url_generation
    - find_by_url_generation_key
    - find_by_url_uncached
    # Exceptions for InboxComment.find_by_filters
    - find_by_filters

Rails/EnvironmentVariableAccess:
  Enabled: true

# Allow all uses of html_safe, they're everywhere...
Rails/OutputSafety:
  Enabled: false

Rails/Output:
  Exclude:
    # Allow patches to print warnings to console:
    - 'config/initializers/monkeypatches/*.rb'
    # Allow migrations to print pt-osc comments to console:
    - 'db/migrate/*.rb'

Rails/RakeEnvironment:
  Enabled: false

Rails/ReversibleMigrationMethodDefinition:
  Enabled: true

# Allow update_attribute, update_all, touch, etc.
Rails/SkipsModelValidations:
  Enabled: false

Rails/UnknownEnv:
  Environments:
    - development
    - test
    - staging
    - production

RSpec:
  Include:
    - "(?:^|/)factories/"
    - "(?:^|/)features/"
    - "(?:^|/)spec/"

# Allow "allow_any_instance_of"
RSpec/AnyInstance:
  Enabled: false

# By default allow only prefixes "when", "with", "without".
# We have too many, so let's allow everything.
RSpec/ContextWording:
  Enabled: false

RSpec/DescribeClass:
  Exclude:
    # Exception for specs about I18n configurations
    - 'spec/lib/i18n/**/*.rb'
    # Exception for rake specs, where the top level describe uses a task name
    - 'spec/lib/tasks/*.rake_spec.rb'
    # Exception for integration specs, which may not test a specific class
    - 'spec/requests/**/*.rb'

RSpec/DescribedClass:
  Enabled: false

RSpec/ExampleLength:
  Enabled: false

# Prefer: expect { run }.to change { Foo.bar }
# over: expect { run }.to change(Foo, :bar)
RSpec/ExpectChange:
  EnforcedStyle: block

RSpec/FilePath:
  Exclude:
    # Exception for WorksController, whose many specs need multiple files
    - 'spec/controllers/works/*.rb'
    # Exception for concern specs, which may test multiple classes
    - 'spec/models/concerns/**/*.rb'

# Avoid instance variables, except for those not assigned within the spec,
# e.g. @request.
RSpec/InstanceVariable:
  AssignmentOnly: true

# Allow unreferenced let! calls for test setup
RSpec/LetSetup:
  Enabled: false

# Allow both "have_received" and "receive" for expectations
RSpec/MessageSpies:
  Enabled: false

# Allow multiple top level describes (rake specs)
RSpec/MultipleDescribes:
  Enabled: false

# Allow unlimited expectations per test
RSpec/MultipleExpectations:
  Enabled: false

# Allow unnamed subjects
RSpec/NamedSubject:
  Enabled: false

# Allow unlimited nested groups
RSpec/NestedGroups:
  Enabled: false

RSpec/PredicateMatcher:
  Enabled: false

Style/AndOr:
  EnforcedStyle: conditionals

Style/ClassAndModuleChildren:
  Enabled: false

Style/Documentation:
  Enabled: false

Style/EmptyMethod:
  EnforcedStyle: expanded

# Prefer template tokens (like %{foo}) over annotated tokens (like %s)
Style/FormatStringToken:
  EnforcedStyle: template

Style/FrozenStringLiteralComment:
  Enabled: false

Style/GlobalVars:
  AllowedVariables:
    - $elasticsearch
    - $rollout

Style/PercentLiteralDelimiters:
  Exclude:
    # Exception for Cucumber step definitions, where we heavily use %{} for strings
    - 'features/**/*.rb'

# Stop checking if uses of "self" are redundant
Style/RedundantSelf:
  Enabled: false

Style/SelectByRegexp:
  Enabled: true

Style/SingleLineMethods:
  AllowIfMethodIsEmpty: false

Style/StringLiterals:
  EnforcedStyle: double_quotes

Style/SymbolArray:
  Enabled: false

Style/TernaryParentheses:
  EnforcedStyle: require_parentheses_when_complex
