禁用 Rubocop 关于方法的投诉
disable Rubocop complaint about method
我有一个像这样的方法 return if amount == 0
而 rubocop 抱怨它应该像 return if amount.zero?
。我怎样才能让它跳过那个方法?这是我的 .rubocop.yml:
rubocop
StringLiterals:
EnforcedStyle: double_quotes
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: false
Style/TrailingCommaInLiteral:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: false
Style/CaseEquality:
Enabled: false
Documentation:
Description: "Document classes and non-namespace modules."
Enabled: false
Metrics/MethodLength:
CountComments: false
Max: 15
Rails/Delegate:
Enabled: false
AllCops:
Exclude:
- db/**/*
- config/**/*
- script/**/*
- vendor/**/*
- bin/**/*
- Rakefile
- spec/spec_helper.rb
- spec/rails_helper.rb
- spec/teaspoon_env.rb
TargetRubyVersion: 2.3
Rails:
Enabled: true
submit_ticket_payment.rb
def call
return if amount == 0
Stripe::Charge.create(
amount: amount,
currency: "usd",
description: event_name,
receipt_email: context.rsvp.email,
source: context.token,
statement_descriptor: event_name
)
rescue Stripe::StripeError
context.fail!
end
所以基本上我怎么能让它不关心那个特定的实例?
如果您只想跳过此特定方法的规则,则:
# rubocop:disable Style/NumericPredicate
def call
return if amount == 0
# ...
end
# rubocop:enable Style/NumericPredicate
有问题的检查由 Style/NumericPredicate
警察执行。
如果您一般希望启用它但不抱怨个别事件,您可以通过特殊注释暂时禁用它:
# rubocop:disable Style/NumericPredicate
return if amount == 0
# rubocop:enable Style/NumericPredicate
注意需要重新启用;否则它将跳过对整个文件剩余部分的检查。
我有一个像这样的方法 return if amount == 0
而 rubocop 抱怨它应该像 return if amount.zero?
。我怎样才能让它跳过那个方法?这是我的 .rubocop.yml:
rubocop
StringLiterals:
EnforcedStyle: double_quotes
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: false
Style/TrailingCommaInLiteral:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: false
Style/CaseEquality:
Enabled: false
Documentation:
Description: "Document classes and non-namespace modules."
Enabled: false
Metrics/MethodLength:
CountComments: false
Max: 15
Rails/Delegate:
Enabled: false
AllCops:
Exclude:
- db/**/*
- config/**/*
- script/**/*
- vendor/**/*
- bin/**/*
- Rakefile
- spec/spec_helper.rb
- spec/rails_helper.rb
- spec/teaspoon_env.rb
TargetRubyVersion: 2.3
Rails:
Enabled: true
submit_ticket_payment.rb
def call
return if amount == 0
Stripe::Charge.create(
amount: amount,
currency: "usd",
description: event_name,
receipt_email: context.rsvp.email,
source: context.token,
statement_descriptor: event_name
)
rescue Stripe::StripeError
context.fail!
end
所以基本上我怎么能让它不关心那个特定的实例?
如果您只想跳过此特定方法的规则,则:
# rubocop:disable Style/NumericPredicate
def call
return if amount == 0
# ...
end
# rubocop:enable Style/NumericPredicate
有问题的检查由 Style/NumericPredicate
警察执行。
如果您一般希望启用它但不抱怨个别事件,您可以通过特殊注释暂时禁用它:
# rubocop:disable Style/NumericPredicate
return if amount == 0
# rubocop:enable Style/NumericPredicate
注意需要重新启用;否则它将跳过对整个文件剩余部分的检查。