Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run opacheck on entire dir for more context #4531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

redbmk
Copy link
Contributor

@redbmk redbmk commented Jun 7, 2023

Running opa check on a single file can report errors that might not exist when considering other files in the same directory

refs: #2531

@hsanson hsanson requested a review from w0rp June 27, 2023 09:50
@@ -11,7 +11,7 @@ function! ale_linters#rego#opacheck#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'rego_opacheck_options')

return ale#Escape(ale_linters#rego#opacheck#GetExecutable(a:buffer))
\ . ' check %s --format json '
\ . ' check . --format json '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the command can start asynchronously, this could fire from a different buffer from the buffer you started on. Luckily, I added a quick way to get the directory of a file with fnamemodify-like syntax a while ago.

Suggested change
\ . ' check . --format json '
\ . ' check %s:h --format json '

Try this instead, and let me know if it works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted in the documentation for ale#linter#Define that by default ALE doesn't set a working directory for commands as that can actually break a lot of things. Another thing you could try is adding 'cwd': '%s:h' to the arguments below, and then . here should work. If you grep the codebase, a lot of linters explicitly set the work directory to be the directory of the file. Setting cwd instead may or may not work better here, it's better to just run the linter and see what happens.

Copy link
Contributor Author

@redbmk redbmk Jul 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for re-opening this - I had forgotten about it. It's been a while since I've done anything with opa or rego but I just tried this out. For a certain file I'm testing with, %s throws some errors due to missing context from the rest of the directory, while both . and %s:h seem to work fine for my setup.

I can see in :ALEInfo that using %s:h shows the full path to the directory and that seems simpler to me than setting the cwd first. I pulled down the latest changes and updated that param

Copy link

stale bot commented Mar 17, 2024

This pull request has been automatically marked as stale because it has not been updated recently. Make sure to write tests and document your changes. See :help ale-dev for information on writing tests.
If your pull request is good to merge, bother w0rp or another maintainer again, and get them to merge it.

@stale stale bot added the stale PRs/Issues no longer valid label Mar 17, 2024
@stale stale bot closed this Apr 22, 2024
@w0rp w0rp reopened this Jul 8, 2024
Running `opa check` on a single file can report errors that might not
exist when considering other files in the same directory
@stale stale bot removed the stale PRs/Issues no longer valid label Jul 8, 2024
@redbmk redbmk requested a review from w0rp July 8, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants