diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/PackageNameRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/DirectoryStructureRule.kt similarity index 73% rename from ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/PackageNameRule.kt rename to ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/DirectoryStructureRule.kt index 0532f1d50f..f88fce668d 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/PackageNameRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/DirectoryStructureRule.kt @@ -8,11 +8,10 @@ import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import java.io.File /** - * @see [Kotlin Style Guide](https://kotlinlang.org/docs/reference/coding-conventions.html#naming-rules) - * @see [Android Style Guide](https://android.github.io/kotlin-guides/style.html#package-names) + * @see [Kotlin Style Guide](https://kotlinlang.org/docs/reference/coding-conventions.html#directory-structure) * @author yokotaso */ -class PackageNameRule : Rule("package-name") { +class DirectoryStructureRule : Rule("directory-structure") { override fun visit( node: ASTNode, @@ -29,10 +28,6 @@ class PackageNameRule : Rule("package-name") { .endsWith(File.separatorChar + qualifiedName.replace('.', File.separatorChar))) { emit(node.startOffset, "Package directive doesn't match file location", false) } - if (qualifiedName.contains('_')) { - emit(node.startOffset, "Package name must not contain underscore", false) - // "package name must be in lowercase" is violated by too many to projects in the wild to forbid - } } } } diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/StandardRuleSetProvider.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/StandardRuleSetProvider.kt index f675d87abf..af1b9dd93b 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/StandardRuleSetProvider.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/StandardRuleSetProvider.kt @@ -10,7 +10,7 @@ class StandardRuleSetProvider : RuleSetProvider { CommentSpacingRule(), FilenameRule(), FinalNewlineRule(), - PackageNameRule(), + DirectoryStructureRule(), // disabled until auto-correct is working properly // (e.g. try formatting "if (true)\n return { _ ->\n _\n}") // MultiLineIfElseRule(), diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/PackageNameRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/DirectoryStructureRuleTest.kt similarity index 70% rename from ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/PackageNameRuleTest.kt rename to ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/DirectoryStructureRuleTest.kt index 6fc0730de9..749f8e20b5 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/PackageNameRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/DirectoryStructureRuleTest.kt @@ -10,7 +10,7 @@ import java.nio.file.Paths /** * @author yokotaso */ -class PackageNameRuleTest { +class DirectoryStructureRuleTest { @Test fun testOK() { @@ -27,16 +27,7 @@ class PackageNameRuleTest { assertNOK( "package hoge.fuga", "/hoge/moge/A.kt", - listOf(LintError(1, 1, "package-name", "Package directive doesn't match file location")) - ) - } - - @Test - fun testNOKUnderScore() { - assertNOK( - "package hoge.moge.hoge_moge", - "/hoge/moge/hoge_moge/A.kt", - listOf(LintError(1, 1, "package-name", "Package name must not contain underscore")) + listOf(LintError(1, 1, "directory-structure", "Package directive doesn't match file location")) ) } @@ -52,10 +43,10 @@ class PackageNameRuleTest { mapOf("file_path" to Paths.get(URI.create("file:///$fileName")).toString()) private fun assertOK(ktScript: String, fileName: String) { - assertThat(PackageNameRule().lint(ktScript, fileName(fileName))).isEmpty() + assertThat(DirectoryStructureRule().lint(ktScript, fileName(fileName))).isEmpty() } private fun assertNOK(ktScript: String, fileName: String, lintErrors: List) { - assertThat(PackageNameRule().lint(ktScript, fileName(fileName))).isEqualTo(lintErrors) + assertThat(DirectoryStructureRule().lint(ktScript, fileName(fileName))).isEqualTo(lintErrors) } }