Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何正确设置rubocop案例缩进_Ruby_Rubocop - Fatal编程技术网

Ruby 如何正确设置rubocop案例缩进

Ruby 如何正确设置rubocop案例缩进,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: Enforc

如何让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'
我做错了什么?我该如何修复它

  • 缩进深度与大小写一样深
  • 将条件表达式的结果赋给变量时, 保持其分支的常规对齐
因此,它可以通过以下方式对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

也许是这样,但我们希望它像在OP中显示的一样,我知道应该可以像这样设置:,我只是想知道如何使用当前版本的rubocop。那么你为什么不在问题中问这个问题?:'-)由于该问题始于2013年,且
indentwhenrelative
已重命名为
EnforcedStyle
,因此该选项很可能不再有效。正如@jonas054所指出的,我无法让它工作。