我只是让 rubocop 自动更正这样的东西。我通常有一个脚本script/rubocop-autocorrect.rb
或其他东西,我明确列出所有应该纠正的警察。我从来没有遇到过它引入的错误;只有一种情况是 rubocop 未能纠正某些问题(在一个非常奇怪的情况下与替换有关or
)||
。它只是什么也没做,它没有破坏代码。
完整的脚本看起来像这样(没什么特别的,只是我的喜好):
bundle exec rubocop -F -a --only \
Style/TrailingBlankLines,\
Style/TrailingWhitespace,\
Style/SymbolProc,\
Style/SpaceInsideHashLiteralBraces,\
Style/SpaceInsideBrackets,\
Style/SpaceInsideBlockBraces,\
Style/SpaceInsideParens,\
Style/SpaceAroundEqualsInParameterDefault,\
Style/Semicolon,\
Style/StringLiterals,\
Style/SpaceAfterComma,\
Style/SpaceAroundOperators,\
Style/AlignHash,\
Style/AlignParameters,\
Style/AndOr,\
Style/EmptyLines,\
Style/HashSyntax,\
Style/RedundantSelf,\
Style/ColonMethodCall,\
Style/IndentationWidth,\
Style/MultilineIfThen,\
Style/NegatedIf,\
Style/PercentLiteralDelimiters,\
Style/BarePercentLiterals,\
Style/BlockEndNewline,\
Style/CollectionMethods,\
Style/CommentIndentation,\
Style/IndentationConsistency,\
Style/ParenthesesAroundCondition,\
Style/CaseIndentation,\
Lint/EndAlignment,\
Style/LeadingCommentSpace,\
Style/MutableConstant,\
Style/NumericLiteralPrefix,\
Style/MultilineIfModifier,\
Style/TrailingCommaInLiteral,\
Style/IndentArray,\
Style/AlignArray,\
Style/MultilineArrayBraceLayout,\
Style/ElseAlignment,\
Lint/EndAlignment,\
Style/MultilineMethodCallBraceLayout,\
Style/ClosingParenthesisIndentation,\
Style/MultilineHashBraceLayout,\
Lint/BlockAlignment,\
Style/IndentHash,\
Style/LeadingCommentSpace,\
Style/SpaceBeforeComma,\
Style/SpaceBeforeSemicolon,\
Style/Tab,\
Style/MultilineMethodCallIndentation