diff --git a/src/main/kotlin/app/extractors/Heuristics.kt b/src/main/kotlin/app/extractors/Heuristics.kt index 6043aba0..e078332b 100644 --- a/src/main/kotlin/app/extractors/Heuristics.kt +++ b/src/main/kotlin/app/extractors/Heuristics.kt @@ -1121,6 +1121,9 @@ val HeuristicsMap = mapOf ExtractorInterface?>( "vue" to { _ -> JavascriptExtractor() }, + "svelte" to { _ -> + JavascriptExtractor() + }, "vw" to { _ -> CommonExtractor(Lang.PLSQL) }, diff --git a/src/main/kotlin/app/extractors/JavascriptExtractor.kt b/src/main/kotlin/app/extractors/JavascriptExtractor.kt index 304358e2..4990fbfe 100644 --- a/src/main/kotlin/app/extractors/JavascriptExtractor.kt +++ b/src/main/kotlin/app/extractors/JavascriptExtractor.kt @@ -26,8 +26,10 @@ class JavascriptExtractor : ExtractorInterface { override fun extractLibStats(files: List): List { val vueExtension = ".vue" + val svelteExtension = ".svelte" val vueFiles = files.filter { it.path.endsWith(vueExtension) } - val otherFiles = files.filter { !it.path.endsWith(vueExtension) } + val svelteFiles = files.filter { it.path.endsWith(svelteExtension) } + val otherFiles = files.filter { !it.path.endsWith(vueExtension) && !it.path.endsWith(svelteExtension) } // Add stats from *.vue files. val vueStats = listOf(CommitStats( @@ -36,7 +38,16 @@ class JavascriptExtractor : ExtractorInterface { type = ExtractorInterface.TYPE_LIBRARY, tech = "js.vue" )).filter { it.numLinesAdded > 0 || it.numLinesDeleted > 0 } - return vueStats + super.extractLibStats(otherFiles) + + // Add stats from *.svelte files. + val svelteStats = listOf(CommitStats( + numLinesAdded = svelteFiles.map { it.getAllAdded().size }.sum(), + numLinesDeleted = svelteFiles.map { it.getAllDeleted().size }.sum(), + type = ExtractorInterface.TYPE_LIBRARY, + tech = "js.svelte" + )).filter { it.numLinesAdded > 0 || it.numLinesDeleted > 0 } + + return vueStats + svelteStats + super.extractLibStats(otherFiles) } override fun tokenize(line: String): List { diff --git a/src/main/kotlin/app/extractors/Languages.kt b/src/main/kotlin/app/extractors/Languages.kt index fb80fea2..8781fc8f 100644 --- a/src/main/kotlin/app/extractors/Languages.kt +++ b/src/main/kotlin/app/extractors/Languages.kt @@ -105,6 +105,7 @@ object Lang { const val VHDL = "vhdl" // VHDL const val VIML = "viml" // Vim L const val VUE = "vue" // Vue + const val SVELTE = "svelte" // Svelte const val WOLFRAM = "wolframlanguage" // Wolfram Language const val XML = "xml" // XML const val XPM = "xpm" // XPM diff --git a/src/main/resources/data/libraries/js_libraries.txt b/src/main/resources/data/libraries/js_libraries.txt index c179587d..8d92db3c 100644 --- a/src/main/resources/data/libraries/js_libraries.txt +++ b/src/main/resources/data/libraries/js_libraries.txt @@ -1,6 +1,7 @@ react d3 vue +svelte angular jquery meteor diff --git a/src/test/kotlin/test/tests/hashers/CommitHasherTest.kt b/src/test/kotlin/test/tests/hashers/CommitHasherTest.kt index e4e9ab06..9d0211cf 100644 --- a/src/test/kotlin/test/tests/hashers/CommitHasherTest.kt +++ b/src/test/kotlin/test/tests/hashers/CommitHasherTest.kt @@ -340,6 +340,50 @@ class CommitHasherTest : Spek({ } } + given("commits with svelte files") { + val lines = listOf("line 1", "line 2") + + val author = Author(userName, userEmail) + + val testRepoPath = "../testrepo-extractor-" + val testRepo = TestRepo(testRepoPath + "svelte") + + val mockApi = MockApi(mockRepo = repo) + val observable = CommitCrawler.getObservable(testRepo.git, repo) + + it("sends stats") { + for (i in 0..lines.size - 1) { + val line = lines[i] + val fileName = "file$i.svelte" + testRepo.createFile(fileName, listOf(line)) + testRepo.commit(message = "$line in $fileName", author = author) + } + + val errors = mutableListOf() + + val rehashes = (0..lines.size - 1).map { "r$it" } + + CommitHasher(repo, mockApi, rehashes, emails) + .updateFromObservable(observable, { e -> errors.add(e) }) + + assertEquals(0, errors.size) + + val syntaxStats = mockApi.receivedAddedCommits + .fold(mutableListOf()) { allStats, commit -> + allStats.addAll(commit.stats) + allStats + }.filter { it.type == ExtractorInterface.TYPE_LIBRARY } + + val svelteStats = syntaxStats.filter { it.tech == "js.svelte" } + assertEquals(2, svelteStats.size) + assertEquals(2, svelteStats.map { it.numLinesAdded }.sum()) + assertEquals(0, svelteStats.map { it.numLinesDeleted }.sum()) + } + + afterGroup { + testRepo.destroy() + } + } given("commits with scss stats") { diff --git a/src/test/resources/samples/JavaScript/basic.svelte b/src/test/resources/samples/JavaScript/basic.svelte new file mode 100644 index 00000000..7e8c1bb8 --- /dev/null +++ b/src/test/resources/samples/JavaScript/basic.svelte @@ -0,0 +1,14 @@ + + + + +
+
\ No newline at end of file