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 (for example https://gitlab.com/gitlab-org/gitlab/-/blob/fdeea9247566ca45fece68605a838ebc659b62db/.rubocop_todo/gitlab/rails/safe_format.yml) - 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
(0 entries) -
Gemspec/DeprecatedAttributeAssignment
(0 entries) -
Gitlab/DocumentationLinks/Link
(56 entries) -
Gitlab/Rails/SafeFormat
(29 entries) -
Gitlab/StrongMemoizeAttr
(591 entries) -
GraphQL/FieldDefinitions
(0 entries) -
GraphQL/FieldHashKey
(0 entries) -
GraphQL/FieldMethod
(0 entries) -
GraphQL/OrderedFields
(0 entries) -
GraphQL/UnnecessaryFieldAlias
(0 entries) -
GraphQL/UnusedArgument
(0 entries) -
Graphql/Descriptions
(47 entries) -
Graphql/ResourceNotAvailableError
(26 entries) -
InternalAffairs/CopDescriptionWithExample
(153 entries) -
Layout/ArgumentAlignment
(38 entries) -
Layout/ArrayAlignment
(226 entries) -
Layout/ClassStructure
(479 entries) -
Layout/ClosingParenthesisIndentation
(0 entries) -
Layout/EmptyLineAfterMagicComment
(650 entries) -
Layout/ExtraSpacing
(14 entries) -
Layout/FirstArgumentIndentation
(0 entries) -
Layout/FirstArrayElementIndentation
(0 entries) -
Layout/FirstHashElementIndentation
(104 entries) -
Layout/HashAlignment
(0 entries) -
Layout/LeadingCommentSpace
(0 entries) -
Layout/LeadingEmptyLines
(0 entries) -
Layout/LineBreakAfterFinalMixin
(124 entries) -
Layout/LineContinuationLeadingSpace
(1 entries) -
Layout/LineContinuationSpacing
(172 entries) -
Layout/LineEndStringConcatenationIndentation
(683 entries) -
Layout/LineLength
(4548 entries) -
Layout/MultilineOperationIndentation
(0 entries) -
Layout/ParameterAlignment
(0 entries) -
Layout/SpaceBeforeBlockBraces
(0 entries) -
Layout/SpaceInLambdaLiteral
(0 entries) -
Layout/SpaceInsideBlockBraces
(0 entries) -
Layout/SpaceInsideParens
(100 entries) -
Layout/SpaceInsidePercentLiteralDelimiters
(0 entries) -
Layout/TrailingEmptyLines
(0 entries) -
Layout/TrailingWhitespace
(0 entries) -
Lint/AmbiguousOperatorPrecedence
(0 entries) -
Lint/AmbiguousRange
(0 entries) -
Lint/AmbiguousRegexpLiteral
(0 entries) -
Lint/AssignmentInCondition
(221 entries) -
Lint/DeprecatedConstants
(0 entries) -
Lint/DuplicateRegexpCharacterClassElement
(0 entries) -
Lint/ImplicitStringConcatenation
(1 entries) -
Lint/IncompatibleIoSelectWithFiberScheduler
(0 entries) -
Lint/NonAtomicFileOperation
(20 entries) -
Lint/OrAssignmentToConstant
(0 entries) -
Lint/RedundantCopDisableDirective
(465 entries) -
Lint/RedundantDirGlobSort
(0 entries) -
Lint/RedundantSafeNavigation
(3 entries) -
Lint/RedundantStringCoercion
(0 entries) -
Lint/SafeNavigationConsistency
(13 entries) -
Lint/SymbolConversion
(130 entries) -
Lint/UnusedBlockArgument
(361 entries) -
Lint/UnusedMethodArgument
(544 entries) -
Lint/UselessAssignment
(0 entries) -
Lint/UselessNumericOperation
(1 entries) -
Lint/Void
(2 entries) -
Naming/HeredocDelimiterCase
(0 entries) -
Naming/InclusiveLanguage
(51 entries) -
Performance/FlatMap
(23 entries) -
Performance/MapCompact
(108 entries) -
Performance/RegexpMatch
(0 entries) -
Performance/StringIdentifierArgument
(230 entries) -
Performance/StringInclude
(0 entries) -
Performance/StringReplacement
(0 entries) -
RSpec/AnyInstanceOf
(331 entries) -
RSpec/BeEmpty
(66 entries) -
RSpec/BeEq
(1597 entries) -
RSpec/BeNil
(180 entries) -
RSpec/BeforeAll
(0 entries) -
RSpec/ChangeByZero
(126 entries) -
RSpec/ContainExactly
(208 entries) -
RSpec/DescribedClass
(6 entries) -
RSpec/Dialect
(35 entries) -
RSpec/EmptyLineAfterHook
(0 entries) -
RSpec/EnvMocking
(0 entries) -
RSpec/Eq
(2 entries) -
RSpec/ExampleWording
(73 entries) -
RSpec/ExcessiveDocstringSpacing
(91 entries) -
RSpec/ExpectChange
(358 entries) -
RSpec/HooksBeforeExamples
(0 entries) -
RSpec/IsExpectedSpecify
(34 entries) -
RSpec/MetadataStyle
(44 entries) -
RSpec/ReceiveMessages
(628 entries) -
RSpec/RedundantAround
(1 entries) -
RSpec/RedundantPredicateMatcher
(21 entries) -
RSpec/ReturnFromStub
(197 entries) -
RSpec/ScatteredLet
(218 entries) -
RSpec/SpecifyExpected
(47 entries) -
RSpec/VerifiedDoubleReference
(267 entries) -
Rails/Date
(256 entries) -
Rails/EnumHash
(1 entries) -
Rails/EnumSyntax
(126 entries) -
Rails/FilePath
(108 entries) -
Rails/FindEach
(34 entries) -
Rails/NegateInclude
(0 entries) -
Rails/Pluck
(245 entries) -
Rails/PluralizationGrammar
(19 entries) -
Rails/RedundantForeignKey
(49 entries) -
Rails/StrongParams
(325 entries) -
Rails/TimeZone
(77 entries) -
Rails/WhereRange
(80 entries) -
Style/AccessorGrouping
(63 entries) -
Style/ArgumentsForwarding
(205 entries) -
Style/BlockDelimiters
(59 entries) -
Style/ClassAndModuleChildren
(498 entries) -
Style/CombinableLoops
(6 entries) -
Style/EmptyElse
(21 entries) -
Style/EmptyLiteral
(1 entries) -
Style/EmptyMethod
(0 entries) -
Style/ExplicitBlockArgument
(0 entries) -
Style/FloatDivision
(0 entries) -
Style/FormatString
(253 entries) -
Style/FrozenStringLiteralComment
(0 entries) -
Style/GuardClause
(537 entries) -
Style/HashAsLastArrayItem
(0 entries) -
Style/HashEachMethods
(133 entries) -
Style/IfUnlessModifier
(832 entries) -
Style/Iso8601Date
(0 entries) -
Style/KeywordParametersOrder
(0 entries) - !148567 (merged) -
Style/Lambda
(0 entries) -
Style/MapIntoArray
(11 entries) -
Style/MutableConstant
(35 entries) -
Style/NumericLiteralPrefix
(50 entries) -
Style/RedundantInterpolation
(0 entries) -
Style/RedundantInterpolationUnfreeze
(12 entries) -
Style/RedundantParentheses
(33 entries) -
Style/RedundantRegexpEscape
(39 entries) -
Style/RedundantReturn
(60 entries) -
Style/RedundantSelf
(343 entries) -
Style/SelfAssignment
(0 entries) -
Style/SendWithLiteralMethodName
(9 entries) -
Style/SingleArgumentDig
(0 entries) -
Style/SoleNestedConditional
(40 entries) -
Style/StringConcatenation
(254 entries) -
Style/StringLiteralsInInterpolation
(44 entries) -
Style/SuperArguments
(180 entries) -
Style/SymbolProc
(190 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
# From https://gitlab.com/gitlab-org/gitlab/-/issues/239356#the-list
require "yaml"
sha = `git rev-parse HEAD`.chomp
template = <<~MD
- [ ] [`%{rule_name}`](https://gitlab.com/gitlab-org/gitlab/-/blob/#{sha}/%{path}) (%{entries} entries)
MD
warn "Paste the 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 && !path
current_line.sub!('- [ ]', '- [x]')
current_line.sub!(/\d+ entries/, '0 entries')
puts current_line
elsif path
puts format(template, rule_name: name, path: path, entries: entries)
end
end
Edited by Vitali Tatarintev