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
0 answers

rubocop gem install gives ERROR: Failed to build native gem extension

I recently installed Ruby from http://railsinstaller.org/en. This included Ruby on Rails and the Ruby dev-kit. Now I am trying to install rubocop, but it isn't working: C:\Windows\System32>gem install rubocop Temporarily enhancing PATH to include…
Richard
  • 494
  • 7
  • 18
0
votes
2 answers

how to properly rescue this statement in ruby?

I have a chef resource and I just added linting with cookstyle to the cookbook. I have this line in the cookbook: existing_value = key.to_s.split('.').inject(node.elasticsearch) { |result, attr| result[attr] } rescue nil if existing_value.nil? It's…
numb3rs1x
  • 4,673
  • 5
  • 31
  • 44
0
votes
2 answers

How to fix "line is too long" error given by lint command

My lint program says this line is too long: @abc = @def.model_name.where(id: @ghi.id).sum(:jkl) unless @ghi.blank? How can I fix it?
User7354632781
  • 2,174
  • 9
  • 31
  • 54
0
votes
1 answer

Ruby Rubocop. MutableConstant - not detecting freeze

I wrote a lib/animal.rb with several lists of params, and I want to reference that list in my controller and add it my params list. I did this because I use this list in several locations and didn't want to litter my code with a bunch of references…
alex_milhouse
  • 891
  • 1
  • 13
  • 31
0
votes
1 answer

How to resoved issue check style in rubocop?

I have a search function with multiple conditions and multiple panels connected together as below hospitals = Hospital.order(created_at: :desc).group(:id) hospitals = hospitals.joins(medical_subjects: :sicks).where("(medical_subjects.name LIKE ? OR…
kientn
  • 1
  • 1
0
votes
0 answers

rubocop not executing from nfs folder

I have a rails project that I run inside a vm and mount the project directory through nfs. I also have a copy of the project checked out locally. If I run rubocop on the local version of the project, everything works correctly. However if I run…
Chris Drappier
  • 5,280
  • 10
  • 40
  • 64
0
votes
1 answer

Custom RuboCop to search for configurable URLs?

I'm writing a custom RuboCop plugin to enforce specific URLs in a Berksfile. I might have taken on more than my limited Ruby knowledge will support at this time. Here is some pseduo code. Am I even…
skohrs
  • 689
  • 2
  • 6
  • 19
0
votes
1 answer

How to configure Atom linter-rubocop to run --rails flag always

I'm getting conflicting cops between my IDE and the console. How do I have Atom's linter-rubocop to always run with the --rails flag? Error in Atom: Error in console: This is my config.cson: ... "linter-rubocop": command: "rubocop -R"
binarymason
  • 1,351
  • 1
  • 14
  • 31
0
votes
1 answer

Ruby Style Guide and logging of messages

I'm developing an application where a lot of errors could occur. So I - and the administrators who shall use this application - have a lot of interest in logging all relevant information. But I'm struggling with ruby style guides. I love the rubocop…
PascalTurbo
  • 2,189
  • 3
  • 24
  • 41
0
votes
2 answers

fix Line is too long error in a ruby file

how to fix Line is too long error in a ruby file without ignoring it and not introducing new errors. I have tried giving the extra character in the next line using IDE. It is introducing new errors like 'Ternary operators must not be nested. Prefer…
0
votes
2 answers

How do you configure Rubocop to display rule when running

It seems like, instead of the SUPER helpful Offense/Concern/Warning sytax like: C: Use delete instead of gsub. It could display: C: Use delete instead of gsub. Cop name: [Whatever it's upset about] So you could disable the thing without another…
Ben Wiseley
  • 537
  • 6
  • 14
0
votes
2 answers

How can I validate a date string without rescuing the exception to keep the Rubocop HandleExceptions linter happy?

I have a string which might or might not be a valid date. I want a clean and simple way to validate whilst keeping Rubocop happy. # TODO: Welcome suggestions for a better way to deal with this... # rubocop:disable HandleExceptions def…
ktec
  • 2,453
  • 3
  • 26
  • 32
0
votes
1 answer

Rails 4 api default limit params do not pass cops

This seems a bit crazy here. Is there another way to write this function to get the cops to pass on it, or should I just make it exempt? Code def set_default_limit params[:limit] = params[:limit].to_i > 0 ? params[:limit] :…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
0
votes
0 answers

Atom editor : linter-rubocop plugin configuration error

Following guidelines according to Atom. I have installed gem rubocop and the linter-rubocop plugin successfully and now I am trying to configure it into Atom editor, but I am facing this error I have followed these steps on my…
Dharmesh Rupani
  • 1,029
  • 2
  • 12
  • 22
0
votes
2 answers

Ruby: Skip element in loop if an exception is raised

I have the following method: def fetch_something @fetch_something ||= array_of_names.inject({}) do |results, name| begin results[name] = fetch_value!(name) rescue NoMethodError, RuntimeError next end results …
Severin
  • 8,508
  • 14
  • 68
  • 117