-
Notifications
You must be signed in to change notification settings - Fork 503
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
[0.49.0] loadBaseline
loads invalid absolute paths when invoked from separate process/with different working directory
#1962
Comments
* Store path of file containing a lint violation relative to the path of the baseline file itself Closes #1962
@mateuszkwiecinski Can you please verify whether the problem is solved for you in latest snapshot build? |
@paul-dingemans Unfortunately I still observe the same behavior. I assume it's because the
loads since From my observation the Or maybe I'm using the wrong code. I'm a bit of lost which artifacts are meant to be used by API consumers and which are only needed for CLI. Previously there was just one, now I have to depend on 4 of them
Baseline.kt I'm referring to comes from |
I have incorrectly assumed that the baseline file was always stored in the root of the project. Now, the baseline again will return the relative path to the file. But it needed a fix in the Ktlint CLI to retrieve the existing errors from the baseline so that errors in the baseline will not be reported. The terminology "API Consumer" might be confusing. For me an API Consumer is a project that invokes the KtlintRuleEngine directly. Such API Consumers do not use the Ktlint CLI (and as of that non of the ktlint-cli modules). Integrators that invoke the Ktlint CLI typically do not invoke the KtlintRuleEngine directly. I am confused why you have a need for using the |
I missed the last part of your comment:
It looks like that you're (ab)using the |
New snapshot is available with fix in |
Expected Behavior
I'd expect
loadBaseline
to expose relative paths, like0.48.x
did, or have a way to pass a root directory baseline entries should be resolved against (aloadBaseline(path = ..., workingDir = ...)
)?Observed Behavior
Baseline#lintErrorsPerFile
reference absolute paths pointing at temporary location created by Gradle, which is different than the one passed toKtlineRuleEngine#lint
or#format
.+ sample baseline entry:
(The screeshot lists result of
loadBaseline(...).lintErrorsPerFile.keys
and compares it with file paths passed to #lint or #format asCode.fromFile(file)
As far as I understand,
loadBaseline
creates absolute paths relatively to the place it was called. So when running in process isolation, when gradle try to run stuff safely,loadBaseline
is effectively called from i.e.$GRADLE_HOME/workers
which results in invalid absolute paths resolved.0.48.0
returned relative paths, so plugins find absolute location on their own: example1, example2Offending code: link + the comment that suggests different things than the function does, I guess 👀
Steps to Reproduce
ktlint --baseline=ktlint-baseline.xml
loadBaseline()
from a process with working directory outside of the directory the baseline was created from? or whatever Gradle Worker with process isolation does here 😬Your Environment
.editorconfig
settings - N/AThe text was updated successfully, but these errors were encountered: