Rubocop is saying that the line require 'rails_helper' cannot resolve the path.
I am using Rubocop via Solargraph called by lsm-mode which is inside a Docker container working on a Ruby on Rails project using Rspec. The Emacs process is running on the local laptop and activating Solargraph using lsm-docker.
The docker compose has three containers, a db container with Postgres, a web container running Rails, and another container for the Solargraph process. The Solargraph container and the web container are starting from the same image that I'm building. The build process includes two steps to populate Solargraph:
( grep -s solargraph /hatred/Gemfile > /dev/null && /root/bin/solargraph download-core && /root/bin/solargraph bundle )
I'm using the solargraph executable that is in Bundler's bin directory.
I'm new to Rubocop, Solargraph, and lsm-mode.
In my spec file that was auto generated using rails g scaffold ... I have a require 'rails_helper'. Doing rspec path/to/spec works in that it finds rails_helper (which is in the spec directory. But rubocop isn't finding it.
My .rubocop.yml file is pretty simple:
require:
- rubocop-rails
- rubocop-rspec
AllCops:
NewCops: enable
Include:
- '**/*.rb'
- '**/*.rake'
I added the Include as part of my debugging process but it didn't change anything. I had errors that the Rails and RSpec cops were not enabled so I added the NewCops: enable line and that solved the issue which indicates that Rubocop is finding my config file. print -l **/rails_helper* gives spec/rails_helper.rb.
rubocop spec/views/import_files/new.html.erb_spec.rb does not complain about the required file. pwdx 1 from within the Solargraph container says that it's current working directory is the app's directory.
My best guess is this is a Rubocop issue so I put the question here rather than in the emacs stack exchange.
Edit: require 'spec/rails_helper' still has the problem but require '/app/spec/rails_helper' removes the warning. It is as if I need to set the load_path of whatever process is generating the warning.
I've been experiencing this same issue, and I believe it is originating from Solargraph, not RuboCop, via the require_not_found reporter:
require_not_foundhighlights require calls where Solargraph could not resolve a required path. Note that this error does not necessarily mean that the path is incorrect; only that Solargraph was unable to recognize it.
For me, running yard gems in the project directory resolved other "Required path * could not be resolved" diagnostics, but not the ones flagging require "rails_helper" in the "/spec" directory.
This appears to be a bug in Solargraph that has not yet been fixed. For now, the only way to silence the warning appears to be to create or update your .solargraph.yml config file and remove require_not_found (as it is part of the default configuration):
reporters:
- rubocop
- require_not_found
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With