Skip to content

Commit

Permalink
Merge pull request #1108 from Tapchicoma/tapchicoma/move-baseline-sup…
Browse files Browse the repository at this point in the history
…port

Move baseline utils into 'ktlint-core' package.
  • Loading branch information
Tapchicoma authored Mar 16, 2021
2 parents 338a9a4 + 1826101 commit b6fa2c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pinterest.ktlint.internal
package com.pinterest.ktlint.core.internal

import com.pinterest.ktlint.core.LintError
import java.io.File
Expand All @@ -16,7 +16,9 @@ import org.xml.sax.SAXException
* @param baselineFilePath the path to the xml baseline file
* @return a [CurrentBaseline] with the file details
*/
internal fun loadBaseline(baselineFilePath: String): CurrentBaseline {
public fun loadBaseline(
baselineFilePath: String
): CurrentBaseline {
if (baselineFilePath.isBlank()) {
return CurrentBaseline(null, false)
}
Expand Down Expand Up @@ -92,17 +94,17 @@ private fun parseBaselineErrorsByFile(element: Element): MutableList<LintError>
return errors
}

internal class CurrentBaseline(
val baselineRules: Map<String, List<LintError>>?,
val baselineGenerationNeeded: Boolean
public class CurrentBaseline(
public val baselineRules: Map<String, List<LintError>>?,
public val baselineGenerationNeeded: Boolean
)

/**
* Checks if the list contains the lint error. We cannot use the contains function
* as the `checkstyle` reporter formats the details string and hence the comparison
* normally fails
*/
internal fun List<LintError>.containsLintError(error: LintError): Boolean {
public fun List<LintError>.containsLintError(error: LintError): Boolean {
return firstOrNull { lintError ->
lintError.col == error.col &&
lintError.line == error.line &&
Expand All @@ -114,7 +116,7 @@ internal fun List<LintError>.containsLintError(error: LintError): Boolean {
* Gets the relative route of the file for baselines
* Also adjusts the slashes for uniformity between file systems
*/
internal val File.relativeRoute: String
public val File.relativeRoute: String
get() {
val rootPath = Paths.get("").toAbsolutePath()
val filePath = this.toPath()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pinterest.ktlint.internal
package com.pinterest.ktlint.core.internal

import com.pinterest.ktlint.core.LintError
import java.io.ByteArrayInputStream
Expand All @@ -7,7 +7,7 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class BaselineUtilsKtTest {
class BaselineSupportTest {

@Test
fun testParseBaselineFile() {
Expand Down
6 changes: 3 additions & 3 deletions ktlint/src/main/kotlin/com/pinterest/ktlint/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.pinterest.ktlint.core.Reporter
import com.pinterest.ktlint.core.ReporterProvider
import com.pinterest.ktlint.core.RuleExecutionException
import com.pinterest.ktlint.core.RuleSetProvider
import com.pinterest.ktlint.core.internal.containsLintError
import com.pinterest.ktlint.core.internal.loadBaseline
import com.pinterest.ktlint.core.internal.relativeRoute
import com.pinterest.ktlint.internal.ApplyToIDEAGloballySubCommand
import com.pinterest.ktlint.internal.ApplyToIDEAProjectSubCommand
import com.pinterest.ktlint.internal.GenerateEditorConfigSubCommand
Expand All @@ -17,15 +20,12 @@ import com.pinterest.ktlint.internal.GitPrePushHookSubCommand
import com.pinterest.ktlint.internal.JarFiles
import com.pinterest.ktlint.internal.KtlintVersionProvider
import com.pinterest.ktlint.internal.PrintASTSubCommand
import com.pinterest.ktlint.internal.containsLintError
import com.pinterest.ktlint.internal.fileSequence
import com.pinterest.ktlint.internal.formatFile
import com.pinterest.ktlint.internal.lintFile
import com.pinterest.ktlint.internal.loadBaseline
import com.pinterest.ktlint.internal.loadRulesets
import com.pinterest.ktlint.internal.location
import com.pinterest.ktlint.internal.printHelpOrVersionUsage
import com.pinterest.ktlint.internal.relativeRoute
import com.pinterest.ktlint.internal.toFilesURIList
import com.pinterest.ktlint.reporter.plain.internal.Color
import java.io.File
Expand Down

0 comments on commit b6fa2c8

Please sign in to comment.