Skip to content

Instantly share code, notes, and snippets.

@wojtha
Last active January 10, 2019 10:37
Show Gist options
  • Save wojtha/f97f45a6a09f14a58e5721fb178f2d3f to your computer and use it in GitHub Desktop.
Save wojtha/f97f45a6a09f14a58e5721fb178f2d3f to your computer and use it in GitHub Desktop.
Ruby script to migrate Rubocop settings from Style to Layout
# Fixes complains such as:
# .rubocop.yml: Style/IndentationConsistency has the wrong namespace - should be Layout
# .rubocop.yml: Style/IndentationWidth has the wrong namespace - should be Layout
# .rubocop.yml: Style/DotPosition has the wrong namespace - should be Layout
layouts = %w[
AccessModifierIndentation
AlignArray
AlignHash
AlignParameters
ClosingParenthesisIndentation
CommentIndentation
DotPosition
EmptyLineBetweenDefs
EmptyLinesAroundBlockBody
EmptyLinesAroundClassBody
EmptyLinesAroundModuleBody
ExtraSpacing
FirstParameterIndentation
IndentArray
IndentationConsistency
IndentationWidth
IndentHash
LeadingCommentSpace
MultilineMethodCallIndentation
MultilineOperationIndentation
SpaceAfterComma
SpaceAroundEqualsInParameterDefault
SpaceAroundOperators
SpaceBeforeBlockBraces
SpaceBeforeComma
SpaceInsideBlockBraces
SpaceInsideBrackets
SpaceInsideHashLiteralBraces
SpaceInsideParens
SpaceInsideStringInterpolation
TrailingBlankLines
]
path = '.rubocop.yml'
legacy_content = File.read(path)
new_content = legacy_content.gsub(/Style\/(#{ layouts.join('|') })/, 'Layout/\1')
File.write(path, new_content)
@thb
Copy link

thb commented Feb 8, 2018

had to add CaseIndentation as well

@Korayem
Copy link

Korayem commented Jan 10, 2019

Forked with further missing replacement keys
https://gist.github.com/Korayem/86060ae7642fa246e657380a39e34bdb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment