2017-01-19 4 views
1

나는이 return if amount == 0과 같은 방법을 가지고 있으며 rubocop은 return if amount.zero?과 같아야한다고 불평하고 있습니다. 어떻게 그 방법을 건너 뛰어도 되겠습니까?방법에 대한 Rubocop 불만 사용 안함

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.yml은?

+0

어리석은 질문이지만 그 제안을 따르지 않는 이유는 무엇입니까? – sevenseacat

+0

'zero?'메소드는 기대가 사실이라면 반환 할 것이고, 나는'== 0'의 명시적인 성격을 더 좋아한다. – Bitwise

답변

4

문제의 검사는 Style/NumericPredicate 경찰에 의해 구현됩니다.

당신은 일반적으로는 가능하지만 개별 선두로부터 불평, 일시적 특별한 코멘트와 함께 그것을 해제 할 수 있습니다 싶은 경우 다시 활성화 할 필요가 있음을

# rubocop:disable Style/NumericPredicate 
return if amount == 0 
# rubocop:enable Style/NumericPredicate 

참고; 그렇지 않으면 파일의 전체 나머지에 대한 검사를 건너 뜁니다.

1

만 다음이 특정 방법에 대한 규칙을 생략하고자하는 경우 :

# rubocop:disable Style/NumericPredicate 
def call 
    return if amount == 0 
    # ... 
end 
# rubocop:enable Style/NumericPredicate