Rubocop rules

This commit is contained in:
Nedim
2025-02-17 19:12:40 +01:00
parent ef01db0700
commit ee89170c32
42 changed files with 1043 additions and 267 deletions

101
.rubocop/base.yml Normal file
View File

@@ -0,0 +1,101 @@
# Cross-Repository Rubcop conguration based on Owens Corning Ruby Style Guide
Layout/LineLength:
AutoCorrect: true
Max: 120
Metrics/BlockLength:
# This exclusion is aimed for RSpec DSL blocks
AllowedMethods: ['describe', 'context']
Exclude:
- config/routes.rb
Metrics/ClassLength:
# Matches with requirements for working on legacy code base.
Max: 250
Metrics/MethodLength:
# Matches with requirements for working on legacy code base.
Max: 20
Metrics/AbcSize:
# Matches with requirements for working on legacy code base.
Max: 25
Metrics/CyclomaticComplexity:
# Matches with requirements for working on legacy code base.
Max: 12
Naming/MemoizedInstanceVariableName:
# There should be clear distionction between explicit instance
# variables and memoized method result. Using underscore before
# name of the variable makes it less likely to confuse those two.
# This convention @_calculate_data also makes it more clear, that
# the variable should _not_ be referenced directly.
EnforcedStyleForLeadingUnderscores: optional
Style/ClassAndModuleChildren:
# Our codebase is full of compact style namespaces. We had several issues
# following incorrect fix for this cop (mixed Module with Class). Let's
# disable this for now, until figure out a better way to introduce this
# cop, perhaps with a bit better test coverage.
Enabled: false
Style/Documentation:
# Don't require comments as documentation.
# They're optional though. Prefer readable code.
Enabled: false
Style/DoubleNegation:
# Allow double negation.
# (If enabled, this Cop warns when we use it.)
Enabled: false
Style/FrozenStringLiteralComment:
# This Cop adds a comment to the top of every file
# to enable a new ruby feature: immutable strings.
#
# The Ruby creator said this feature would be enabled
# by default on Ruby 3.
# Switching from Ruby 2 to 3 would be painful if the
# codebase was not prepared for it, so one way to prepare
# was to enable this optional feature.
#
# However, this plan was canceled.
# See https://bugs.ruby-lang.org/issues/11473#note-53
#
# Disable the Cop, we can opt-in on a case-by-case basis.
Enabled: false
Style/NumericLiterals:
# It's trivial to fix this issue globally, but the value seems to be minimal.
# I am disabling for now, until we decide this is worth pursuing.
Enabled: false
Style/PercentLiteralDelimiters:
Enabled: false
Style/StringLiterals:
# Allow single or double quotes.
# There's times when one or the other makes sense.
# Please try to be consistent within the same file, though.
Enabled: false
# Disabling any kinds of enforcement on Trailing argument, are there
# seem to be disagreement on which way we should go. Defaults are
# to remove those, but trailing commans in multiline definitions are very
# useful, as they help to reduce diff churn and make code reviews easier.
# Perhaps we should enforce the trailing on multiline at some later time.
# Let's just prevent corrections in the wrong direction for now.
Style/TrailingCommaInArguments:
# See comment above
Enabled: false
Style/TrailingCommaInArrayLiteral:
# See comment above
Enabled: false
Style/TrailingCommaInHashLiteral:
# See comment above
Enabled: false

5
.rubocop/factory_bot.yml Normal file
View File

@@ -0,0 +1,5 @@
# Cross-Repository conguration for Cops of the rubocop-factory_bot extension
FactoryBot:
Include:
- spec/factories/**/*

26
.rubocop/local.yml Normal file
View File

@@ -0,0 +1,26 @@
# Repository individual configurations
Metrics/BlockLength:
Exclude:
- config/routes.rb
- Gemfile
Naming/VariableNumber:
Enabled: true
AllowedIdentifiers: [
'street_1',
'street_2',
'ship_to_address_line_1',
'ship_to_address_line_2',
'ship_to_address_line_3',
'shipping_point_address_line_1',
'shipping_point_address_line_2',
'shipping_point_address_line_3',
]
Lint/MissingSuper:
AllowedParentClasses: [
'Bazaarvoice::BaseService',
'BaseService'
]
Rails/DynamicFindBy:
Whitelist:
- find_by_ums_guid

24
.rubocop/rails.yml Normal file
View File

@@ -0,0 +1,24 @@
# Cross-Repository conguration for Cops of the rubocop-rails extension
Rails/BelongsTo:
# This is about changing "required: true" to "optional: false". Wording of
# this warning is a bit unfortunate, as it suggest the option is not needed
# at all:
#
# C: [Correctable] Rails/BelongsTo: You specified required: true, in Rails
# > 5.0 the required option is deprecated and you want to use optional:
# false. In most configurations, this is the default and you can omit this
# option altogether
#
# This is only true, if framework defaults for 5.0 are loaded or special
# option config.active_record.belongs_to_required_by_default is set to true.
#
# None of those are set in MDMS, so lets remove this cop, to avoid pushing
# someone to remove the "required: true" and changing the behaviour by
# mistake.
Enabled: false
Rails/RedundantPresenceValidationOnBelongsTo:
# See comment for Rails/BelongsTo. Our setting for default is different
# than defaults in Rails 5+ applications. This should not be enabled.
Enabled: false

5
.rubocop/rails_5.yml Normal file
View File

@@ -0,0 +1,5 @@
# Cross-Repository conguration for Cops of the rubocop-rails extension while running rails version 5
Rails/ResponseParsedBody:
# We will disable this cop for rails version 5 or lower
Enabled: false

29
.rubocop/rspec.yml Normal file
View File

@@ -0,0 +1,29 @@
# Cross-Repository conguration for Cops of the rubocop-rspec extension
RSpec:
Include:
- spec/**/*
RSpec/ExampleLength:
# Topic on how to structure the specs is whole separate thing. When
# we want to reduce let/before to improve redablity, then block length
# cannot stay low. See comments on "MultipleExpectations".
Enabled: false
RSpec/MultipleExpectations:
# Disable check for multiple Expectations in single specs. Forcing
# single assertion requires repeated specs, which might slow down
# legacy test suites. Also this forces heavey extraction into
# separate lets/before which itself causes readablity issues.
# Please refer to https://thoughtbot.com/blog/lets-not
Enabled: false
RSpec/MultipleMemoizedHelpers:
# Current legacy codebase uses a lot of helpers in RSpec. Please see comment
# for RSpec/MultipleExpectations why this is not a good thing. For now
# "lets" (hehe) relax this rule.
Max: 35
RSpec/NestedGroups:
# Legacy codebase. Relax for now to avoid heavy refactoring.
Max: 7

14
.rubocop/strict.yml Normal file
View File

@@ -0,0 +1,14 @@
# Cross-Repository configuration of Cops that are mandatory enabled.
#
# There are a handful of cops that must be enabled for all the files
# independently of any prior excludes.
Lint/Debugger:
# don't leave binding.pry or debugger
Enabled: true
Exclude: []
Rails/UniqBeforePluck:
# uniq.pluck and not pluck.uniq
Enabled: true
Exclude: []