Resolve auto-correctable RuboCop offenses (Exclude-only) in .rubocop_todo/**/*.yml
Problem
.rubocop_todo/**/*.yml
contains auto-correctable grep -hr auto-correct .rubocop_todo -A 1 | grep "^[A-Z]"
) which can be fixed automatically.
Implementation guide
Resolve auto-correctable rules which are enabled by letting RuboCop auto-correct them automatically
- Verify that the
👮 you are working on is already enabled. See also #369268 (closed) - Pick a
👮 offense from The List below e.g.Layout/ClosingHeredocIndentation
- Create a branch (e.g.
239356-fix-Layout/ClosingHeredocIndentation
)- Info: Using this issue ID (
239356
) in a branch name will add required labels and reference to this issue in the new merge request.
- Info: Using this issue ID (
- Delete the rule from the corresponding
.rubocop_todo/
YAML file (e.g. https://gitlab.com/gitlab-org/gitlab/-/blob/396a7ccb979635b041285881098b0023faf56bba/.rubocop_todo.yml#L21-32) - Auto-correct RuboCop offenses via e.g.
bundle exec rubocop --auto-correct --only Layout/ClosingHeredocIndentation
- Check changed files and adjust if needed
- Suggestion: In order to keep MRs short one can fix 10-15 files in one go. Depending on the amount of changes in the file.
- Commit and create a merge request
- Hint: You can use
Fix <Cop/Name> offenses
as git commit message - Info: Community contributions can use git trailer
Changelog: other
so they are attributed inCHANGELOG.md
- Hint: You can use
- Mention this merge request in this issue
🎉
The List
Offenses marked with
-
Capybara/CurrentPathExpectation
(325 offenses) !81897 (merged) -
Layout/ArgumentAlignment
(2477 offenses) (!96010 (merged) ...) -
Layout/EmptyLinesAroundAttributeAccessor
(51 offenses) !81264 (merged) -
Layout/FirstArrayElementIndentation
(1115 offenses) (!97213 (merged) ...) -
Layout/FirstHashElementIndentation
(1999 offenses) -
Layout/HashAlignment
(3711 offenses) !93427 (closed) -
Layout/LineLength
(67 offenses) -
Layout/MultilineOperationIndentation
(254 offenses) !105765 (merged) -
Layout/SpaceAroundMethodCallOperator
(35 offenses) !93381 (merged) -
Layout/SpaceInLambdaLiteral
(948 offenses) !97180 -
Layout/SpaceInsideBlockBraces
!93383 (merged) -
Layout/SpaceInsideParens
(687 offenses) (in progress, multiple MRs) -
Lint/RedundantCopDisableDirective
(236 offenses) -
Lint/UselessMethodDefinition
(27 offenses) - [-]
Naming/RescuedExceptionsVariableName
(249 offenses) -⚠ !93828 (comment 1054703843) -
Performance/AncestorsInclude
(1 offenses) -
Performance/BlockGivenWithExplicitBlock
(51 offenses) !93800 (merged) -
Performance/ConstantRegexp
(47 offenses) !93426 (merged) -
Performance/DeletePrefix
(12 offenses) -
Performance/DeleteSuffix
(1 offenses) !81344 (merged) -
Performance/StringInclude
(14 offenses) - !110576 (merged) -
Performance/Sum
(13 offenses) !81350 (merged) -
RSpec/ExpectChange
- 1 ... -
RSpec/PredicateMatcher
(2464 offenses) -
RSpec/ReturnFromStub
(689 offenses) -
RSpec/ScatteredLet
(692 offenses) -
Rails/ActiveRecordCallbacksOrder
(27 offenses) -
Rails/ApplicationController
(9 offenses) !83291 (merged) -
Rails/BelongsTo
(3 offenses) !81382 (merged) -
Rails/ContentTag
(160 offenses) -
Rails/FindById
(15 offenses) -
Rails/IndexBy
(17 offenses) !81391 (merged) -
Rails/IndexWith
(53 offenses) !105409 (merged) -
Rails/LinkToBlank
(2 offenses) !81397 (merged) -
Rails/MailerName
(1 offenses) !84566 (closed)❗ See the discussion below #239356 (comment 956419227) -
Rails/NegateInclude
(60 offenses) !105387 (merged) -
Rails/Pick
(38 offenses) !93973 (merged) -
Rails/Pluck
(150 offenses) -
Rails/RakeEnvironment
(31 offenses) !93419 (merged) -
Rails/RedundantForeignKey
(88 offenses) -
Rails/ShortI18n
(1 offenses) !81399 (merged) -
Rails/SquishedSQLHeredocs
(323 offenses) -
Rails/WhereExists
(46 offenses) !96675 (closed) -
Style/AccessorGrouping
(255 offenses) -
Style/ArrayCoercion
(6 offenses) !93421 (merged) - [-]
Style/BarePercentLiterals
(223 offenses) ON HOLD -
Style/BisectedAttrAccessor
(2 offenses) !83834 (merged) -
Style/CaseLikeIf
(58 offenses) -
Style/EachWithObject
(5 offenses) !83823 (merged) -
Style/EmptyElse
(58 offenses) -
Style/EmptyMethod
(230 offenses) -
Style/ExpandPathArguments
(1 offenses) !83728 (merged) -
Style/ExplicitBlockArgument
(139 offenses) -
Style/FormatString
(738 offenses) -
Style/HashAsLastArrayItem
(75 offenses) -
Style/HashEachMethods
(93 offenses) -
Style/IfUnlessModifier
(1916 offenses) -
Style/KeywordParametersOrder
(103 offenses) -
Style/Lambda
(599 offenses) -
Style/Next
(38 offenses) !93329 (merged) -
Style/NumericLiteralPrefix
(124 offenses) -
Style/PercentLiteralDelimiters
(3001 offenses) -
Style/RedundantFetchBlock
(26 offenses) !82093 (merged) -
Style/RedundantInterpolation
(275 offenses) -
Style/RedundantRegexpEscape
(323 offenses) -
Style/RedundantSelf
(1163 offenses) -
Style/RescueModifier
(61 offenses) !93420 (merged) -
Style/SingleArgumentDig
(159 offenses) -
Style/StringConcatenation
(610 offenses) -
Style/StringLiteralsInInterpolation
(115 offenses) -
Style/SymbolProc
(330 offenses) -
Layout/LineLength
(19721 offenses)
Script
script
sha = `git rev-parse HEAD`.chomp
template = <<~MD
- [ ] [`%{rule_name}`](https://gitlab.com/gitlab-org/gitlab/-/blob/#{sha}/.rubocop_todo.yml#L%{lineno}) (%{offenses} offenses)
MD
File.open(".rubocop_todo.yml") do |file|
new_rule = proc {
$offenses = nil
$rule_name = nil
$track = false
$lineno = nil
}
new_rule.call
file.each.with_index do |line, i|
case line
when /^$/ # new rule
new_rule.call
when /^# Offense count: (\d+)/
$offenses = $1
when /^# Cop supports --auto-correct/
$track = true
when %r{^(\w+\/\w+):$}
next new_rule.call unless $track
$rule_name = $1
$lineno = i + 1
when /\s+Exclude:/, /\s+Enabled:/
next unless $track
puts template % { rule_name: $rule_name, lineno: $lineno, offenses: $offenses }
end
end
end