我有一个像这样的方法,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
所以基本上我怎么能不关心那个特定的实例呢?
有问题的检查是由Style/NumericPredicate
警察实施的.
如果您通常希望启用它但不抱怨个别出现,您可以使用特殊注释暂时禁用它:
# rubocop:disable Style/NumericPredicate return if amount == 0 # rubocop:enable Style/NumericPredicate
请注意,它需要再次启用; 否则它将跳过检查文件的整个剩余部分.