Open dogweather opened 5 years ago
Would an option similar to Ruby's -I
CLI option be enough to fix this?
Rubocop has nice solutions for this. E.g., one can exclude certain files from a certain check. I use this to tailor the checks for specs, eliminating the false positives:
Metrics/BlockLength:
Exclude:
- spec/**/*
That's one possibility. In .solargraph.yml, I imagine it would look something like this:
reporters:
- require_not_found:
exclude:
- spec/**/*
Another option is allowing .solargraph.yml files in subdirectories. Right now, Solargraph only checks the project root, but the ability to apply a different configuration to the spec
folder could be helpful. (I'm already looking at this feature for other reasons.)
Hey @castwide did you ever follow-up on this?
This issue still persists. Anyone willing to look up to this issue?
I'm glad I finally found this issue. I'm going to guess / hope that this is what I'm seeing.
In my rspec files, there is a require 'rails_helper'
line which someone is flagging with a Warning of "Required path rails_helper could not be resolved.". I say someone because I have quite a complicated set up with Emacs, lsm-mode, Solargraph along with docker containers. I could't tell if it was Rubocop, Solargraph, Flymake, etc.
Rubocop, when run alone on the command line doesn't complain. And I'm new to lsm-mode, Solargraph, Rubocop, etc so it has taken me a while to finally find this.
Being new, I have more questions than answers:
It seems like the equivalent of load_path
is what is needed.
@castwide It appears that you or someone implemented the pattern in this post at some point and didn't close / reference this issue. We tried it and it worked, but I couldn't find any indication in docs that this was the case. If at all possible, this would also be great to see on the configuration docs to help people looking to fix the warnings in specs.
@TikiTDO Are you sure that it worked? I'm using version 0.50.0 and if I add that snippet to my .solargraph.yml file it causes solargraph to crash with an error: undefined method split
for require_not_found.
All that snippet does is prevent it from running a check on the spec files. There's really not much to not work.
Try to find what it's splitting, maybe you left something blank.
On Mon, Jan 15, 2024, 2:40 AM Jeff Bigler @.***> wrote:
@TikiTDO https://github.com/TikiTDO Are you sure that it worked? I'm using version 0.50.0 and if I add that snippet to my .solargraph.yml file it causes solargraph to crash with an error: undefined method split for require_not_found.
— Reply to this email directly, view it on GitHub https://github.com/castwide/vscode-solargraph/issues/94#issuecomment-1891480287, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACPUKE62QBS6TNPDF5MGK3YOTMNBAVCNFSM4GMREFWKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBZGE2DQMBSHA3Q . You are receiving this because you were mentioned.Message ID: @.***>
I was seeing the same error as @jbigler when trying to get require_not_found
to correctly run against my rails spec files.
The aforementioned adjustment to the .solargraph.yml config did not work for me (running solargraph v0.50.0, ruby 3.1.4).
What I've ended up doing instead is using require_relative
instead of require, like in the following example:
# spec/models/some_model_spec.rb
# instead of `require "rails_helper"`, the following seems to work:
require_relative "../rails_helper"
Rspec.describe "my model" do
# ...etc
end
I don't love it as I imagine nested/namespaced spec directories will be an ugly nuisance to maintain... but at least this way the specs do run and the require_not_found check does pass.
I get an error whenever I open an rspec file, "Required path spec_helper could not be resolved." I'm wondering if it's because the
spec/
directory is not on the library search path? One workaround would be to add it, but I can't find a Solargraph option for that.NB: I tried to exclude my RSpec files from checks, but that has no effect for me. Reported here: #93