【发布时间】:2017-06-04 08:59:03
【问题描述】:
我有一个像 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
那么基本上我怎么能让它不关心那个特定的实例呢?
【问题讨论】:
-
愚蠢的问题,但为什么不听从它的建议呢?
-
zero?方法会在预期为真时返回,我更喜欢== 0的明确性质。
标签: ruby-on-rails rubocop