Disabling and re-enabling a rubocop rule for a specific set of code

Public, Testing / TDD

harrylevine

Created: Nov 07, 2017     Updated: Nov 07, 2017


For example, if this rule is in your .rubocop.yml file:

Style/RedundantSelf:
  Description: Don't use self where it's not needed.
  StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-self-unless-required
  Enabled: true

You can disable it for a specific set of code like this:

# rubocop:disable Style/RedundantSelf
def self.currently_own(home)
  self
    .joins(home_people: :home)
    .merge(CoreModels::HomePerson.current)
    .where(homes: { id: home.id })
end
# rubocop:enable Style/RedundantSelf

https://stackoverflow.com/questions/37228624/rubocop-line-is-too-long-how-to-ignore