RSpec&;rubocp/Ruby风格指南

RSpec&;rubocp/Ruby风格指南,rspec,rubocop,Rspec,Rubocop,当告诉RailsScaffold控制器生成rspec测试时,生成的文件不遵循,因此会在这些测试上抛出错误 只有几个“警察”失败了。Style/HashSyntax、Style/StringLiterals、Style/MethodCall括号、Style/SpaceInsidehHashLiteralBrages、Style/Blocks 我理解其中一些COP只是样式首选项,比如样式/字符串文本(当您不需要字符串插值或特殊符号时,更喜欢单引号字符串) 尽管如此,我还是希望我的测试符合ruboco

当告诉RailsScaffold控制器生成rspec测试时,生成的文件不遵循,因此会在这些测试上抛出错误

只有几个“警察”失败了。Style/HashSyntax、Style/StringLiterals、Style/MethodCall括号、Style/SpaceInsidehHashLiteralBrages、Style/Blocks

我理解其中一些COP只是样式首选项,比如样式/字符串文本(当您不需要字符串插值或特殊符号时,更喜欢单引号字符串)

尽管如此,我还是希望我的测试符合rubocop。有人知道有一个gem用符合Ruby风格指南/rubocops的模板替换rspecrails模板(例如)吗?或者任何未记录(或记录)的rspec/rspec rails特性解决了我的问题

一个工作区正在运行

bundle exec rubocop spec --auto-correct
在生成新的测试文件之后,但我更愿意省略该步骤


非常感谢您的帮助和指点

我建议向RSpec发出请求,更改他们的模板以符合Rubocop。

我只是让Rubocop自动更正类似的内容。我通常有一个script
script/rubocop autocorrect.rb
或者一些我明确列出所有应该纠正的COP的东西。我从来没有因为它而犯过错误;只有一例rubocop未能纠正某些错误(在一个非常奇怪的案例中,与用
|
替换
有关)。它什么也没做,也没破译密码

完整的脚本看起来是这样的(没有什么特别的,只是我的首选项):


你能分享剧本吗?:-)当然,享受吧@塞克莫
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