Fixed path matching with reek config #23
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Awhile back, I fixed reek to be able to know the filename being examined, even if it wasn't passed a File object: troessner/reek#1343
When the reek config file has different configuration for different files/directories, this allows reek to match the filenames when not using the reek CLI.
However, it wasn't working to match the full path as provided by pronto-reek. For example, if your reek.yml specifies "lib/foo.rb", pronto-reek was supplying files as
Pathname("/home/me/code/project/lib/foo.rb")`, and it was failing to match.
This change modifies the new_file_full_path from the patch to instead be a relative path from the pwd, which is correctly matched by the reek config.
Caveats:
double
that knows a whole lot about Reek internals to generate a config.#new_file_relative_path
method.patch.new_file_full_path.relative_path_from(Pathname.new(repo.path))
, but this did not work in the tests because the fixture git repo is in a subdir, so reek was unable to open "./hello.rb". While relative_path_from repo.path worked fine testing this against my own repository, I'm not familiar enough with how pronto treats submodules or nested git directories to know if that approach will work. I also don't know ifpwd
is the right approach either, depending on how reek/pronto is called. Probably a better thing to do is try and figure out the directory containing a reek config file, and do everything relative from there.Fixes #19