Skip to content

Commit

Permalink
File with single toplevel extension function should only adhere to Pa…
Browse files Browse the repository at this point in the history
…scalConvention (#1528)

Closes #1521
  • Loading branch information
paul-dingemans committed Jul 18, 2022
1 parent 6ad30d2 commit 7abe7da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The "visit" life cycle hook will be removed in Ktlint 0.48. In KtLint 0.47 the "
### Fixed

* Fix cli argument "--disabled_rules" ([#1520](https://github.com/pinterest/ktlint/issue/1520)).
* A file which contains a single top level declaration of type function does not need to be name after the function but only needs to adhere to the PascalCase convention. `filename` ([#1521](https://github.com/pinterest/ktlint/issue/1521)).
* When a glob is specified then ensure that it matches files in the current directory and not only in subdirectories of the current directory ([#1533](https://github.com/pinterest/ktlint/issue/1533)).
* Disable/enable IndentationRule on blocks in middle of file. (`indent`) [#631](https://github.com/pinterest/ktlint/issues/631)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public class FilenameRule : Rule("filename") {
if (topLevelDeclarations.size == 1) {
val topLevelDeclaration = topLevelDeclarations.first()
if (topLevelDeclaration.elementType == OBJECT_DECLARATION ||
topLevelDeclaration.elementType == TYPEALIAS ||
topLevelDeclaration.elementType == FUN
topLevelDeclaration.elementType == TYPEALIAS
) {
val pascalCaseIdentifier =
topLevelDeclaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,10 @@ class FilenameRuleTest {
@ValueSource(
strings = [
"object Foo",
"typealias Foo = String",
"fun String.foo() = {}",
"fun foo() = {}"
"typealias Foo = String"
]
)
fun `Given a file containing one top level declaration (no class or property) then the file should be named after the identifier`(
fun `Given a file containing one top level declaration then the file should be named after the identifier`(
code: String
) {
fileNameRuleAssertThat(code)
Expand All @@ -98,10 +96,13 @@ class FilenameRuleTest {
@ValueSource(
strings = [
"val foo",
"const val FOO"
"const val FOO",
"fun String.foo() = {}",
"fun foo() = {}",
"operator fun Foo.plus(other: Foo): Foo { /* ... */ }"
]
)
fun `Given a file containing one top level property declaration (non-private) then the file should conform to PascalCase`(
fun `Given a file containing one top level then the file should conform to PascalCase`(
code: String
) {
fileNameRuleAssertThat(code)
Expand Down

0 comments on commit 7abe7da

Please sign in to comment.