gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 08:57:17 25 4
gpt4 key购买 nike

如何让 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com