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

Common root package #280

Closed
mhlz opened this issue Sep 13, 2018 · 6 comments
Closed

Common root package #280

mhlz opened this issue Sep 13, 2018 · 6 comments

Comments

@mhlz
Copy link

mhlz commented Sep 13, 2018

Currently ktlint flags package names as invalid, if you're following the recommendation outlined in the coding conventions:

In pure Kotlin projects, the recommended directory structure is to follow the package structure with the common root package omitted (e.g. if all the code in the project is in the "org.example.kotlin" package and its subpackages, files with the "org.example.kotlin" package should be placed directly under the source root, and files in "org.example.kotlin.foo.bar" should be in the "foo/bar" subdirectory of the source root).

I'd like for ktlint to be able to support this directory structure as it cuts down on the nesting a lot. IntelliJ does not generate warnings (anymore) either, when following this recommendation.

@shyiko
Copy link
Collaborator

shyiko commented Sep 13, 2018

Hi @mhlz. This was supposedly fixed in 0.28.0. Let me know if that's not the case (steps to reproduce would be great).

@shyiko shyiko closed this as completed Sep 13, 2018
@mhlz
Copy link
Author

mhlz commented Sep 14, 2018

You can test it in this project: https://github.com/mhlz/kotlin-issue

Either run ktlint from the command line or run mvn install. ktlint fails with

ktlint:
   [ktlint] /Users/mhlz/Documents/IdeaProjects/acomodeo/kotlin-issue/src/main/kotlin/Main.kt:1:1: Package directive doesn't match file location (cannot be auto-corrected)
   [ktlint] /Users/mhlz/Documents/IdeaProjects/acomodeo/kotlin-issue/src/main/kotlin/model/TestClass.kt:1:1: Package directive doesn't match file location (cannot be auto-corrected)

@shyiko
Copy link
Collaborator

shyiko commented Sep 14, 2018

I see... Thank you, @mhlz. Reopening...

@shyiko shyiko reopened this Sep 14, 2018
@serebit
Copy link

serebit commented Sep 20, 2018

I have this issue as well with https://gitlab.com/serebit/diskord. Using the kotlinter gradle plugin, latest version

@mhlz
Copy link
Author

mhlz commented Sep 28, 2018

So, I looked into fixing this myself, but it seems kinda difficult to do with the way that rules currently work. We'd need some sort of "module" wide state to determine the root package. Otherwise it's going to be hard to support all use cases. Maybe as a quick fix, it'd be good to disable this rule again? I'd like to keep following and recommending the JetBrains coding conventions, but with ktlint going against them it's kinda hard.

@shyiko
Copy link
Collaborator

shyiko commented Oct 2, 2018

@mhlz Disabled in 0.29.0.

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

No branches or pull requests

3 participants