-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address feedback on ClassNameMatchesFileNameRule PR
- Get filepath from userData - Ignore non .kt files - Change offset to 0 for errror reporting - Removed ASTNodeExtensions, moved visit() method to internal util file
- Loading branch information
1 parent
790710e
commit 1025de1
Showing
8 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
ktlint-core/src/main/kotlin/com/github/shyiko/ktlint/core/ASTNodeExtensions.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...tandard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoMultipleSpacesRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/NoUnusedImportsRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...rd/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/ParameterListWrappingRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 31 additions & 14 deletions
45
...test/kotlin/com/github/shyiko/ktlint/ruleset/standard/ClassNameMatchesFileNameRuleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,81 @@ | ||
package com.github.shyiko.ktlint.ruleset.standard | ||
|
||
import com.github.shyiko.ktlint.core.LintError | ||
import com.github.shyiko.ktlint.test.lintWithFileName | ||
import com.github.shyiko.ktlint.test.lint | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.testng.annotations.Test | ||
|
||
class ClassNameMatchesFileNameRuleTest { | ||
|
||
@Test | ||
fun testMatchingSingleClassName() { | ||
assertThat(ClassNameMatchesFileNameRule().lintWithFileName("/some/path/A.kt", | ||
assertThat(ClassNameMatchesFileNameRule().lint( | ||
""" | ||
class A | ||
""".trimIndent() | ||
""".trimIndent(), | ||
fileName("/some/path/A.kt") | ||
)).isEmpty() | ||
} | ||
|
||
@Test | ||
fun testNonMatchingSingleClassName() { | ||
assertThat(ClassNameMatchesFileNameRule().lintWithFileName("A.kt", | ||
assertThat(ClassNameMatchesFileNameRule().lint( | ||
""" | ||
class B | ||
""".trimIndent() | ||
""".trimIndent(), | ||
fileName("A.kt") | ||
)).isEqualTo(listOf( | ||
LintError(1, 7, "class-name-matches-file-name", "Single top level class name [B] does not match file name") | ||
LintError(1, 1, "class-name-matches-file-name", "Single top level class name [B] does not match file name") | ||
)) | ||
} | ||
|
||
@Test | ||
fun testMultipleTopLevelClasses() { | ||
assertThat(ClassNameMatchesFileNameRule().lintWithFileName("A.kt", | ||
assertThat(ClassNameMatchesFileNameRule().lint( | ||
""" | ||
class B | ||
class C | ||
""".trimIndent() | ||
""".trimIndent(), | ||
fileName("A.kt") | ||
)).isEmpty() | ||
} | ||
|
||
@Test | ||
fun testMultipleNonTopLevelClasses() { | ||
assertThat(ClassNameMatchesFileNameRule().lintWithFileName("A.kt", | ||
assertThat(ClassNameMatchesFileNameRule().lint( | ||
""" | ||
class B { | ||
class C | ||
class D | ||
} | ||
""".trimIndent() | ||
""".trimIndent(), | ||
fileName("A.kt") | ||
)).isEqualTo(listOf( | ||
LintError(1, 7, "class-name-matches-file-name", "Single top level class name [B] does not match file name") | ||
LintError(1, 1, "class-name-matches-file-name", "Single top level class name [B] does not match file name") | ||
)) | ||
} | ||
|
||
@Test | ||
fun testCaseSensitiveMatching() { | ||
assertThat(ClassNameMatchesFileNameRule().lintWithFileName("woohoo.kt", | ||
assertThat(ClassNameMatchesFileNameRule().lint( | ||
""" | ||
interface Woohoo | ||
""".trimIndent() | ||
""".trimIndent(), | ||
fileName("woohoo.kt") | ||
)).isEqualTo(listOf( | ||
LintError(1, 11, "class-name-matches-file-name", "Single top level class name [Woohoo] does not match file name") | ||
LintError(1, 1, "class-name-matches-file-name", "Single top level class name [Woohoo] does not match file name") | ||
)) | ||
} | ||
|
||
@Test | ||
fun testIgnoreKotlinScriptFiles() { | ||
assertThat(ClassNameMatchesFileNameRule().lint( | ||
""" | ||
class B | ||
""".trimIndent(), | ||
fileName("A.kts") | ||
)).isEmpty() | ||
} | ||
|
||
private fun fileName(fileName: String) = mapOf("file_path" to fileName) | ||
} |