Description
Your feature request related to a problem? Please describe.
We have a configuration that looks like this to write a JUnit report to a reports/ output directory that is normally ignored with a direction to ignore it in the top-level .gitignore
file.
output:
format: colored-line-number,junit-xml:reports/junit/lint.xml
If this reports/ directory does not exist, then golangci-lint will fail with:
level=error msg="Running error: can't create output for reports/junit/lint.xml: open reports/junit/lint.xml: no such file or directory"
Describe the solution you'd like.
I would have expected the output directory to be created, rather than failing with an error.
Describe alternatives you've considered.
We can work around the problem by committing some placeholder files in the reports directory, and then setting up .gitignore
files to ignore the individual files in this output directory. This forces git to create that output directory upon repo checkout.
But this is less ideal because it means that cleaning the repo is more complicated; you can't just delete the reports/
directory any more because some of those files (the placeholder files) are committed & thus result in dirty repo status. It also makes for more work managing the .gitignore
files.
Additional context.
The key location to change is probably here:
golangci-lint/pkg/commands/run.go
Lines 462 to 474 in 19a3387
If this function creates the directory hierarchy before attempting to open the file, then the problem can be avoided.