com.github.shyiko.ktlint.test.RuleExtension.kt Maven / Gradle / Ivy
package com.github.shyiko.ktlint.test
import com.github.shyiko.ktlint.core.KtLint
import com.github.shyiko.ktlint.core.LintError
import com.github.shyiko.ktlint.core.Rule
import com.github.shyiko.ktlint.core.RuleSet
import java.util.ArrayList
fun Rule.lint(text: String, userData: Map = emptyMap(), script: Boolean = false): List {
val res = ArrayList()
val debug = debugAST()
val f: L = if (script) KtLint::lintScript else KtLint::lint
f(text, (if (debug) listOf(RuleSet("debug", DumpAST())) else emptyList()) +
listOf(RuleSet("standard", this@lint)), userData) { e ->
if (debug) {
System.err.println("^^ lint error")
}
res.add(e)
}
return res
}
private typealias L = (
text: String,
ruleSets: Iterable,
userData: Map,
cb: (e: LintError) -> Unit
) -> Unit
fun Rule.format(
text: String,
userData: Map = emptyMap(),
cb: (e: LintError, corrected: Boolean) -> Unit = { _, _ -> },
script: Boolean = false
): String {
val f: F = if (script) KtLint::formatScript else KtLint::format
return f(text, (if (debugAST()) listOf(RuleSet("debug", DumpAST())) else emptyList()) +
listOf(RuleSet("standard", this@format)), userData, cb)
}
private typealias F = (
text: String,
ruleSets: Iterable,
userData: Map,
cb: (e: LintError, corrected: Boolean) -> Unit
) -> String
© 2015 - 2024 Weber Informatics LLC | Privacy Policy