ruby-on-rails – 禁用Rubocop对方法的抱怨
发布时间:2020-12-17 03:57:12 所属栏目:百科 来源:网络整理
导读:如果amount == 0并且rubocop抱怨它应该像amount.zero?那样返回,我有一个像这样返回的方法.我怎么能跳过这个方法呢?这是我的.rubocop.yml: rubocop StringLiterals: EnforcedStyle: double_quotes Enabled: trueStyle/FrozenStringLiteralComment: Enabled
如果amount == 0并且rubocop抱怨它应该像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 请注意,它需要再次启用;否则它将跳过检查文件的整个剩余部分. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |