我有一些代码
# Filters
filter :name
filter :email
filter :organization_status, label: 'Status'
filter :subscriptions_subscription_status_id,
as: :select,
label: 'Subscription Status',
collection: proc do
Organization
.includes(subscriptions: [:subscription_status])
.map(&:subscriptions)
.flatten
.map(&:subscription_status)
.uniq
end
Rubocop 说:如果哈希文本的元素跨越多行,请对齐它们。
collection: proc do
^^^^^^^^^^^^^^^^
我能用它做什么?
我对齐:s并将部分包装在
# rubocop:disable AlignHash
# rubocop:enable AlignHash
(参看 https://github.com/bbatsov/rubocop#disabling-cops-within-source-code)
使用您的代码:
# Filters
filter :name
filter :email
filter :organization_status, label: 'Status'
# rubocop:disable AlignHash
filter :subscriptions_subscription_status_id,
as: :select,
label: 'Subscription Status',
collection: proc do
Organization
.includes(subscriptions: [:subscription_status])
.map(&:subscriptions)
.flatten
.map(&:subscription_status)
.uniq
end
# rubocop:enable AlignHash
在你的.rubocop.yml
中,添加:
Style/AlignHash:
Enabled: false
您也可以
在.rubocop.yml
配置中禁用它:
Style/Encoding:
Enabled: false
在 RubyMine 或 IntelliJ 中,如果您遵循 IDE 建议的解决方案,则可以修复它。基本上,IDE 会为您对齐代码。