简体   繁体   English

防暴警察。 如果散列文字的元素跨越多行,则对齐它们

[英]Rubocop. Align the elements of a hash literal if they span more than one line

I have some code我有一些代码

# 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 says: Align the elements of a hash literal if they span more than one line. Rubocop 说:如果散列文字的元素跨越多行,则对齐它们。

collection: proc do
^^^^^^^^^^^^^^^^

What can I do with it?我可以用它做什么?

I align :s and wrap the sections in我对齐 :s 并将这些部分包裹起来

# rubocop:disable AlignHash
# rubocop:enable AlignHash

(cf https://github.com/bbatsov/rubocop#disabling-cops-within-source-code ) (参见https://github.com/bbatsov/rubocop#disabling-cops-within-source-code

With your 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

In your .rubocop.yml , add:在您的.rubocop.yml ,添加:

Style/AlignHash:
  Enabled: false

You can also disable it in your .rubocop.yml configuration :您还可以在.rubocop.yml配置中禁用它:

Style/Encoding:
  Enabled: false

In RubyMine or IntelliJ, If you follow the solution suggested by the IDE, that fixes it.在 RubyMine 或 IntelliJ 中,如果您遵循 IDE 建议的解决方案,则可以修复它。 Basically the IDE aligns the code for you. IDE 基本上会为您调整代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM