Skip to content

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

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

Activity

  1. nedtwigg commented on Apr 28, 2022

    @nedtwigg
    Member

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

  2. petertrr commented on Apr 30, 2022

    @petertrr
    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

  3. nedtwigg commented on May 4, 2022

    @nedtwigg
    Member

    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

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