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
161
votes
5 answers

Rubocop line length: How to ignore lines with comments?

I would like Rubocop to ignore lines with comments (just a comment or some code with an end of line comment) when checking if a line is too long. Is there a way to do this?
Twiek
  • 2,013
  • 2
  • 14
  • 14
155
votes
1 answer

What is meant by 'Assignment Branch Condition Size too high' and how to fix it?

In my Rails app, I use Rubocop to check for problems. Today it gave me an error like this : Assignment Branch Condition size for show is too high. Here's my code : def show @category = Category.friendly.find(params[:id]) @categories =…
THpubs
  • 7,804
  • 16
  • 68
  • 143
116
votes
6 answers

How to tell Rubocop to ignore a specific directory or file

My project is extending open-source classes from a third-party gem that we don't want to hold to the same coding standards as our own code. Refactoring the gem code isn't a viable option. We just want Rubocop to ignore the copied code. How can I…
emery
  • 8,603
  • 10
  • 44
  • 51
93
votes
4 answers

RuboCop: Line is too long ← How to Ignore?

I just added RuboCop to a rails project and installed the Sublime package to see RuboCop suggestions in the editor. I'm trying to figure out how to change the maximum line length from 80 characters, or just ignore the rule completely. Currently in…
Abram
  • 39,950
  • 26
  • 134
  • 184
85
votes
2 answers

Rubocop 25 line block size and RSpec tests

A typical RSpec unit test makes extensive use of nested Ruby blocks in order to structure the code and make use of DSL "magic" to have specs read like BDD statements: describe Foo do context "with a bar" do before :each do subject {…
Neil Slater
  • 26,512
  • 6
  • 76
  • 94
49
votes
3 answers

Why does RuboCop suggest replacing .times.map with Array.new?

RuboCop suggests: Use Array.new with a block instead of .times.map. In the docs for the cop: This cop checks for .times.map calls. In most cases such calls can be replaced with an explicit array creation. Examples: # bad 9.times.map do |i| …
shirakia
  • 2,369
  • 1
  • 22
  • 33
45
votes
3 answers

Top-level class documentation

Rubycop outputs messages like: app/controllers/welcome_controller.rb:1:1: C: Missing top-level class documentation comment. class WelcomeController < ApplicationController ^^^^^ I wonder what does top-level class documentation look like. It's not…
DreamWalker
  • 1,327
  • 1
  • 11
  • 19
39
votes
4 answers

Disable frozen string literal comment checking

I'm newbie in Rails. I am using 'Rubocop' for checking standards, however I'm bothered with the way it checks the 'frozen string literal'. It keeps on saying on my files: Missing frozen string literal comment. Is there a way to disable the…
mpalencia
  • 5,481
  • 4
  • 45
  • 59
37
votes
2 answers

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
fguillen
  • 36,125
  • 23
  • 149
  • 210
35
votes
6 answers

How to integrate rubocop with Rake?

rubocop is a code style checker for Ruby. A similar tool to rubocop, Cane, can be integrated with Rake. I prefer rubocop to Cane since rubocop makes checks based on the Ruby Style Guide and it seems to spot more problems. To automate the process of…
N.N.
  • 8,336
  • 12
  • 54
  • 94
34
votes
5 answers

Rails: rubocop disable Class has too many lines error

I have a class with constants, many constants. And rubocop is complaining about the length of this Class, which I don't care how long it gets. I want to disable rubocop's error: "Class has too many lines" but the following is not working: #…
fedest
  • 1,190
  • 3
  • 15
  • 35
33
votes
6 answers

rubocop on VScode not working.Error "rubocop is not executable"

Recently I installed rubocop on vscode. However, it doesn't work.Error message is below. rubocop is not excutable execute path is empty! please check ruby.rubocop.executePath How should I fix it? I searched some articles, never solved... cf.…
ShogoTGM
  • 468
  • 1
  • 4
  • 10
33
votes
2 answers

How to silence Rubocop warning on Assignment Branch Condition?

I would like to silence a specific Rubocop warning: Assignment Branch Condition size for plot_defaults is too high. [21.05/15] What is the appropriate syntax to do this in the code on a comment line like: # rubocop: disable
maasha
  • 1,926
  • 3
  • 25
  • 45
29
votes
8 answers

vscode( vscode-ruby + rubocop ) how to auto correct on save?

Environments vscode Version 1.19.1 (1.19.1) rubocop (0.52.1) Darwin mbp 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct 4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64 ruby 2.3.5p376 (2017-09-14 revision 59905)…
kukrt
  • 2,117
  • 3
  • 21
  • 32
29
votes
1 answer

How to pass &:key as an argument to map instead of a block with ruby?

I wrote this code: my.objects.map { |object| object.key } My rubocop said: Pass &:key as an argument to map instead of a block. Is there a short way to do the same thing?
s-cho-m
  • 967
  • 2
  • 13
  • 28
1
2 3
30 31