Skip to content

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

Closed
@HaukeRa

Description

@HaukeRa

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")
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions