Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo the Rubocop config #564

Merged
merged 6 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
360 changes: 53 additions & 307 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,341 +1,87 @@
# SEVERITY LEVELS
# In the GitHub CI/CD, we can only distinguish between "error" and "warning".
# In Rubocop this is much more granular: "info", "refactor", "convention",
# "warning", "error" and "fatal".
# From the docs: "The level is normally 'warning' for Lint and 'convention' for
# all the others, but this can be changed in user configuration."
# However, we don't want to set the severity for each cop individually, so instead
# we set the fatal level as "convention" in the CI/CD,
# i.e. severity: "convention" and up will be treated as an error on GitHub
# and below as warning such that the check will still pass (with a warning).
#
# Short:
# "convention" severity and up = Error on GitHub (CI/CD) -> check fails
# "refactor" severity and below = Warning on GitHub (CI/CD) -> check passes
#
# see the docs on severity
# https://docs.rubocop.org/rubocop/configuration.html#severity

# "Rubocop defaults" are by default required/included:
# https://github.com/rubocop/rubocop/blob/master/config/default.yml
require:
- rubocop-packaging
- rubocop-performance
- rubocop-rails

AllCops:
TargetRubyVersion: 3.0
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: false
Exclude:
- '**/tmp/**/*'
- '**/templates/**/*'
- '**/vendor/**/*'
- 'actionpack/lib/action_dispatch/journey/parser.rb'
- 'actionmailbox/test/dummy/**/*'
- 'actiontext/test/dummy/**/*'
- '**/node_modules/**/*'
# While default cops are automatically included, they are not "configured"
# by default (only on each next major version of RuboCop). Therefore, we
# have to explicitly configure them here.
# see https://docs.rubocop.org/rubocop/configuration.html#defaults
# and https://docs.rubocop.org/rubocop/1.2/versioning.html#pending-cops
NewCops: enable
# Ruby version is determined automatically from the Gemfile.lock

#############################################
# Layout
#############################################

Performance:
Exclude:
- '**/test/**/*'

# Prefer assert_not over assert !
Rails/AssertNot:
Include:
- '**/test/**/*'

# Prefer assert_not_x over refute_x
Rails/RefuteMethods:
Include:
- '**/test/**/*'

Rails/IndexBy:
Enabled: true

Rails/IndexWith:
Enabled: true

# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

Layout/ArgumentAlignment:
Enabled: true

Layout/ArrayAlignment:
Enabled: true

Layout/BlockAlignment:
Enabled: true

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

Layout/ClosingHeredocIndentation:
Enabled: true

# Align comments with method definitions.
Layout/CommentIndentation:
Enabled: true

Layout/ElseAlignment:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable
AutoCorrect: true

Layout/EmptyLines:
Enabled: true

Layout/EmptyLineAfterMagicComment:
Enabled: true

Layout/EmptyLinesAroundAccessModifier:
Enabled: true

Layout/EmptyLinesAroundBlockBody:
Enabled: true

# In a regular class definition, no empty lines around the body.
Layout/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Layout/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Layout/EmptyLinesAroundModuleBody:
Enabled: true

Layout/ExtraSpacing:
Enabled: true

Layout/LineLength:
Max: 80
Max: 100

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true

Layout/FirstArgumentIndentation:
Enabled: true

Layout/HashAlignment:
Enabled: true

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: indented_internal_methods

# Two spaces, no tabs (for indentation).
Layout/IndentationWidth:
Enabled: true

Layout/LeadingCommentSpace:
Enabled: true

Layout/MultilineOperationIndentation:
Enabled: true

Layout/SpaceAfterColon:
Enabled: true

Layout/SpaceAfterComma:
Enabled: true

Layout/SpaceAfterSemicolon:
Enabled: true

Layout/SpaceAroundEqualsInParameterDefault:
Enabled: true

Layout/SpaceAroundKeyword:
Enabled: true
#############################################
# Metrics
#############################################

Layout/SpaceBeforeComma:
Enabled: true

Layout/SpaceBeforeComment:
Enabled: true

Layout/SpaceBeforeFirstArg:
Enabled: true

Layout/SpaceInsideArrayLiteralBrackets:
Enabled: true

Style/BlockDelimiters:
Enabled: true

Style/BlockComments:
Enabled: true
Metrics:
Enabled: false

Style/ConditionalAssignment:
Metrics/ParameterLists:
Enabled: true

Style/DefWithParentheses:
Enabled: true
#############################################
# Style
#############################################

Style/Documentation:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

Style/MethodCallWithoutArgsParentheses:
Enabled: true
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always
Exclude:
- 'actionview/test/**/*.builder'
- 'actionview/test/**/*.ruby'
- 'actionpack/test/**/*.builder'
- 'actionpack/test/**/*.ruby'
- 'activestorage/db/migrate/**/*.rb'
- 'activestorage/db/update_migrate/**/*.rb'
- 'actionmailbox/db/migrate/**/*.rb'
- 'actiontext/db/migrate/**/*.rb'

Style/NumericLiterals:
Enabled: true

Style/NumericPredicate:
Enabled: true

Style/RedundantFreeze:
Enabled: true

Style/SymbolProc:
Enabled: true
EnforcedStyle: never

Style/SymbolArray:
Enabled: false

# Use `foo {}` not `foo{}`.
Layout/SpaceBeforeBlockBraces:
Enabled: true
EnforcedStyle: brackets

# Use `foo { bar }` not `foo {bar}`.
Layout/SpaceInsideBlockBraces:
Enabled: true
EnforcedStyleForEmptyBraces: space

# Use `{ a: 1 }` not `{a:1}`.
Layout/SpaceInsideHashLiteralBraces:
Enabled: true

Layout/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes

# Detect hard tabs, no hard tabs.
Layout/IndentationStyle:
Enabled: true

# Empty lines should not have any spaces.
Layout/TrailingEmptyLines:
Enabled: true

# No trailing whitespace.
Layout/TrailingWhitespace:
Enabled: true

# Use quotes for string literals when they are enough.
Style/RedundantPercentQ:
Enabled: true

Lint/AmbiguousOperator:
Enabled: true

Lint/AmbiguousRegexpLiteral:
Enabled: true

Lint/ErbNewArguments:
Enabled: true

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true

Lint/ShadowingOuterLocalVariable:
Enabled: true

Lint/RedundantStringCoercion:
Enabled: true

Lint/UriEscapeUnescape:
Enabled: true

Lint/UselessAssignment:
Enabled: true

Lint/DeprecatedClassMethods:
Enabled: true
EnforcedStyle: double_quotes

Naming/VariableNumber:
Enabled: true

Style/ParenthesesAroundCondition:
Enabled: true

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true

Style/RedundantBegin:
Enabled: true
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/RedundantReturn:
Splines marked this conversation as resolved.
Show resolved Hide resolved
Enabled: true
AllowMultipleReturnValues: true

Style/Semicolon:
Enabled: true
AllowAsExpressionSeparator: true

# Prefer Foo.method over Foo::method
Style/ColonMethodCall:
Enabled: true
#############################################
# Performance
#############################################

Style/TrivialAccessors:
Enabled: true
Performance:
Severity: refactor # a warning in CI/CD

Performance/FlatMap:
Enabled: true

Performance/RedundantMerge:
Enabled: true

Performance/StartWith:
Enabled: true

Performance/EndWith:
Enabled: true

Performance/RegexpMatch:
Enabled: true

Performance/ReverseEach:
Enabled: true

Performance/UnfreezeString:
Enabled: true

Performance/DeletePrefix:
Enabled: true

Performance/DeleteSuffix:
Enabled: true

Metrics/ModuleLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/MethodLength:
Exclude:
- 'app/abilities/**/*'

Metrics/AbcSize:
Exclude:
- 'app/abilities/**/*'
Severity: warning # an error in CI/CD
Loading
Loading