Skip to content

Commit

Permalink
Add JS support to LanguageComposition recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 23, 2024
1 parent 7cb42eb commit 885dd3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation("org.openrewrite:rewrite-python:$latest")
implementation("org.openrewrite:rewrite-kotlin:$latest")
implementation("org.openrewrite:rewrite-csharp:$latest")
implementation("org.openrewrite:rewrite-javascript:$latest")

testRuntimeOnly("org.openrewrite:rewrite-java-17")
}
13 changes: 13 additions & 0 deletions src/main/java/org/openrewrite/LanguageComposition.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openrewrite.groovy.tree.G;
import org.openrewrite.hcl.tree.Hcl;
import org.openrewrite.java.tree.J;
import org.openrewrite.javascript.tree.JS;
import org.openrewrite.json.tree.Json;
import org.openrewrite.kotlin.tree.K;
import org.openrewrite.properties.tree.Properties;
Expand Down Expand Up @@ -184,6 +185,18 @@ public TreeVisitor<?, ExecutionContext> getScanner(Accumulator acc) {
s.getClass().getName(),
genericLineCount,
hasParseFailure));
} else if (s instanceof JS.CompilationUnit) {
Counts javaScriptCounts = acc.getFolderToLanguageToCounts()
.computeIfAbsent(folderPath, k -> new HashMap<>())
.computeIfAbsent("JavaScript", k -> new Counts());
javaScriptCounts.fileCount++;
javaScriptCounts.lineCount += genericLineCount;
perFileReport.insertRow(ctx, new LanguageCompositionPerFile.Row(
s.getSourcePath().toString(),
"JavaScript",
s.getClass().getName(),
genericLineCount,
hasParseFailure));
} else if (s instanceof J) {
Counts javaCounts = acc.getFolderToLanguageToCounts()
.computeIfAbsent(folderPath, k -> new HashMap<>())
Expand Down

0 comments on commit 885dd3d

Please sign in to comment.