Resolve auto-correctable RuboCop offenses (Exclude-only) in .rubocop_todo/**/*.yml
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
❗ 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-abc/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 your username or initials (e.g.
abc/above) in the branch name will help to prevent branch naming clashes with other contributors also working on this issue.
- 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> offensesas git commit message - Info: Community contributions can use git trailer
Changelog: otherso they are attributed inCHANGELOG.md
- Hint: You can use
- Mention this merge request in this issue
🎉
Burndown chart
The List
-
API/DescriptionTags(11 entries) Chart -
API/EntityFieldType(152 entries) Chart -
FactoryBot/CreateList(0 entries) Chart -
Gemspec/DeprecatedAttributeAssignment(0 entries) Chart -
Gitlab/Authz/UsePolicyHelpers(152 entries) Chart -
Gitlab/DocumentationLinks/Link(0 entries) Chart -
Gitlab/FeatureFlagKeyDynamic(27 entries) Chart -
Gitlab/JsonSafeParse(377 entries) Chart -
Gitlab/Rails/AttrEncrypted(50 entries) Chart -
Gitlab/Rails/SafeFormat(0 entries) Chart -
Gitlab/StrongMemoizeAttr(515 entries) Chart -
GraphQL/FieldDefinitions(0 entries) Chart -
GraphQL/FieldHashKey(0 entries) Chart -
GraphQL/FieldMethod(0 entries) Chart -
GraphQL/OrderedFields(0 entries) Chart -
GraphQL/UnnecessaryFieldAlias(0 entries) Chart -
GraphQL/UnusedArgument(0 entries) Chart -
Graphql/Descriptions(0 entries) Chart -
Graphql/ResourceNotAvailableError(0 entries) Chart -
InternalAffairs/CopDescriptionWithExample(115 entries) Chart -
InternalAffairs/ExampleHeredocDelimiter(0 entries) Chart -
InternalAffairs/LocationExpression(0 entries) Chart -
InternalAffairs/NodeMatcherDirective(0 entries) Chart -
InternalAffairs/NodeTypeMultiplePredicates(0 entries) Chart -
InternalAffairs/NodeTypePredicate(0 entries) Chart -
InternalAffairs/RedundantExpectOffenseArguments(0 entries) Chart -
InternalAffairs/RedundantMessageArgument(0 entries) Chart -
InternalAffairs/RedundantSourceRange(0 entries) Chart -
Layout/ArgumentAlignment(0 entries) Chart -
Layout/ArrayAlignment(0 entries) Chart -
Layout/ClassStructure(381 entries) Chart -
Layout/ClosingParenthesisIndentation(0 entries) Chart -
Layout/EmptyLineAfterMagicComment(60 entries) Chart -
Layout/EmptyLines(1 entry) Chart -
Layout/EmptyLinesAroundMethodBody(0 entries) Chart -
Layout/ExtraSpacing(0 entries) Chart -
Layout/FirstArgumentIndentation(0 entries) Chart -
Layout/FirstArrayElementIndentation(0 entries) Chart -
Layout/FirstHashElementIndentation(0 entries) Chart -
Layout/HashAlignment(0 entries) Chart -
Layout/LeadingCommentSpace(0 entries) Chart -
Layout/LeadingEmptyLines(0 entries) Chart -
Layout/LineBreakAfterFinalMixin(23 entries) Chart -
Layout/LineContinuationLeadingSpace(0 entries) Chart -
Layout/LineContinuationSpacing(119 entries) Chart -
Layout/LineEndStringConcatenationIndentation(528 entries) Chart -
Layout/LineLength(3607 entries) Chart -
Layout/MultilineOperationIndentation(0 entries) Chart -
Layout/ParameterAlignment(0 entries) Chart -
Layout/SpaceBeforeBlockBraces(0 entries) Chart -
Layout/SpaceInLambdaLiteral(0 entries) Chart -
Layout/SpaceInsideBlockBraces(0 entries) Chart -
Layout/SpaceInsideParens(0 entries) Chart -
Layout/SpaceInsidePercentLiteralDelimiters(0 entries) Chart -
Layout/TrailingEmptyLines(0 entries) Chart -
Layout/TrailingWhitespace(0 entries) Chart -
Lint/AmbiguousOperatorPrecedence(0 entries) Chart -
Lint/AmbiguousRange(31 entries) Chart -
Lint/AmbiguousRegexpLiteral(0 entries) Chart -
Lint/AssignmentInCondition(189 entries) Chart -
Lint/DeprecatedConstants(0 entries) Chart -
Lint/DuplicateRegexpCharacterClassElement(0 entries) Chart -
Lint/ImplicitStringConcatenation(0 entries) Chart -
Lint/IncompatibleIoSelectWithFiberScheduler(0 entries) Chart -
Lint/NonAtomicFileOperation(0 entries) Chart -
Lint/OrAssignmentToConstant(0 entries) Chart -
Lint/RedundantCopDisableDirective(0 entries) Chart -
Lint/RedundantDirGlobSort(0 entries) Chart -
Lint/RedundantSafeNavigation(0 entries) Chart -
Lint/RedundantStringCoercion(0 entries) Chart -
Lint/SafeNavigationConsistency(0 entries) Chart -
Lint/SymbolConversion(0 entries) Chart -
Lint/UnusedBlockArgument(303 entries) Chart -
Lint/UnusedMethodArgument(460 entries) Chart -
Lint/UselessAccessModifier(5 entries) Chart -
Lint/UselessAssignment(0 entries) Chart -
Lint/UselessNumericOperation(0 entries) Chart -
Lint/Void(1 entry) Chart -
Naming/HeredocDelimiterCase(0 entries) Chart -
Naming/InclusiveLanguage(48 entries) Chart -
Performance/FlatMap(0 entries) Chart -
Performance/MapCompact(83 entries) Chart -
Performance/RegexpMatch(0 entries) Chart -
Performance/StringIdentifierArgument(198 entries) Chart -
Performance/StringInclude(0 entries) Chart -
Performance/StringReplacement(0 entries) Chart -
RSpec/AnyInstanceOf(290 entries) Chart -
RSpec/BeEmpty(0 entries) Chart -
RSpec/BeEq(0 entries) Chart -
RSpec/BeNil(0 entries) Chart -
RSpec/BeforeAll(0 entries) Chart -
RSpec/ChangeByZero(0 entries) Chart -
RSpec/ContainExactly(160 entries) Chart -
RSpec/DescribedClass(0 entries) Chart -
RSpec/Dialect(0 entries) Chart -
RSpec/EmptyLineAfterHook(0 entries) Chart -
RSpec/EnvMocking(0 entries) Chart -
RSpec/Eq(0 entries) Chart -
RSpec/ExampleWording(0 entries) Chart -
RSpec/ExcessiveDocstringSpacing(23 entries) Chart -
RSpec/ExpectChange(0 entries) Chart -
RSpec/HooksBeforeExamples(0 entries) Chart -
RSpec/IsExpectedSpecify(0 entries) Chart -
RSpec/MetadataStyle(0 entries) Chart -
RSpec/ReceiveMessages(24 entries) Chart -
RSpec/RedundantAround(0 entries) Chart -
RSpec/RedundantMetatagType(142 entries) Chart -
RSpec/RedundantPredicateMatcher(12 entries) Chart -
RSpec/ReturnFromStub(127 entries) Chart -
RSpec/ScatteredLet(0 entries) Chart -
RSpec/SpecifyExpected(9 entries) Chart -
RSpec/VerifiedDoubleReference(220 entries) Chart -
Rails/Date(176 entries) Chart -
Rails/EnumHash(0 entries) Chart -
Rails/EnumSyntax(0 entries) Chart -
Rails/FilePath(94 entries) Chart -
Rails/FindEach(12 entries) Chart -
Rails/NegateInclude(0 entries) Chart -
Rails/Pluck(34 entries) Chart -
Rails/PluralizationGrammar(0 entries) Chart -
Rails/RedundantForeignKey(41 entries) Chart -
Rails/StrongParams(0 entries) Chart -
Rails/TimeZone(62 entries) Chart -
Rails/WhereRange(67 entries) Chart -
Style/AccessorGrouping(32 entries) Chart -
Style/ArgumentsForwarding(0 entries) Chart -
Style/BlockDelimiters(0 entries) Chart -
Style/ClassAndModuleChildren(455 entries) Chart -
Style/CombinableLoops(0 entries) Chart -
Style/EmptyElse(17 entries) Chart -
Style/EmptyLiteral(0 entries) Chart -
Style/EmptyMethod(0 entries) Chart -
Style/EndlessMethod(0 entries) Chart -
Style/ExplicitBlockArgument(0 entries) Chart -
Style/FloatDivision(0 entries) Chart -
Style/FormatString(142 entries) Chart -
Style/FrozenStringLiteralComment(0 entries) Chart -
Style/GuardClause(439 entries) Chart -
Style/HashAsLastArrayItem(0 entries) Chart -
Style/HashEachMethods(87 entries) Chart -
Style/IfUnlessModifier(654 entries) Chart -
Style/Iso8601Date(0 entries) Chart -
Style/KeywordParametersOrder(0 entries) - !148567 (merged) Chart -
Style/Lambda(0 entries) Chart -
Style/MapIntoArray(0 entries) Chart -
Style/MutableConstant(26 entries) Chart -
Style/NumericLiteralPrefix(44 entries) Chart -
Style/RedundantCondition(12 entries) Chart -
Style/RedundantInterpolation(0 entries) Chart -
Style/RedundantInterpolationUnfreeze(0 entries) Chart -
Style/RedundantParentheses(36 entries) Chart -
Style/RedundantRegexpCharacterClass(7 entries) Chart -
Style/RedundantRegexpEscape(83 entries) Chart -
Style/RedundantReturn(0 entries) Chart -
Style/RedundantSelf(248 entries) Chart -
Style/SelfAssignment(0 entries) Chart -
Style/SendWithLiteralMethodName(0 entries) Chart -
Style/SingleArgumentDig(0 entries) Chart -
Style/SoleNestedConditional(33 entries) Chart -
Style/StringConcatenation(215 entries) Chart -
Style/StringLiteralsInInterpolation(0 entries) Chart -
Style/SuperArguments(143 entries) Chart -
Style/SymbolProc(150 entries) Chart
How to regenerate the list?
- Copy+paste the Script from below
👇 and save it asregenerate.rbin the root of yourgitlabrepository. - Copy The List from above
☝️ in Markdown format. You can include the heading and the:mega:line. The script skips them. - Paste the list into a new file
old_list.mdin the same directory. - Run
ruby regenerate.rb. It readsold_list.mdand writes the new list tonew_list.md. - Copy+paste the content of
new_list.mdinto The List section.
A cop is ticked only when it has 0 entries left. If a cop still has entries, the script unticks it.
You can also use other file names: ruby regenerate.rb <input_file> <output_file>.
Script
script
#!/usr/bin/env ruby
# frozen_string_literal: true
# From https://gitlab.com/gitlab-org/gitlab/-/issues/239356#the-list
#
# Usage (from the root of the gitlab repo, on an up-to-date master):
# ruby regenerate.rb [old_list.md] [new_list.md]
require "yaml"
BURNDOWN_CHART_URL = "https://ck3g.gitlab.io/rubocop-burndown/"
BLOB_URL = "https://gitlab.com/gitlab-org/gitlab/-/blob"
input_path = ARGV.fetch(0, "old_list.md")
output_path = ARGV.fetch(1, "new_list.md")
sha = `git rev-parse HEAD`.chomp
abort "Could not read git HEAD. Run this from the gitlab repo." if sha.empty?
def entries_text(count)
"#{count} #{count == 1 ? 'entry' : 'entries'}"
end
def chart_link(name)
"[Chart](#{BURNDOWN_CHART_URL}##{name})"
end
# Only bullet lines with a cop name count. Headers and blank lines are ignored.
current = File.readlines(input_path, chomp: true).each_with_object({}) do |line, hash|
next unless line.start_with?("- [")
name = line[/`(\S+)`/, 1]
hash[name] = line if name
end
warn "Read #{current.size} cops from #{input_path}"
todos = Dir.glob(".rubocop_todo/**/*.yml").each_with_object({}) do |path, hash|
next unless /^# Cop supports --auto-?correct/.match?(File.read(path))
name, config = YAML.safe_load_file(path).first
entries = (config && config["Exclude"]) || []
hash[name] = [path, entries.size]
end
lines = (current.keys | todos.keys).sort.filter_map do |name|
path, count = todos[name]
old_line = current[name]
if path
# Keep any note (for example an MR link) from the old line.
note = old_line&.[](/entr(?:y|ies)\)(.*?)\s*\[Chart\]/, 1).to_s
"- [#{count.zero? ? 'x' : ' '}] [`#{name}`](#{BLOB_URL}/#{sha}/#{path}) " \
"(#{entries_text(count)})#{note} #{chart_link(name)}"
elsif old_line
# The todo file is gone, so the cop is done. Keep the old link to its last version.
line = old_line.sub("- [ ]", "- [x]").sub(/\d+ entr(?:y|ies)/, entries_text(0))
line.include?("[Chart](") ? line : "#{line} #{chart_link(name)}"
end
end
File.write(output_path, "#{lines.join("\n")}\n")
warn "Wrote #{lines.size} cops to #{output_path}"
Edited by Vitali Tatarintev