Skip to content

Commit

Permalink
Fixed code formatting (#563)
Browse files Browse the repository at this point in the history
Using current ktlint-maven-plugin version.
  • Loading branch information
freemanjp committed Aug 14, 2023
1 parent acfdd3c commit 304000f
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class AbstractBaseMojo : AbstractMojo() {
@Parameter(
defaultValue = "\${project.testCompileSourceRoots}",
readonly = true,
required = true
required = true,
)
protected lateinit var testSourceRoots: List<String>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import org.apache.maven.plugins.annotations.Parameter
name = "check",
defaultPhase = LifecyclePhase.VERIFY,
requiresProject = true,
threadSafe = true
threadSafe = true,
)
class CheckMojo : AbstractBaseMojo() {

Expand Down Expand Up @@ -94,20 +94,20 @@ class CheckMojo : AbstractBaseMojo() {
isIncluded = includeSources,
sourceRoots = sourceRoots,
includes = sourcesIncludes,
excludes = sourcesExcludes
excludes = sourcesExcludes,
),
Sources(
isIncluded = includeTestSources,
sourceRoots = testSourceRoots,
includes = testSourcesIncludes,
excludes = testSourcesExcludes
excludes = testSourcesExcludes,
),
Sources(
isIncluded = includeScripts,
sourceRoots = scriptRoots,
includes = scriptsIncludes,
excludes = scriptsExcludes
)
excludes = scriptsExcludes,
),
),
charset = encoding?.trim()?.takeUnless(String::isEmpty)
?.let { Charset.forName(it) }
Expand All @@ -118,7 +118,7 @@ class CheckMojo : AbstractBaseMojo() {
reporterColor = reporterColor,
reporterColorName = reporterColorName,
enableExperimentalRules = experimental,
failOnViolation = failOnViolation
failOnViolation = failOnViolation,
)()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.apache.maven.plugins.annotations.Parameter
name = "format",
defaultPhase = LifecyclePhase.PROCESS_SOURCES,
requiresProject = true,
threadSafe = true
threadSafe = true,
)
class FormatMojo : AbstractBaseMojo() {

Expand All @@ -63,26 +63,26 @@ class FormatMojo : AbstractBaseMojo() {
isIncluded = includeSources,
sourceRoots = sourceRoots,
includes = sourcesIncludes,
excludes = sourcesExcludes
excludes = sourcesExcludes,
),
Sources(
isIncluded = includeTestSources,
sourceRoots = testSourceRoots,
includes = testSourcesIncludes,
excludes = testSourcesExcludes
excludes = testSourcesExcludes,
),
Sources(
isIncluded = includeScripts,
sourceRoots = scriptRoots,
includes = scriptsIncludes,
excludes = scriptsExcludes
)
excludes = scriptsExcludes,
),
),
charset = encoding?.trim()?.takeUnless(String::isEmpty)
?.let { Charset.forName(it) }
?: UTF_8,
android = android,
enableExperimentalRules = experimental
enableExperimentalRules = experimental,
)()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import org.apache.maven.reporting.AbstractMavenReport
name = "ktlint",
defaultPhase = LifecyclePhase.VERIFY,
requiresProject = true,
threadSafe = true
threadSafe = true,
)
class KtlintReport : AbstractMavenReport() {

Expand All @@ -62,7 +62,7 @@ class KtlintReport : AbstractMavenReport() {
@Parameter(
defaultValue = "\${project.testCompileSourceRoots}",
readonly = true,
required = true
required = true,
)
private lateinit var testSourceRoots: List<String>

Expand Down Expand Up @@ -166,7 +166,7 @@ class KtlintReport : AbstractMavenReport() {
return ResourceBundle.getBundle(
"ktlint-report",
locale,
AbstractMavenReport::class.java.classLoader
AbstractMavenReport::class.java.classLoader,
)
}

Expand All @@ -191,28 +191,28 @@ class KtlintReport : AbstractMavenReport() {
isIncluded = includeSources,
sourceRoots = sourceRoots,
includes = sourcesIncludes,
excludes = sourcesExcludes
excludes = sourcesExcludes,
),
Sources(
isIncluded = includeTestSources,
sourceRoots = testSourceRoots,
includes = testSourcesIncludes,
excludes = testSourcesExcludes
excludes = testSourcesExcludes,
),
Sources(
isIncluded = includeScripts,
sourceRoots = scriptRoots,
includes = scriptsIncludes,
excludes = scriptsExcludes
)
excludes = scriptsExcludes,
),
),
charset = encoding?.trim()?.takeUnless(String::isEmpty)
?.let { Charset.forName(it) }
?: UTF_8,
android = android,
reporterConfig = reporters ?: emptySet(),
verbose = verbose,
enableExperimentalRules = experimental
enableExperimentalRules = experimental,
)()
KtlintReportGenerator(sink, getBundle(locale)).generatorReport(results)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MavenLogReporter(
val log: Log,
val verbose: Boolean,
val groupByFile: Boolean,
val pad: Boolean
val pad: Boolean,
) : Reporter {

private val acc = ConcurrentHashMap<String, MutableList<LintError>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MavenLogReporterProvider : ReporterProvider<MavenLogReporter> {
log = log,
verbose = opt["verbose"].emptyOrTrue(),
groupByFile = opt["group_by_file"].emptyOrTrue(),
pad = opt["pad"].emptyOrTrue()
pad = opt["pad"].emptyOrTrue(),
)

private fun String?.emptyOrTrue() = this == "" || this == "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ import java.util.Properties
data class ReporterConfig @JvmOverloads constructor(
var name: String? = null,
var output: File? = null,
var properties: Properties? = null
var properties: Properties? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ internal abstract class AbstractCheckSupport(
protected val verbose: Boolean,
private var reporterColor: Boolean,
private var reporterColorName: String,
enableExperimentalRules: Boolean
enableExperimentalRules: Boolean,
) : AbstractLintSupport(log, basedir, android, enableExperimentalRules) {

protected open val reporter: Reporter
get() {
data class ReporterTemplate(
val id: String,
val config: Map<String, String>,
var output: String?
var output: String?,
)

val templates: List<ReporterTemplate> =
Expand All @@ -86,9 +86,9 @@ internal abstract class AbstractCheckSupport(
config = mapOf(
"verbose" to verbose.toString(),
"color" to reporterColor.toString(),
"color_name" to reporterColorName
"color_name" to reporterColorName,
) + properties,
output = output?.toString()
output = output?.toString(),
)
}
.distinct()
Expand All @@ -106,13 +106,13 @@ internal abstract class AbstractCheckSupport(
val availableReporters = reporterProviderById.keys.sorted()
throw MojoFailureException(
"Error: reporter '$id' wasn't found (available: " +
"${availableReporters.joinToString(",")})"
"${availableReporters.joinToString(",")})",
)
}
if (log.isDebugEnabled) {
log.debug(
"Initializing '$id' reporter with $config" +
(output?.let { ", output=$it" } ?: "")
(output?.let { ", output=$it" } ?: ""),
)
}
val stream =
Expand Down Expand Up @@ -162,14 +162,14 @@ internal abstract class AbstractCheckSupport(
}
if (!sourceRoot.isDirectory) {
throw MojoFailureException(
"Source root is not a directory: ${sourceRoot.toRelativeString(basedir)}"
"Source root is not a directory: ${sourceRoot.toRelativeString(basedir)}",
)
}

val includesArray =
includes.takeUnless(Set<String>::isEmpty)?.toTypedArray() ?: arrayOf(
"**/*.kt",
"**/*.kts"
"**/*.kts",
)
val excludesArray = excludes.toTypedArray()

Expand Down Expand Up @@ -214,7 +214,7 @@ internal abstract class AbstractCheckSupport(

hasErrors = true
},
editorConfigOverride
editorConfigOverride,
)

reporter.after(baseRelativePath)
Expand All @@ -230,15 +230,15 @@ internal abstract class AbstractCheckSupport(
sourceText: String,
ruleProviders: Set<RuleProvider>,
onError: (error: LintError) -> Unit,
editorConfigOverride: EditorConfigOverride
editorConfigOverride: EditorConfigOverride,
) = KtLint.lint(
KtLint.ExperimentalParams(
fileName = fileName,
text = sourceText,
ruleProviders = ruleProviders,
script = !fileName.endsWith(".kt", ignoreCase = true),
cb = { e, _ -> onError(e) },
editorConfigOverride = editorConfigOverride
)
editorConfigOverride = editorConfigOverride,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal abstract class AbstractLintSupport(
protected val log: Log,
protected val basedir: File,
protected val android: Boolean,
private val enableExperimentalRules: Boolean
private val enableExperimentalRules: Boolean,
) {
protected val ruleProviders: Set<RuleProvider> by lazy {
return@lazy ServiceLoader.load(RuleSetProviderV2::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class Check(
reporterColor: Boolean,
reporterColorName: String,
enableExperimentalRules: Boolean,
private val failOnViolation: Boolean
private val failOnViolation: Boolean,
) : AbstractCheckSupport(
log,
basedir,
Expand All @@ -56,7 +56,7 @@ internal class Check(
verbose,
reporterColor,
reporterColorName,
enableExperimentalRules
enableExperimentalRules,
) {
operator fun invoke() {
val reporter = reporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ internal class FileLintError(
val line: Int,
val col: Int,
val ruleId: String,
val detail: String
val detail: String,
) {
constructor(file: String, lintError: LintError) : this(
file,
lintError.line,
lintError.col,
lintError.ruleId,
lintError.detail
lintError.detail,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class Format(
private val sources: List<Sources>,
private val charset: Charset,
android: Boolean,
enableExperimentalRules: Boolean
enableExperimentalRules: Boolean,
) : AbstractLintSupport(log, basedir, android, enableExperimentalRules) {

private val formattedFileCount = AtomicInteger()
Expand All @@ -69,7 +69,7 @@ internal class Format(
}
if (!sourceRoot.isDirectory) {
throw MojoFailureException(
"Source root is not a directory: ${sourceRoot.toRelativeString(basedir)}"
"Source root is not a directory: ${sourceRoot.toRelativeString(basedir)}",
)
}

Expand Down Expand Up @@ -112,7 +112,7 @@ internal class Format(
val lintError = "$baseRelativePath:$line:$col: $detail"
log.debug("Format ${if (corrected) "fixed" else "could not fix"} > $lintError")
},
editorConfigOverride
editorConfigOverride,
)
if (formattedText !== sourceText) {
log.debug("Format fixed > $baseRelativePath")
Expand All @@ -130,15 +130,15 @@ internal class Format(
sourceText: String,
ruleProviders: Set<RuleProvider>,
onError: (err: LintError, corrected: Boolean) -> Unit,
editorConfigOverride: EditorConfigOverride
editorConfigOverride: EditorConfigOverride,
): String = KtLint.format(
KtLint.ExperimentalParams(
fileName = fileName,
text = sourceText,
ruleProviders = ruleProviders,
script = !fileName.endsWith(".kt", ignoreCase = true),
cb = onError,
editorConfigOverride = editorConfigOverride
)
editorConfigOverride = editorConfigOverride,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.apache.maven.doxia.sink.Sink

internal class KtlintReportGenerator(
private val sink: Sink,
private val bundle: ResourceBundle
private val bundle: ResourceBundle,
) {

private val title = bundle["report.ktlint.title"]
Expand Down Expand Up @@ -133,7 +133,7 @@ internal class KtlintReportGenerator(
val sortedErrors = errors.sortedWith(
Comparator.comparingInt(FileLintError::line)
.thenComparingInt(FileLintError::col)
.thenComparing(FileLintError::ruleId)
.thenComparing(FileLintError::ruleId),
)
section(2, id = file.replace('/', '.')) {
title {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal class Report(
android: Boolean,
reporterConfig: Set<ReporterConfig>,
verbose: Boolean,
enableExperimentalRules: Boolean
enableExperimentalRules: Boolean,
) : AbstractCheckSupport(
log,
basedir,
Expand All @@ -53,7 +53,7 @@ internal class Report(
verbose,
false,
Color.DARK_GRAY.name,
enableExperimentalRules
enableExperimentalRules,
) {
operator fun invoke(): CheckResults {
val modelReporter = ModelReporter()
Expand Down

0 comments on commit 304000f

Please sign in to comment.