如何正确设置rubocop case缩进

时间:2018-02-14 11:26:28

标签: 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'

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

1 个答案:

答案 0 :(得分:2)

它说

  
      
  • 在与案例一样深的时候缩进
  •   
  • 将条件表达式的结果赋给变量时,   保持其分支的通常对齐
  •   

所以它可能对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