首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rubocop JSON:如果方法调用的参数跨越多行,则它们对齐

Rubocop JSON:如果方法调用的参数跨越多行,则它们对齐
EN

Stack Overflow用户
提问于 2016-09-16 11:25:46
回答 1查看 7.3K关注 0票数 2

我在我的测试文件里遇到了鲁博克的问题。首先,这是我现在的代码:

代码语言:javascript
复制
should 'should show user' do
  get user_url(@user),
    headers: @header
  assert_response :success
end

should 'should update user' do
  patch user_url(@user),
    params: {
      data: {
        attributes: {
          name: @user.name
        }
      }
    }, headers: @header
  assert_response :success
end

这就是Rubocop错误输出:

代码语言:javascript
复制
test/controllers/users_controller_test.rb:34:9: C: Align the parameters of a method call if they span more than one line.
        headers: @header
        ^^^^^^^^^^^^^^^^
test/controllers/users_controller_test.rb:40:9: C: Align the parameters of a method call if they span more than one line.
        params: { ...
        ^^^^^^^^^

因此,我在样式指南中搜索JSON的正确对齐方式。我真的尝试了缩进和新行的每一个组合,但是Rubocop每次都抛出同样的错误。顺便提一下,把整个JSON放在一行也不是解决方案。有人能解释一下,正确的排列方式是什么样子,所以鲁博克对此很满意吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-16 11:27:10

把它改成

代码语言:javascript
复制
should 'should show user' do
  get user_url(@user),
      headers: @header
  assert_response :success
end

should 'should update user' do
  patch user_url(@user),
        params: {
          data: {
            attributes: {
              name: @user.name
            }
          }
        },
        headers: @header
  assert_response :success
end

解释:

由于user_url(@user)是您获得第二个param的第一个param,所以headers: @header应该与它对齐。

同样的情况也适用于第二名,你有三个配对。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39530324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档