-
Notifications
You must be signed in to change notification settings - Fork 503
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
Allow naming file with single extension method after the target of the extension #1521
Comments
I like the suggestion for the expected behavior. So either the name of the function For now, you can work around this by suppressing the rule for this file specifically:
|
In my particular case I worked around it by converting it from a function to a property since it probably should have been a property all along |
…plus name of an extension function when it is the only top level declaration in a file Closes pinterest#1521
That works sometimes but in general it can't be a solution. In my case, the rule wants to name my file operator fun PaddingValues.plus(other: PaddingValues): PaddingValues {
val self = this
return object : PaddingValues {
override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp {
return self.calculateLeftPadding(layoutDirection) + other.calculateLeftPadding(layoutDirection)
}
override fun calculateTopPadding(): Dp {
return self.calculateTopPadding() + other.calculateTopPadding()
}
override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp {
return self.calculateRightPadding(layoutDirection) + other.calculateRightPadding(layoutDirection)
}
override fun calculateBottomPadding(): Dp {
return self.calculateBottomPadding() + other.calculateBottomPadding()
}
}
} |
I would question if this rule should be applied to file which does not contain any class at all. In earlier versions, this rule wasn't applied in this case and I would really like to keep it this way (for the already provided reasons here). |
Yeah I'd prefer the rules to be split. Currently it's all or nothing but I'd like to apply some rules and others not. |
The Kotlin Coding Conventions have recently been updated based on a question I asked when the rule was changed in 0.46.0. The wording is now more clear:
From above, it is clear that a single top level declaration should not dictate the name of the file. So that needs to be changed. |
When can we expect a new tag including this fix? |
I don't know. You can track the progress of what I planned to do in this release |
Revert to extension function. Fix warnings.
When a file contains a single top-level extension function should allow naming the file after the fully qualified function, just like is allowed for extension properties
Steps to Reproduce
Given a class like this:
If I create a file that only has a single extension method on Foo.Status like this:
Observed Behavior
Ktlint demands that the file be named Image.kt which is not descriptive and may even conflict if I had multiple similar functions in the same directory
Expected Behavior
I should be able to name the file based on the target of the exension, so in this case FooStatusImage.kt.
Note that this is the behavior when it is an extension property, but not when it is an extension function.
Your Environment
ktlint 0.46.1
The text was updated successfully, but these errors were encountered: