[英]Rubocop. Align the elements of a hash literal if they span more than one line
[英]Rubocop JSON: Align the parameters of a method call if they span more than one line
我在測試文件中遇到了Rubocop的問題。 首先,這是我的代碼:
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錯誤輸出:
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每次都拋出相同的錯誤。 順便說一句,Andy將整個JSON放在一行中也不是解決方案。 任何人都可以解釋一下正確的對齊方式如何,從而使Rubocop滿意嗎?
更改為
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)
是獲取第二個參數headers: @header
第一個參數headers: @header
應該與其對齊
同樣適用於擁有三個參數的第二名
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.