Resolve auto-correctable RuboCop offenses (Exclude-only) in .rubocop_todo/**/*.yml
❗ COMMUNITY CONTRIBUTORS, PLEASE ONLY PICKUP ONE COP VIOLATION TO ALLOW OTHER NEW CONTRIBUTORS TO LEARN FROM THESE TOO ❗
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 --autocorrect --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
-
FactoryBot/CreateList
(77 entries) -
Gemspec/DeprecatedAttributeAssignment
(1 entries) -
Gitlab/Rails/SafeFormat
(8 entries) -
Gitlab/StrongMemoizeAttr
(629 entries) -
GraphQL/FieldDefinitions
(1 entries) -
GraphQL/FieldHashKey
(1 entries) -
GraphQL/FieldMethod
(1 entries) -
GraphQL/OrderedFields
(8 entries) -
GraphQL/UnnecessaryFieldAlias
(8 entries) -
GraphQL/UnusedArgument
(2 entries) -
Graphql/Descriptions
(84 entries) -
Graphql/ResourceNotAvailableError
(34 entries) -
Layout/ArgumentAlignment
(1279 entries) -
Layout/ArrayAlignment
(333 entries) -
Layout/ClassStructure
(8 entries) -
Layout/ClosingParenthesisIndentation
(2 entries) -
Layout/EmptyLineAfterMagicComment
(724 entries) -
Layout/ExtraSpacing
(8 entries) -
Layout/FirstArgumentIndentation
(21 entries) -
Layout/FirstArrayElementIndentation
(69 entries) -
Layout/FirstHashElementIndentation
(237 entries) -
Layout/HashAlignment
(6 entries) -
Layout/LeadingCommentSpace
(2 entries) -
Layout/LeadingEmptyLines
(8 entries) -
Layout/LineBreakAfterFinalMixin
(8 entries) -
Layout/LineContinuationLeadingSpace
(63 entries) -
Layout/LineContinuationSpacing
(187 entries) -
Layout/LineEndStringConcatenationIndentation
(301 entries) -
Layout/LineLength
(4805 entries) -
Layout/MultilineOperationIndentation
(62 entries) -
Layout/ParameterAlignment
(6 entries) -
Layout/SpaceBeforeBlockBraces
(1 entries) -
Layout/SpaceInLambdaLiteral
(379 entries) -
Layout/SpaceInsideBlockBraces
(1 entries) -
Layout/SpaceInsideParens
(218 entries) -
Layout/SpaceInsidePercentLiteralDelimiters
(1 entries) -
Layout/TrailingEmptyLines
(8 entries) -
Layout/TrailingWhitespace
(4 entries) -
Lint/AmbiguousOperatorPrecedence
(134 entries) -
Lint/AmbiguousRange
(5 entries) -
Lint/AmbiguousRegexpLiteral
(86 entries) -
Lint/AssignmentInCondition
(242 entries) -
Lint/DeprecatedConstants
(2 entries) -
Lint/DuplicateRegexpCharacterClassElement
(1 entries) -
Lint/IncompatibleIoSelectWithFiberScheduler
(1 entries) -
Lint/NonAtomicFileOperation
(35 entries) -
Lint/OrAssignmentToConstant
(2 entries) -
Lint/RedundantCopDisableDirective
(283 entries) -
Lint/RedundantDirGlobSort
(5 entries) -
Lint/RedundantSafeNavigation
(9 entries) -
Lint/RedundantStringCoercion
(2 entries) -
Lint/SymbolConversion
(137 entries) -
Lint/UnusedBlockArgument
(401 entries) -
Lint/UnusedMethodArgument
(607 entries) -
Lint/UselessAssignment
(8 entries) -
Naming/HeredocDelimiterCase
(5 entries) -
Naming/InclusiveLanguage
(8 entries) -
Performance/FlatMap
(29 entries) -
Performance/MapCompact
(123 entries) -
Performance/RegexpMatch
(33 entries) -
Performance/StringIdentifierArgument
(8 entries) -
Performance/StringInclude
(1 entries) -
Performance/StringReplacement
(3 entries) -
RSpec/AnyInstanceOf
(351 entries) -
RSpec/BeforeAll
(1 entries) -
RSpec/DescribedClass
(7 entries) -
RSpec/EmptyLineAfterHook
(43 entries) -
RSpec/EnvMocking
(3 entries) -
RSpec/ExampleWording
(8 entries) -
RSpec/ExpectChange
(381 entries) -
RSpec/HooksBeforeExamples
(23 entries) -
RSpec/ReturnFromStub
(234 entries) -
RSpec/ScatteredLet
(243 entries) -
RSpec/SpecifyExpected
(49 entries) -
Rails/FilePath
(115 entries) -
Rails/FindEach
(42 entries) -
Rails/NegateInclude
(34 entries) -
Rails/Pluck
(259 entries) -
Rails/RedundantForeignKey
(55 entries) -
Rails/StrongParams
(8 entries) -
Rails/TimeZone
(80 entries) -
Style/AccessorGrouping
(65 entries) -
Style/ArgumentsForwarding
(164 entries) -
Style/BlockDelimiters
(63 entries) -
Style/ClassAndModuleChildren
(521 entries) -
Style/CombinableLoops
(8 entries) -
Style/EmptyElse
(23 entries) -
Style/EmptyMethod
(120 entries) -
Style/ExplicitBlockArgument
(86 entries) -
Style/FloatDivision
(2 entries) -
Style/FormatString
(291 entries) -
Style/FrozenStringLiteralComment
(8 entries) -
Style/GuardClause
(564 entries) -
Style/HashAsLastArrayItem
(46 entries) -
Style/HashEachMethods
(76 entries) -
Style/IfUnlessModifier
(885 entries) -
Style/KeywordParametersOrder
(18 entries) - !148567 (merged) -
Style/Lambda
(70 entries) -
Style/MutableConstant
(39 entries) -
Style/NumericLiteralPrefix
(57 entries) -
Style/RedundantInterpolation
(29 entries) -
Style/RedundantParentheses
(8 entries) -
Style/RedundantRegexpEscape
(76 entries) -
Style/RedundantReturn
(95 entries) -
Style/RedundantSelf
(379 entries) -
Style/SelfAssignment
(8 entries) -
Style/SingleArgumentDig
(57 entries) -
Style/SoleNestedConditional
(50 entries) -
Style/StringConcatenation
(281 entries) -
Style/StringLiteralsInInterpolation
(49 entries) -
Style/SymbolProc
(200 entries)
How to regenerate the list?
- Copy+paste the Script from below
👇 as save asregenerate.rb
- Copy+paste the The List from above
☝ and save asold_list.txt
- Run
regenerate.rb < old_list.txt > new_list.txt
- Replace the new list in the The List section
Script
script
#!/usr/bin/env ruby
# frozen_string_literal: true
require "yaml"
sha = `git rev-parse HEAD`.chomp
template = <<~MD
- [ ] [`%{rule_name}`](https://gitlab.com/gitlab-org/gitlab/-/blob/#{sha}/%{path}) (%{entries} entries)
MD
puts "Paste the current markdown bullet point list from https://gitlab.com/gitlab-org/gitlab/-/issues/239356:"
current = $stdin.readlines.to_h { |line| [line[/`(\S+)`/, 1], line] }
todos = Dir.glob(".rubocop_todo/**/*.yml").to_h do |path|
next [nil, []] unless /^# Cop supports --auto-?correct/.match?(File.read(path))
yaml = YAML.safe_load_file(path)
name, config = yaml.first
entries = config.fetch('Exclude', []) || []
[name, [path, entries.size]]
end
todos.delete(nil)
(current.keys | todos.keys).uniq.sort.each do |name|
path, entries = todos[name]
current_line = current[name]
if current_line
current_line.sub!('- [ ]', '- [x]') unless path
puts current_line
elsif path
puts format(template, rule_name: name, path: path, entries: entries.size)
end
end
Edited by Peter Leitzen