Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move baseline utils into 'ktlint-core' package. #1108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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