ruby - 如何正确设置 rubocop 大小写缩进

标签 ruby rubocop

如何让 rubo-cop 接受以下案例选择的正确内容:

variable = case some_other_variable
  when 'some value' then 'some result'
  when 'some other value' then 'some other result'
  when 'one more value'  then 'one more result'
end

我目前在我的 .rubocop.yml 中有这个:

CaseIndentation:
  EnforcedStyle: end
  IndentOneStep: true

但它一直这样出错:

C: Layout/CaseIndentation: Indent when one step more than end.
    when 'some value' then 'some result'

我做错了什么,我该如何解决?

最佳答案

它说

  • Indent when as deep as case
  • When assigning the result of a conditional expression to a variable, preserve the usual alignment of its branches

所以它可能以这种方式对 Rubocop 有效:

variable = case some_other_variable
           when 'some value' then 'some result'
           when 'some other value' then 'some other result'
           when 'one more value' then 'one more result'
           end

或者这样

variable =
  case some_other_variable
  when 'some value' then 'some result'
  when 'some other value' then 'some other result'
  when 'one more value' then 'one more result'
  end

关于ruby - 如何正确设置 rubocop 大小写缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48786060/

相关文章:

ruby - 为什么我不能用 yum 安装最新版本的 ruby​​?

ruby - 使用 Ruby On Rails 拍摄 html 页面的快照

ruby - 当我已经在使用 %r 时,为什么 rubocop 要求我放置//围绕正则表达式?

ruby-on-rails - 运行从另一个目录安装的 rubocop

ruby - 用于扫描 ruby​​ 代码文件以查找重复或相似代码块的工具

ruby - 探究 parent 的内部状态

ruby-on-rails - rails console - 在表格中显示事件记录结果

ruby - Rubocop:是否可以向 Metrics/AbcSize cop 添加排除项?

sublimetext - 在 Rubocop Sublime Linter 上设置配置文件