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
1 answer

Rubocop error: "Use attr_reader to define trivial reader methods."

I am having some struggle using rubocop and don't know how I could solve this problem. The code I have: class Test @hello = 'stackoverflow' def self.hello @hello end end p Test.hello It runs the way i want, but when I run rubocop it…
Domas Mar
  • 1,148
  • 1
  • 11
  • 23
0
votes
1 answer

Chef rvm cookbook - issues with accessing installed gems

I'm trying to use chef for the following (Centos VM): Install ruby 1.9.3 Create a gemset ('chef-test') that's available to anyone Install two gems (rubocop and foodcritic) on the 'chef-test' gemset I am using https://github.com/fnichol/chef-rvm…
georgthebub
  • 407
  • 6
  • 18
0
votes
1 answer

How to prevent rubocop to add a space after hash

Rubocop changes #!/usr/bin/ruby to # !/usr/bin/ruby adds a space after the hash when I use rubocop -a, how can I avoid this
Rpj
  • 5,348
  • 16
  • 62
  • 122
-1
votes
1 answer

GitHub Actions: rubocop errors out, but the code is not from my repo

When running the workflow in GitHub actions, rubocop errors out, but the code that it complains about is not present in my repo. How can I fix this? Error: Run bin/rubocop…
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
-1
votes
1 answer

Node Pattern Rubocop

Can't figure out how to match the node pattern for enum options. Code I want to match, enum that has prefix: true (or scoped: true for later versions): enum bla: { active: 0, not_active: 1 }, _prefix:true Will get node as: ruby-parse -e 'enum bla:…
user5639287
-1
votes
1 answer

robocop.yml won't ignore files for code checking

I installed gem 'rubocop', '~> 0.67.2' on my rails app and now I want to add some files to rubocom.yml/Exclude so that Rubocop don't track them. I put it in the root of my app rubocop.yml AllCops: Exclude: - 'db/**/*' - 'config/**/*' -…
synopsa
  • 75
  • 1
  • 8
-1
votes
1 answer

Configuration file not found: /path/to/rubocop.yml

I saved the file rubocop.vim in ~/.vim/plugin/, and when I run :Rubocop in Vim I get Configuration file not found: /path/to/rubocop.yml. I couldn't find the path to rubocop.yml. I am on MacOS Mojave. Thank you.
aerijman
  • 2,522
  • 1
  • 22
  • 32
-1
votes
2 answers

Lint/AmbiguousOperator: Ambiguous negative number operator

I am using rubocop gem. Following is my factorybot code. factory :cut, class: CutSetting do maximum_length 100 max_colors_cut_together -1 end Rubocop give the following errors for negative value…
Bablu Patel
  • 85
  • 1
  • 8
-1
votes
3 answers

Rubocop claims for too many 'if' statements

I am measuring my code for a Rails app using Rubocop. This is my code: def ratings_treatment if @rating.advertise_id advertise = Advertise.find(advertise_id) rating_average(advertise) elsif @rating.product_id product =…
Paliao
  • 71
  • 3
  • 11
-1
votes
1 answer

How to refactor case..when in Ruby

def readable uptime = (Time.now - self).to_i case uptime when 0 then 'just now' when 1 then 'uptime second ago' when 2..59 then uptime.to_s + ' seconds ago' when 60..119 then 'uptime minute ago' # 120 = 2 minutes when…
-1
votes
1 answer

How to use excludes for a specific rule in rubocop.yml

Metrics/BlockLength: Excludes: - '/app/**' I have this .rubocop.yml, I am expecting rubocop to not to complain only for whatever files under app regarding the block length. But it still complains, is there something I am missing?
gates
  • 4,465
  • 7
  • 32
  • 60
-1
votes
2 answers

Remove eval from method using dynamic variables in Ruby

The following method is passed a :symbol which correlates to both a method name and an instance variable set via attr_accessor :symbol. The only way I have been able to make this work is via eval. Is there a way around this? def…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
-1
votes
1 answer

Value is not an accepted value. Valid values: ["rubocop"] (737, 20)

I install Ruby and ruby-rubocop extension in my Visual Studio Code, but this warning is showing in my editor: Value is not an accepted value. Valid values: ["rubocop"] (737, 20) When I click in warning redirect to settings.json (/), specifically…
Luiz Carvalho
  • 1,549
  • 1
  • 23
  • 46
-1
votes
1 answer

Ruby method refactor multi line assignment to pass RuboCop

I have been trying to tune this method that sets up complex assignment and I am looking for other options to make this function pass the cops. Would anyone have thoughts to point me in the right direction? Right now, I am tinkering with breaking…
Chris Hough
  • 3,389
  • 3
  • 41
  • 80
-2
votes
1 answer

How to get the cyclomatic complexity of a ruby function?

I am looking for a function or gem that gives me the cyclomatic complexity of a function. For example, using rubocop, If I write def my_func(foo) foo.details['errors'].each do |attr, message| case attr when 1 then foo.errors.add(:err1,…
1 2 3
30
31