Questions tagged [rubocop]

RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.

RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide.

Apart from reporting problems in your code, RuboCop can also automatically fix some of the problems for you.

More info on GitHub.

453 questions
0
votes
2 answers

Having issues installing ruby gems after latest OS X El Capitan update

After the latest update it appears a few of my gems have been affected and are either missing/changed. In particular the gem 'rubocop' is giving me issues as I use atom for a text editor and I have flags popping up. "Failed to spawn command…
JKW
  • 47
  • 6
0
votes
1 answer

rubocop string interpolation and size condition

Before I except these two methods I wanted to see if anyone in the community had a better idea to structure these and make the cops pass. The first one with to_s seems a bit crazy too. I was thinking of refactoring the other method but that would…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
1 answer

How to avoid cyclometic complexity caused by guard blocks?

I have the following function in one of my classes def intraday_time_series(opts) ### Guard block ### valid_resource = opts[:resource] && [:calories, :steps, :distance, :floors, :elevation].include?(opts[:resource]) valid_date = opts[:date] …
Ankit
  • 6,772
  • 11
  • 48
  • 84
0
votes
3 answers

rubocop app controller function validate param integer use of nil? predicate

I tried rewriting this function numerous ways to get around this error, however, I want to defer to other experts before I disable the cop around it. def numeric?(obj) obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true end This…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
1 answer

rubocop eval in rake task

Rubocop chokes on the following setup: desc 'Clear the db data of development records' task clear: :environment do msg('Clearing the development database and rebuilding the default values') 'job,company'.split(/, ?/).each do |model| #…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
2 answers

rubocop style model self needed but triggering warning

For some reason rubocop is choking on this code I have in my model to properly address accepts_nested_attributes_for to work like find or create. When I tried to remove the self calls it blows up. At this point I am deferring to experts before I…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
1 answer

Guard clause in Rails if

I am using Rubocop in my application and it suggests Use a guard clause instead of wrapping the code inside a conditional expression for this. Plz suggest a clean way to rewrite it. if (geolocation_points.exists? || geolocation_boxes.exists?) …
bhvd
  • 55
  • 1
  • 7
0
votes
2 answers

rails rubocop use && instead of and with render and return

I have been stuck on this issue for some time now, but keep skipping over it. If I follow the cop guidelines here and change this to && my routes break. They are connected to my routes via: # Override Error Codes match '/404', to:…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
1 answer

rubocop self.routes custom routes

Rubocop keeps choking on this line in my application.rb file, yet I need this to set my routes properly for custom error messages. # use my own routes for error codes config.exceptions_app = self.routes My Routes File: # Override Error Codes …
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
1 answer

In RuboCop, what's the difference between error and fatal severities?

What's the difference between the severities "error" and "fatal" in RuboCop? The documentation about severity says Each cop has a default severity level based on which department it belongs to. The level is warning for Lint and convention for all…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
0
votes
1 answer

Rubocop: Ignore all cops that are boilerplate from a new rails app

When I run rubocop in my app directory, I get a long list of cops that stem from the default boiler-plate rails app which I just generated. I don't want rubocop to look at these files since I'm not the author of the files and I don't want to mess…
mikeymurph77
  • 752
  • 1
  • 11
  • 28
0
votes
1 answer

Pronto-Rubocop on Gitlab is not working, wrong URL being called

I'm using: Gitlab 7.11.2 Rails 3.2 Pronto 0.4.2 pronto-rubocop 0.4.4 And I'm having trouble setting up the script to run Rubocop on git commits. I want to use Pronto so only the changes are checked. I am not using GitLab to host so I am not sure how…
ecoding5
  • 404
  • 6
  • 19
0
votes
1 answer

Ruby lint error what is the right way to write this with a guard clause

Trying to run a command, if success continue on, if failure raise error and send commands output to console. output = `#{command}` unless $CHILD_STATUS.success? raise "#{command} failed with:\n#{output}" end C: Use a guard clause instead of…
Bill Warner
  • 639
  • 6
  • 18
0
votes
1 answer

Rubocop RSpec Describes are failing

Actually i'm trying to fix that issues: Do not use multiple top level describes - try to nest them. The first argument to describe should be the class or module being tested. I have eight tests in that format: describe…
Sascha Manns
  • 2,331
  • 2
  • 14
  • 21
0
votes
1 answer

How to make rubocop output nothing when there are no warnings or offenses?

I'd like rubocop but have it create no output if there are no offenses. I've played with the documented command line options, and taken a quick peek a the config option and source code without seeing anything promising. The closest I've come is…
David Hempy
  • 5,373
  • 2
  • 40
  • 68