476 questions
0 votes
0 answers
52 views
Disable Rubocop in html.slim
I am using Ruby 3.3.1 and Rails 7.2. I have Rubocop and slim installed in my project. Right now, I have a .each in my html.slim but I am getting this error: Rails/FindEach: Use find_each instead of ...
2 votes
1 answer
103 views
Rubocop Assignment Branch Condition Size Error
I have a class Invoice that belongs to an Entity. In the entity, the current period, meaning the business year, is set. When creating a new invoice I want to have an invoice number that is an ...
0 votes
0 answers
25 views
Can I add a line-level regex pattern to Rubocop's AllowedPatterns, or mimic this behaviour somehow?
My goal is to allow the following single-line pattern without increasing cyclomatic complexity: somearray << somevalue if somecondition Ideally, I'd like to do this by adding something like '^\s*...
1 vote
1 answer
123 views
Is there a way to enforce explicit returns in Rubocop?
I'm looking for a way to make Rubocop linter for Ruby enforce explicit returns from function calls. This is a house rule I want to implement since it is easier for people coming from other languages. ...
1 vote
1 answer
223 views
How to enforce Ruby code to break long lines with multiple arguments into one argument per line
I'm currently using RuboCop in a Ruby on Rails project, and I have a question regarding code style enforcement for long lines with multiple arguments. We have set a line length maximum of 100 ...
0 votes
0 answers
41 views
ROR + While running server start command or rubocop command getting Ignoring because its extensions are not built
❯ rubocop or rails s Ignoring racc-1.6.0 because its extensions are not built. Try: gem pristine racc --version 1.6.0 Ignoring racc-1.6.0 because its extensions are not built. Try: gem pristine racc --...
2 votes
1 answer
833 views
Rubocop doesn't run and returns `Connection refused` instead
I can't run bundle exec rubocop -a because of the following error: /.asdf/installs/ruby/3.3.1/lib/ruby/gems/3.3.0/gems/rubocop-1.65.1/lib/rubocop/server/client_command/base.rb:28:in `initialize': ...
0 votes
1 answer
95 views
How to omit the outer braces around an implicit options hash in Rubocop?
Rubocop does not swear at code where a hash with parentheses is passed to the method parameter, for example: user.set({ name: 'John', age: 45, permissions: { read: true } }) I would like him to ...
0 votes
2 answers
130 views
How to configure Rubocop to skip counting log lines - Metrics/MethodLength AllowedPatterns/AllowedMethods
Running RuboCop results in the following error $ rubocop Running RuboCop... Offenses: C: Metrics/MethodLength: Method has too many lines. [25/10] (https://rubystyle.guide#short-methods) def ...
1 vote
1 answer
174 views
How to define a Ruby method in runtime so that Rubocop doesn't complain?
I'm doing this: class F def foo @x = Object.new def @x.bar(_t) true end end end Rubocop complains: a.rb:4:5: W: Lint/NestedMethodDefinition: Method definitions must not be ...
0 votes
1 answer
312 views
How to deal with `RuboCop::Cop::Rails::LexicallyScopedActionFilter ` when including a module?
I have a class similar to this: class UsersController < ApplicationController before_action :user_authentication, except: :create include Crud end Rubocop Rails complains, "create is ...
2 votes
0 answers
434 views
Rubocop rule for separated keyword arguments in ruby 3
I'm making a slowly upgrade on a huge rails app with rails 5 and ruby 2.7, to rails 7 and ruby 3. I want to add a rubocop rule that warns users of deprecated stuff in ruby 3 while still using ruby 2.7,...
0 votes
0 answers
203 views
How can I write a custom cop in Rubocop for dealing with one-line class definitions?
Is it possible to write a custom cop that would call out class definitions like this: MyError = Class.new(StandardError) And advise the author to format it like this? class MyError < StandardError;...
1 vote
1 answer
553 views
How can I warn about Ruby 3 deprecated code, while using Ruby 2.7 with Rubocop?
I'm working on a huge repo with many contributors, and many code changes happen daily. I'm tasked to update current Ruby 2.7.4 to Ruby 3+, and as a first step I have decided best to add some rules to ...
2 votes
0 answers
87 views
Rubocop Lint/UselessAssignment offense not detected
With Ruby3.3.0 (rbenv global) and rubocop 1.60.2, I noticed that sometime 'useless assignements' are not detected. Below is an example where offense is detected for foo, but not for bar. #!/usr/bin/...