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

Spotless causes Diktat to fail to execute PACKAGE_NAME_INCORRECT_PATH inspection correctly #1189

Closed
HaukeRa opened this issue Apr 28, 2022 · 3 comments
Labels

Comments

@HaukeRa
Copy link

HaukeRa commented Apr 28, 2022

As already reported by someone to Diktat's issue tracker:
saveourtool/diktat#1202

running Spotless with Diktat and the PACKAGE_NAME_INCORRECT_PATH inspection causes the following error:

Not able to determine a path to a scanned file or "src" directory cannot be found in it's path. Will not be able to determine correct package name. It can happen due to missing <src> directory in the path

This is caused by Spotless passing file.getName() to KtLint.Params:

/* fileName, nullable */ file.getName(),

The parameter name is fileName but the documentation of the class states that it expects the "path of file to lint/format".
Spotless also tries to pass the absolute file name in the Params::userData map, but this value will get overriden with the value passed to fileName here:
https://github.com/pinterest/ktlint/blob/3472532b6e413ac302c3f63fc75a32db0169f54c/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt#L279

Spotless-Gradle 6.5.1
Spotless 2.25.1
Diktat 1.1.0
KtLint 0.45.2
Gradle 7.4.2
Windows 10 21H2 / Ubuntu 20.04.4 LTS

Config:

spotless {
    kotlin {
        target("**/*.kt")
        diktat("1.1.0")
    }
@nedtwigg nedtwigg added the bug label Apr 28, 2022
@nedtwigg
Copy link
Member

PR's welcome :) If you happen to be interested in adding more diktat features, #524 would be a good approach.

@petertrr
Copy link
Contributor

I can confirm @HaukeRa 's idea - in diktat-maven-plugin there is a similar setup with invoking Ktlint.lint and Ktlint.format directly, and diktat-maven-plugin uses relative path to the file rather than just a name:
https://github.com/analysis-dev/diktat/blob/90b852939fb5b606e96611004435c8038e991982/diktat-maven-plugin/src/main/kotlin/org/cqfn/diktat/plugin/maven/DiktatBaseMojo.kt#L237

@nedtwigg
Copy link
Member

nedtwigg commented May 4, 2022

Fixed by @petertrr , released in plugin-gradle 6.5.2 and plugin-maven 2.22.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants