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

"Not able to determine a path to a scanned file or "src" directory cannot be found in it's path" Error #1202

Closed
yewton opened this issue Jan 31, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@yewton
Copy link

yewton commented Jan 31, 2022

Describe the bug

./gradlew spotlessApply output 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

P.S. Telegram inivitation link seems being expired...

Expected behavior

Not getting any error

Observed behavior

Described error occurs

Steps to Reproduce

checkout https://github.com/yewton/testdiktat and run ./gradlew spotlessApply

Environment information

  • diktat version:1.0.1
  • build tool (maven/gradle):gradle
  • how is diktat run (CLI, plugin, etc.):Spotless plugin
  • kotlin version:1.5.31
  • operating system:Xubuntu Jammy Jellyfish (development branch) x86_64
  • link to a project (if your project is public): https://github.com/yewton/testdiktat
@yewton yewton added the bug Something isn't working label Jan 31, 2022
@orchestr7
Copy link
Member

Hi! @Cheshiriks will investigate it as he was integrating it to the spotless.

But @yewton do you really need Spotless? 😄 Why not to use diktat directly.

@yewton
Copy link
Author

yewton commented Jan 31, 2022

Yes, there is no reason to do so 😄
I learned about diktat in the Spotless repository, so test them out of curiosity.

@Cheshiriks
Copy link
Member

Cheshiriks commented Jan 31, 2022

Problem in PACKAGE_NAME_MISSING and INCORRECT_PACKAGE_SEPARATOR. I will continue investigation. The reason looks to be in the incorrect path finder in spotless.

Please note that this warning does not affect other rules and if you will enabled those rules that you have disabled you will see diktat warnings.

@orchestr7
Copy link
Member

@Cheshiriks you will also need to update version of ktlint and diktat in Spotless

@HaukeRa
Copy link

HaukeRa commented Apr 28, 2022

Still happening in Spotless version 6.5.1 with diktat 1.1.0

@HaukeRa
Copy link

HaukeRa commented Apr 28, 2022

Spotless passes file.getName() to KtLint's Params
https://github.com/diffplug/spotless/blob/a8f208a99d571502fa960c25530c83d2a8349bbd/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java#L155

Compared to ktlint's own cli implementation passing the whole path:
https://github.com/pinterest/ktlint/blob/3472532b6e413ac302c3f63fc75a32db0169f54c/ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt#L325

I have not tested this, but this looks like the culprit. If this is the case, then diktat's parameter name choice is questionable. Should be an easy fix though.

EDIT: Further debugging revealed that this line is probably also the culprit:
https://github.com/pinterest/ktlint/blob/3472532b6e413ac302c3f63fc75a32db0169f54c/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt#L279

It overrides the file_path entry supplied in userData with params.normalizedFilePath.toString() which effectively returns the fileName provided in the Params constructor.

So to fix the issue either KtLint does not forcibly override a file_path property supplied via Params::userData or Spotless should pass the absolute path to Params::fileName.

Consequently this is not Diktat's fault, but Spotless and/or KtLint are responsible.

@petertrr
Copy link
Member

petertrr commented May 4, 2022

The issue should be resolved in spotless-grade 6.5.2, so I'm closing it. Feel free to reopen if this issue ever occurs again

@petertrr petertrr closed this as completed May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants