Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat: add check for .dot file
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 24, 2022
1 parent d443ec3 commit 75d3a80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ class LanguageService {
}
}

fun detectLanguage(countFile: String): String {
fun detectLanguage(name: String): String {
val language = ""
val dotCount = countFile.count { it == '.' }
if (dotCount == 0) {
val optFilenameLang = filenameToLanguage[countFile.lowercase()]
val dotCount = name.count { it == '.' }

// such as `.gitignore` file
val isDotFile = name[0] == '.' && dotCount == 1
val notExtensionName = dotCount == 0
val ifNeedToCheckFullName = notExtensionName || isDotFile
if (ifNeedToCheckFullName) {
val optFilenameLang = filenameToLanguage[name.lowercase()]
if (optFilenameLang != null) {
return optFilenameLang.toString()
}
}

val dotSplit = countFile.split(".")
val dotSplit = name.split(".")
val firstExt = dotSplit.last()
val optLang = extToLanguage[firstExt.lowercase()]
if (optLang != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ internal class LanguageServiceTest {
val lang = LanguageService()
assertEquals("License", lang.detectLanguage("LICENSE"))
}

@Test
fun should_check_gitignore() {
val lang = LanguageService()
assertEquals("gitignore", lang.detectLanguage(".gitignore"))
}

// @Test
// fun should_return_typescript_define_file() {
// val lang = LanguageService()
// assertEquals("TypeScript Typings", lang.detectLanguage("d.ts"))
// }
}

0 comments on commit 75d3a80

Please sign in to comment.