castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
423 stars 25 forks source link

require_not_found cannot find spec_helper #94

Open dogweather opened 5 years ago

dogweather commented 5 years ago

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

dogweather commented 5 years ago

Would an option similar to Ruby's -I CLI option be enough to fix this?

dogweather commented 5 years ago

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/**/*

https://medium.freecodecamp.org/rubocop-enable-disable-and-configure-linter-checks-for-your-ruby-code-475fbf11046a

castwide commented 5 years ago

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.)

CharlieIGG commented 3 years ago

Hey @castwide did you ever follow-up on this?

ghost commented 2 years ago

This issue still persists. Anyone willing to look up to this issue?

pedz commented 1 year ago

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:

  1. Who is actually reporting the error? I guess it is Solargraph or is it Rubocop when invoked via Solargraph?
  2. Can I tag the line perhaps with a magic comment to tell whoever to ignore this error? I think I'd rather have that than a global ignore.

It seems like the equivalent of load_path is what is needed.

TikiTDO commented 11 months ago

@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.

jbigler commented 8 months ago

@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.

TikiTDO commented 8 months ago

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: @.***>

mbostler commented 3 months ago

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.