Repository: cjbooms/fabrikt
Pull request #64 (2021-07-08 19:40:22)

ISSUE-60 Backing out linter entirely.
 It conflicts with the version of kotlin in source projects

cjbooms: 👍 

Patch:
diff --git a/build.gradle.kts b/build.gradle.kts
index 6572a17..08b2ad1 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -48,8 +48,6 @@ dependencies {
     implementation("com.reprezen.jsonoverlay:jsonoverlay:4.0.3")
     implementation("com.squareup:kotlinpoet:1.3.0") { exclude(module = "kotlin-stdlib-jre7") }
     implementation("com.google.flogger:flogger:0.4")
-    implementation("com.pinterest.ktlint:ktlint-core:0.41.0")
-    implementation("com.pinterest:ktlint:0.41.0")
 
     testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0")
     testImplementation("org.junit.jupiter:junit-jupiter-engine:5.1.0")
@@ -59,6 +57,8 @@ dependencies {
     testImplementation("javax.validation:validation-api:2.0.1.Final")
     testImplementation("org.springframework:spring-webmvc:5.1.9.RELEASE")
     testImplementation("com.squareup.okhttp3:okhttp:4.9.1")
+    testImplementation("com.pinterest.ktlint:ktlint-core:0.41.0")
+    testImplementation("com.pinterest:ktlint:0.41.0")
 }
 
 tasks {
diff --git a/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGen.kt b/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGen.kt
index 78eda10..ade74bf 100644
--- a/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGen.kt
+++ b/src/main/kotlin/com/cjbooms/fabrikt/cli/CodeGen.kt
@@ -4,7 +4,6 @@ import com.beust.jcommander.ParameterException
 import com.cjbooms.fabrikt.configurations.Packages
 import com.cjbooms.fabrikt.generators.MutableSettings
 import com.cjbooms.fabrikt.model.SourceApi
-import com.cjbooms.fabrikt.validation.Linter
 import java.nio.file.Files
 import java.nio.file.Path
 import java.util.logging.Logger
@@ -51,6 +50,5 @@ object CodeGen {
         val sourceApi = SourceApi.create(suppliedApi, apiFragments, baseDir)
         val generator = CodeGenerator(packages, sourceApi)
         generator.generate().forEach { it.writeFileTo(outputDir.toFile()) }
-        Linter.lint(outputDir)
     }
 }
diff --git a/src/main/kotlin/com/cjbooms/fabrikt/validation/Linter.kt b/src/test/kotlin/com/cjbooms/fabrikt/util/Linter.kt
similarity index 50%
rename from src/main/kotlin/com/cjbooms/fabrikt/validation/Linter.kt
rename to src/test/kotlin/com/cjbooms/fabrikt/util/Linter.kt
index bbeaad7..68eab22 100644
--- a/src/main/kotlin/com/cjbooms/fabrikt/validation/Linter.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/util/Linter.kt
@@ -1,16 +1,11 @@
-package com.cjbooms.fabrikt.validation
+package com.cjbooms.fabrikt.util
 
 import com.pinterest.ktlint.core.KtLint
 import com.pinterest.ktlint.core.RuleSetProvider
-import java.nio.file.FileSystems
-import java.nio.file.Files
-import java.nio.file.Path
 import java.util.ServiceLoader
 
 object Linter {
 
-    private const val KOTLIN_EXTENSION = "kt"
-    private const val ARBITRARY_FOLDER_DEPTH = 20
     private val lintRuleSets = ServiceLoader.load(RuleSetProvider::class.java)
         .map { it.get() }.sortedBy {
             when (it.id) {
@@ -19,20 +14,6 @@ object Linter {
             }
         }
 
-    fun lint(directory: Path) {
-        val matcher = FileSystems.getDefault().getPathMatcher("glob:**.$KOTLIN_EXTENSION")
-        val ktSourceFiles = Files.find(
-            directory, ARBITRARY_FOLDER_DEPTH,
-            { file, _ -> matcher.matches(file) }
-        )
-        ktSourceFiles.forEach { path ->
-            val file = path.toFile()
-            val fileContent = file.readText()
-            val lintedContent = lintString(fileContent)
-            if (fileContent != lintedContent) file.writeText(lintedContent)
-        }
-    }
-
     fun lintString(rawText: String) =
         // lint twice, first lint adds whitespace after each line in a multiline field annotation.
         internalLintString(internalLintString(rawText))


Test patch:
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
index 8ae8fe0..889e80f 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
@@ -7,8 +7,8 @@ import com.cjbooms.fabrikt.configurations.Packages
 import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator
 import com.cjbooms.fabrikt.model.Models
 import com.cjbooms.fabrikt.model.SourceApi
+import com.cjbooms.fabrikt.util.Linter
 import com.cjbooms.fabrikt.util.ResourceHelper.readTextResource
-import com.cjbooms.fabrikt.validation.Linter
 import com.squareup.kotlinpoet.FileSpec
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.BeforeEach
@@ -116,11 +116,13 @@ class ModelGeneratorTest {
         "/badInput/ErrorMixingOneOfWithObject.yaml",
         "schema contains an invalid combination of properties and `oneOf | anyOf | allOf`"
     )
+
     @Test
     fun `mixing anyOf with object type throws constructive error`() = assertExceptionWithMessage(
         "/badInput/ErrorMixingAnyOfWithObject.yaml",
         "schema contains an invalid combination of properties and `oneOf | anyOf | allOf`"
     )
+
     @Test
     fun `mixing allOf with object type throws constructive error`() = assertExceptionWithMessage(
         "/badInput/ErrorMixingAllOfWithObject.yaml",
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt
index 8933df7..0a58195 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/OkHttpClientGeneratorTest.kt
@@ -11,8 +11,8 @@ import com.cjbooms.fabrikt.model.ClientType
 import com.cjbooms.fabrikt.model.Models
 import com.cjbooms.fabrikt.model.SimpleFile
 import com.cjbooms.fabrikt.model.SourceApi
+import com.cjbooms.fabrikt.util.Linter
 import com.cjbooms.fabrikt.util.ResourceHelper.readTextResource
-import com.cjbooms.fabrikt.validation.Linter
 import com.squareup.kotlinpoet.FileSpec
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.BeforeEach
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt
index cecd709..6b7d90a 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/ResourceGeneratorTest.kt
@@ -6,13 +6,13 @@ import com.cjbooms.fabrikt.generators.model.JacksonModelGenerator
 import com.cjbooms.fabrikt.generators.model.QuarkusReflectionModelGenerator
 import com.cjbooms.fabrikt.model.ResourceFile
 import com.cjbooms.fabrikt.model.SourceApi
-import java.nio.file.Paths
-import java.util.stream.Stream
 import org.assertj.core.api.Assertions.assertThat
 import org.junit.jupiter.api.BeforeEach
 import org.junit.jupiter.api.TestInstance
 import org.junit.jupiter.params.ParameterizedTest
 import org.junit.jupiter.params.provider.MethodSource
+import java.nio.file.Paths
+import java.util.stream.Stream
 
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
 class ResourceGeneratorTest {
@@ -32,8 +32,9 @@ class ResourceGeneratorTest {
         print("Testcase: $testCaseName")
         val basePackage = "examples.$testCaseName"
         val apiLocation = javaClass.getResource("/examples/$testCaseName/api.yaml")
-        val sourceApi = SourceApi(apiLocation.readText(), baseDir = Paths.get(apiLocation.toURI()))
-        val expectedResource = javaClass.getResource("/examples/$testCaseName/resources/reflection-config.json").readText()
+        val sourceApi = SourceApi(apiLocation!!.readText(), baseDir = Paths.get(apiLocation.toURI()))
+        val expectedResource =
+            javaClass.getResource("/examples/$testCaseName/resources/reflection-config.json")!!.readText()
         val generationTypes = setOf(CodeGenerationType.QUARKUS_REFLECTION_CONFIG)
 
         val models = JacksonModelGenerator(Packages(basePackage), sourceApi, emptySet()).generate()
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/SpringControllerGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/SpringControllerGeneratorTest.kt
index a90046d..f10387e 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/generators/SpringControllerGeneratorTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/SpringControllerGeneratorTest.kt
@@ -7,8 +7,8 @@ import com.cjbooms.fabrikt.generators.controller.metadata.SpringImports
 import com.cjbooms.fabrikt.model.Controllers
 import com.cjbooms.fabrikt.model.Destinations.controllersPackage
 import com.cjbooms.fabrikt.model.SourceApi
+import com.cjbooms.fabrikt.util.Linter
 import com.cjbooms.fabrikt.util.ResourceHelper.readTextResource
-import com.cjbooms.fabrikt.validation.Linter
 import com.squareup.kotlinpoet.FileSpec
 import com.squareup.kotlinpoet.TypeSpec
 import org.assertj.core.api.Assertions.assertThat