Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

529
Views
Rubocop, how to Disable/Enable cops on blocks of code

I will like to disable a cop for a specific block or method.

I know it is possible to disable a cop for the whole project using .rubocop.yml but I just want to deactivate the cop temporarily for a specific portion of the code

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I answer my question because it is always very difficult for me to find the reference to this solution:

# rubocop:disable Metrics/MethodLength
def my_code
  ..
end
# rubocop:enable Metrics/MethodLength

Same for multiple cops:

# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def my_code
  ..
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

Documentation: https://docs.rubocop.org/rubocop/configuration.html#disabling-cops-within-source-code

over 4 years ago · Santiago Trujillo Report

0

If you want to disable the cop for a particular line, you can just use something like this

 before_action :authenticate_user!, except: [:index, :show] # rubocop:disable Style/SymbolArray

No need to enable it again. If there is a block of code and you want to enable or disable the cop, then as suggested above, you can follow that approach.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!