diff --git a/README.md b/README.md index 14c19289..4abe302f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Available on the Gradle Plugins Portal: https://plugins.gradle.org/plugin/org.jm ```kotlin plugins { - id("org.jmailen.kotlinter") version "3.13.0" + id("org.jmailen.kotlinter") version "3.14.0" } ``` @@ -31,7 +31,7 @@ plugins { ```groovy plugins { - id "org.jmailen.kotlinter" version "3.13.0" + id "org.jmailen.kotlinter" version "3.14.0" } ``` @@ -45,7 +45,7 @@ Root `build.gradle.kts` ```kotlin plugins { - id("org.jmailen.kotlinter") version "3.13.0" apply false + id("org.jmailen.kotlinter") version "3.14.0" apply false } ``` @@ -65,7 +65,7 @@ Root `build.gradle` ```groovy plugins { - id 'org.jmailen.kotlinter' version "3.13.0" apply false + id 'org.jmailen.kotlinter' version "3.14.0" apply false } ``` @@ -155,8 +155,6 @@ Options are configured in the `kotlinter` extension. Defaults shown (you may omi kotlinter { ignoreFailures = false reporters = arrayOf("checkstyle", "plain") - experimentalRules = false - disabledRules = emptyArray() } ``` @@ -169,8 +167,6 @@ kotlinter { kotlinter { ignoreFailures = false reporters = ['checkstyle', 'plain'] - experimentalRules = false - disabledRules = [] } ``` @@ -180,21 +176,13 @@ Options for `reporters`: `checkstyle`, `html`, `json`, `plain`, `sarif` Reporters behave as described at: https://github.com/pinterest/ktlint -The `experimentalRules` property enables rules which are part of ktlint's experimental rule set. - -The `disabledRules` property can includes an array of rule ids you wish to disable. For example to allow wildcard imports: -```groovy -disabledRules = ["no-wildcard-imports"] -``` -You must prefix rule ids not part of the standard rule set with `:`. For example `experimental:annotation`. - ### Editorconfig Kotlinter will configure itself using an `.editorconfig` file if one is present. -If a non-empty `disabledRules` value is specified in the `kotlinter` extension, it will take precedence over any `disabled_rules` in `.editorconfig`. +This configuration includes code style and linting rules. -See [Ktlint editorconfig](https://github.com/pinterest/ktlint#editorconfig) for supported values. +See [KtLint configuration](https://pinterest.github.io/ktlint/rules/configuration-ktlint/) for details. ### Customizing Tasks @@ -205,8 +193,8 @@ so you can customize includes, excludes, and source. Kotlin ```kotlin -tasks.lintKotlinMain { - exclude("com/example/**/generated/*.kt") +tasks.named("lintKotlinMain") { + source = source - fileTree("$buildDir/generated") } ``` @@ -216,8 +204,8 @@ tasks.lintKotlinMain { Groovy ```groovy -tasks.named('lintKotlinMain') { - exclude 'com/example/**/generated/*.kt' +tasks.named("lintKotlinMain") { + source = source - fileTree("$buildDir/generated") } ``` @@ -270,7 +258,6 @@ tasks.register('ktLint', LintTask) { 'plain': file('build/lint-report.txt'), 'json' : file('build/lint-report.json') ] - disabledRules = ['import-ordering'] } @@ -278,7 +265,6 @@ tasks.register('ktFormat', FormatTask) { group 'formatting' source files('src/test') report = file('build/format-report.txt') - disabledRules = ['import-ordering'] } ``` @@ -296,14 +282,14 @@ buildscript { configurations.classpath { resolutionStrategy { force( - "com.pinterest.ktlint:ktlint-core:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-checkstyle:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-json:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-html:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-plain:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-sarif:0.39.0", - "com.pinterest.ktlint:ktlint-ruleset-experimental:0.39.0", - "com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0" + "com.pinterest.ktlint:ktlint-core:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-checkstyle:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-json:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-html:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-plain:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-sarif:0.48.0", + "com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0", + "com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0" ) } } @@ -320,14 +306,14 @@ buildscript { configurations.classpath { resolutionStrategy { force( - "com.pinterest.ktlint:ktlint-core:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-checkstyle:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-json:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-html:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-plain:0.39.0", - "com.pinterest.ktlint:ktlint-reporter-sarif:0.39.0", - "com.pinterest.ktlint:ktlint-ruleset-experimental:0.39.0", - "com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0" + "com.pinterest.ktlint:ktlint-core:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-checkstyle:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-json:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-html:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-plain:0.48.0", + "com.pinterest.ktlint:ktlint-reporter-sarif:0.48.0", + "com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0", + "com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0" ) } } diff --git a/build.gradle.kts b/build.gradle.kts index b0824ddc..c900eedd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.8.0" + kotlin("jvm") version "1.8.10" id("com.gradle.plugin-publish") version "1.1.0" `java-gradle-plugin` `maven-publish` @@ -20,7 +20,7 @@ val githubUrl = "https://github.com/jeremymailen/kotlinter-gradle" val webUrl = "https://github.com/jeremymailen/kotlinter-gradle" val projectDescription = "Lint and formatting for Kotlin using ktlint with configuration-free setup on JVM and Android projects" -version = "3.13.0" +version = "3.14.0" group = "org.jmailen.gradle" description = projectDescription @@ -98,8 +98,8 @@ tasks { } withType().configureEach { kotlinOptions { - apiVersion = "1.4" - languageVersion = "1.4" + apiVersion = "1.8" + languageVersion = "1.8" jvmTarget = targetJavaVersion.toString() } } @@ -131,6 +131,10 @@ gradlePlugin { } } +java { + withSourcesJar() +} + publishing { publications.withType { @@ -156,6 +160,10 @@ publishing { id.set("jeremymailen") name.set("Jeremy Mailen") } + developer { + id.set("mateuszkwiecinski") + name.set("Mateusz KwieciƄski") + } } } } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt index c09867ef..26189337 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterExtension.kt @@ -5,16 +5,10 @@ import org.jmailen.gradle.kotlinter.support.ReporterType open class KotlinterExtension { companion object { const val DEFAULT_IGNORE_FAILURES = false - const val DEFAULT_EXPERIMENTAL_RULES = false val DEFAULT_REPORTER = ReporterType.checkstyle.name - val DEFAULT_DISABLED_RULES = emptyArray() } var ignoreFailures = DEFAULT_IGNORE_FAILURES var reporters = arrayOf(DEFAULT_REPORTER) - - var experimentalRules = DEFAULT_EXPERIMENTAL_RULES - - var disabledRules = DEFAULT_DISABLED_RULES } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt index ce1e4166..f0900513 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/KotlinterPlugin.kt @@ -36,7 +36,10 @@ class KotlinterPlugin : Plugin { val formatKotlin = registerParentFormatTask() sourceResolver.applyToAll(this) { id, resolvedSources -> - val lintTaskPerSourceSet = tasks.register("lintKotlin${id.capitalize()}", LintTask::class.java) { lintTask -> + val lintTaskPerSourceSet = tasks.register( + "lintKotlin${id.replaceFirstChar(Char::titlecase)}", + LintTask::class.java, + ) { lintTask -> lintTask.source(resolvedSources) lintTask.ignoreFailures.set(provider { kotlinterExtension.ignoreFailures }) lintTask.reports.set( @@ -46,18 +49,17 @@ class KotlinterPlugin : Plugin { } }, ) - lintTask.experimentalRules.set(provider { kotlinterExtension.experimentalRules }) - lintTask.disabledRules.set(provider { kotlinterExtension.disabledRules.toList() }) } lintKotlin.configure { lintTask -> lintTask.dependsOn(lintTaskPerSourceSet) } - val formatKotlinPerSourceSet = tasks.register("formatKotlin${id.capitalize()}", FormatTask::class.java) { formatTask -> + val formatKotlinPerSourceSet = tasks.register( + "formatKotlin${id.replaceFirstChar(Char::titlecase)}", + FormatTask::class.java, + ) { formatTask -> formatTask.source(resolvedSources) formatTask.report.set(reportFile("$id-format.txt")) - formatTask.experimentalRules.set(provider { kotlinterExtension.experimentalRules }) - formatTask.disabledRules.set(provider { kotlinterExtension.disabledRules.toList() }) } formatKotlin.configure { formatTask -> formatTask.dependsOn(formatKotlinPerSourceSet) diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/EditorConfigUtils.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/EditorConfigUtils.kt index cbeba016..5aa48c19 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/EditorConfigUtils.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/EditorConfigUtils.kt @@ -1,84 +1,8 @@ package org.jmailen.gradle.kotlinter.support -import com.pinterest.ktlint.core.api.EditorConfigDefaults -import com.pinterest.ktlint.core.api.EditorConfigOverride -import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty -import org.ec4j.core.model.EditorConfig -import org.ec4j.core.model.Glob -import org.ec4j.core.model.Property -import org.ec4j.core.model.PropertyType -import org.ec4j.core.model.PropertyType.PropertyValueParser.IDENTITY_VALUE_PARSER -import org.ec4j.core.model.Section import org.gradle.api.file.ProjectLayout import java.io.File -internal fun editorConfigOverride(ktLintParams: KtLintParams) = - getPropertiesForDisabledRules(ktLintParams) - .let(::buildEditorConfigOverride) - -internal fun editorConfigDefaults(ktLintParams: KtLintParams): EditorConfigDefaults = - getPropertiesForExperimentalRules(ktLintParams) - .let(::buildEditorConfigDefaults) - -private fun getPropertiesForDisabledRules( - ktLintParams: KtLintParams, -): List, String>> { - val rules = ktLintParams.disabledRules - return if (rules.isEmpty()) { - emptyList() - } else { - rules - .asSequence() - .map(::getKtlintRulePropertyName) - .map { propertyName -> - EditorConfigProperty( - type = PropertyType(propertyName, "Rule to be disabled", IDENTITY_VALUE_PARSER), - defaultValue = "disabled", - ) - } - .map { it to "disabled" } - .toList() - } -} - -private fun getPropertiesForExperimentalRules(ktLintParams: KtLintParams) = - Property - .builder() - .name("ktlint_experimental") - .value(if (ktLintParams.experimentalRules) "enabled" else "disabled") - .let(::listOf) - -private fun buildEditorConfigOverride(editorConfigProperties: List, String>>) = - if (editorConfigProperties.isEmpty()) { - EditorConfigOverride.EMPTY_EDITOR_CONFIG_OVERRIDE - } else { - EditorConfigOverride.from(*editorConfigProperties.toTypedArray()) - } - -private fun buildEditorConfigDefaults(kotlinSectionProperties: List) = - if (kotlinSectionProperties.isEmpty()) { - EditorConfigDefaults.EMPTY_EDITOR_CONFIG_DEFAULTS - } else { - EditorConfigDefaults( - EditorConfig - .builder() - .section( - Section - .builder() - .glob(Glob("*.{kt,kts}")) - .properties(kotlinSectionProperties), - ) - .build(), - ) - } - -private fun getKtlintRulePropertyName(ruleName: String) = - if (ruleName.contains(':')) { // Rule from a non-standard rule set - "ktlint_${ruleName.replace(':', '_')}" - } else { - "ktlint_standard_$ruleName" - } - internal fun ProjectLayout.findApplicableEditorConfigFiles(): Sequence { val projectEditorConfig = projectDirectory.file(".editorconfig").asFile diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtLintParams.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtLintParams.kt deleted file mode 100644 index 2d0effd8..00000000 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtLintParams.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jmailen.gradle.kotlinter.support - -import java.io.Serializable - -data class KtLintParams( - val experimentalRules: Boolean, - val disabledRules: List, -) : Serializable diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt index 463d20b3..9985178a 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/KtlintEngineUtils.kt @@ -5,19 +5,22 @@ import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.logging.Logger import java.io.File -internal fun createKtlintEngine(ktLintParams: KtLintParams) = KtLintRuleEngine( +// You must create a new KtLintRuleEngine per file with fresh rule providers. +// Otherwise, KtLint errors on resolving rule enable/disable statements in .editorconfig +internal fun createKtlintEngine() = KtLintRuleEngine( ruleProviders = resolveRuleProviders(defaultRuleSetProviders), - editorConfigOverride = editorConfigOverride(ktLintParams), - editorConfigDefaults = editorConfigDefaults(ktLintParams), ) -internal fun KtLintRuleEngine.resetEditorconfigCacheIfNeeded( +internal fun resetEditorconfigCacheIfNeeded( changedEditorconfigFiles: ConfigurableFileCollection, logger: Logger, ) { + val engine = createKtlintEngine() val changedFiles = changedEditorconfigFiles.files if (changedFiles.any()) { logger.info("Editorconfig changed, resetting KtLint caches") - changedFiles.map(File::toPath).forEach(::reloadEditorConfigFile) + changedFiles.map(File::toPath).forEach { + engine.reloadEditorConfigFile(it) + } } } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/Reporters.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/Reporters.kt index f3b834e9..840ee113 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/support/Reporters.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/support/Reporters.kt @@ -10,7 +10,7 @@ import java.io.File import java.io.PrintStream /* ktlint-disable enum-entry-name-case */ -internal enum class ReporterType(val fileExtension: String) { +enum class ReporterType(val fileExtension: String) { checkstyle("xml"), html("html"), json("json"), diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt index f8b46c35..b8ad3531 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/ConfigurableKtLintTask.kt @@ -6,9 +6,7 @@ import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles -import org.gradle.api.tasks.Internal import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SourceTask @@ -16,9 +14,6 @@ import org.gradle.internal.exceptions.MultiCauseException import org.gradle.work.FileChange import org.gradle.work.Incremental import org.gradle.work.InputChanges -import org.jmailen.gradle.kotlinter.KotlinterExtension.Companion.DEFAULT_DISABLED_RULES -import org.jmailen.gradle.kotlinter.KotlinterExtension.Companion.DEFAULT_EXPERIMENTAL_RULES -import org.jmailen.gradle.kotlinter.support.KtLintParams import org.jmailen.gradle.kotlinter.support.findApplicableEditorConfigFiles abstract class ConfigurableKtLintTask( @@ -26,12 +21,6 @@ abstract class ConfigurableKtLintTask( objectFactory: ObjectFactory, ) : SourceTask() { - @Input - val experimentalRules: Property = objectFactory.property(default = DEFAULT_EXPERIMENTAL_RULES) - - @Input - val disabledRules: ListProperty = objectFactory.listProperty(default = DEFAULT_DISABLED_RULES.toList()) - @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) @get:Incremental @@ -39,12 +28,6 @@ abstract class ConfigurableKtLintTask( from(projectLayout.findApplicableEditorConfigFiles().toList()) } - @Internal - protected fun getKtLintParams(): KtLintParams = KtLintParams( - experimentalRules = experimentalRules.get(), - disabledRules = disabledRules.get(), - ) - protected fun getChangedEditorconfigFiles(inputChanges: InputChanges) = if (inputChanges.isIncremental) { inputChanges.getFileChanges(editorconfigFiles).map(FileChange::getFile) diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/FormatTask.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/FormatTask.kt index 53ba5c2d..fd2d6815 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/FormatTask.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/FormatTask.kt @@ -38,7 +38,6 @@ open class FormatTask @Inject constructor( p.name.set(name) p.files.from(source) p.projectDirectory.set(projectLayout.projectDirectory.asFile) - p.ktLintParams.set(getKtLintParams()) p.output.set(report) p.changedEditorConfigFiles.from(getChangedEditorconfigFiles(inputChanges)) } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/LintTask.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/LintTask.kt index f294144b..3762b57f 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/LintTask.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/LintTask.kt @@ -51,7 +51,6 @@ open class LintTask @Inject constructor( p.files.from(source) p.projectDirectory.set(projectLayout.projectDirectory.asFile) p.reporters.putAll(reports) - p.ktLintParams.set(getKtLintParams()) p.changedEditorConfigFiles.from(getChangedEditorconfigFiles(inputChanges)) } runCatching { await() } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerAction.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerAction.kt index 53ef90fe..37e344a8 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerAction.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerAction.kt @@ -7,7 +7,6 @@ import org.gradle.api.logging.Logging import org.gradle.internal.logging.slf4j.DefaultContextAwareTaskLogger import org.gradle.workers.WorkAction import org.jmailen.gradle.kotlinter.support.KotlinterError -import org.jmailen.gradle.kotlinter.support.KtLintParams import org.jmailen.gradle.kotlinter.support.createKtlintEngine import org.jmailen.gradle.kotlinter.support.resetEditorconfigCacheIfNeeded import org.jmailen.gradle.kotlinter.tasks.FormatTask @@ -18,19 +17,19 @@ abstract class FormatWorkerAction : WorkAction { private val files: List = parameters.files.toList() private val projectDirectory: File = parameters.projectDirectory.asFile.get() private val name: String = parameters.name.get() - private val ktLintParams: KtLintParams = parameters.ktLintParams.get() private val output: File? = parameters.output.asFile.orNull override fun execute() { - val ktLintEngine = createKtlintEngine(ktLintParams = ktLintParams) - ktLintEngine.resetEditorconfigCacheIfNeeded( + resetEditorconfigCacheIfNeeded( changedEditorconfigFiles = parameters.changedEditorConfigFiles, logger = logger, ) - val fixes = mutableListOf() + try { files.forEach { file -> + val ktLintEngine = createKtlintEngine() + val sourceText = file.readText() val relativePath = file.toRelativeString(projectDirectory) @@ -46,11 +45,11 @@ abstract class FormatWorkerAction : WorkAction { true -> "${file.path}:${error.line}:${error.col}: Format fixed > [${error.ruleId}] ${error.detail}" false -> "${file.path}:${error.line}:${error.col}: Format could not fix > [${error.ruleId}] ${error.detail}" } - logger.log(LogLevel.QUIET, msg) + logger.warn(msg) fixes.add(msg) } if (!formattedText.contentEquals(sourceText)) { - logger.log(LogLevel.QUIET, "${file.path}: Format fixed") + logger.warn("${file.path}: Format fixed") file.writeText(formattedText) } } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerParameters.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerParameters.kt index d8a4b64b..3f182cf2 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerParameters.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/format/FormatWorkerParameters.kt @@ -4,13 +4,11 @@ import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.workers.WorkParameters -import org.jmailen.gradle.kotlinter.support.KtLintParams interface FormatWorkerParameters : WorkParameters { val name: Property val changedEditorConfigFiles: ConfigurableFileCollection val files: ConfigurableFileCollection val projectDirectory: RegularFileProperty - val ktLintParams: Property val output: RegularFileProperty } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerAction.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerAction.kt index 01f210a0..1ba6b76c 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerAction.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerAction.kt @@ -7,7 +7,6 @@ import org.gradle.api.logging.Logging import org.gradle.internal.logging.slf4j.DefaultContextAwareTaskLogger import org.gradle.workers.WorkAction import org.jmailen.gradle.kotlinter.support.KotlinterError -import org.jmailen.gradle.kotlinter.support.KtLintParams import org.jmailen.gradle.kotlinter.support.LintFailure import org.jmailen.gradle.kotlinter.support.createKtlintEngine import org.jmailen.gradle.kotlinter.support.reporterFor @@ -24,20 +23,19 @@ abstract class LintWorkerAction : WorkAction { private val files: List = parameters.files.toList() private val projectDirectory: File = parameters.projectDirectory.asFile.get() private val name: String = parameters.name.get() - private val ktLintParams: KtLintParams = parameters.ktLintParams.get() override fun execute() { - val ktLintEngine = createKtlintEngine(ktLintParams = ktLintParams) - ktLintEngine.resetEditorconfigCacheIfNeeded( + resetEditorconfigCacheIfNeeded( changedEditorconfigFiles = parameters.changedEditorConfigFiles, logger = logger, ) - var hasError = false try { reporters.onEach { it.beforeAll() } files.forEach { file -> + val ktLintEngine = createKtlintEngine() + val relativePath = file.toRelativeString(projectDirectory) reporters.onEach { it.before(relativePath) } logger.debug("$name linting: $relativePath") @@ -54,7 +52,7 @@ abstract class LintWorkerAction : WorkAction { val filePath = reporterPathFor(reporter, file, projectDirectory) reporter.onLintError(filePath, error, false) } - logger.quiet("${file.path}:${error.line}:${error.col}: Lint error > [${error.ruleId}] ${error.detail}") + logger.error("${file.path}:${error.line}:${error.col}: Lint error > [${error.ruleId}] ${error.detail}") } reporters.onEach { it.after(relativePath) } } diff --git a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerParameters.kt b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerParameters.kt index f060af66..c04474b4 100644 --- a/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerParameters.kt +++ b/src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/lint/LintWorkerParameters.kt @@ -5,7 +5,6 @@ import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.MapProperty import org.gradle.api.provider.Property import org.gradle.workers.WorkParameters -import org.jmailen.gradle.kotlinter.support.KtLintParams import java.io.File interface LintWorkerParameters : WorkParameters { @@ -14,5 +13,4 @@ interface LintWorkerParameters : WorkParameters { val files: ConfigurableFileCollection val projectDirectory: RegularFileProperty val reporters: MapProperty - val ktLintParams: Property } diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/CustomTaskTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/CustomTaskTest.kt index 6bfa46bb..de1266ed 100644 --- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/CustomTaskTest.kt +++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/CustomTaskTest.kt @@ -52,6 +52,7 @@ class CustomTaskTest : WithGradleTest.Kotlin() { println("go") } } + """.trimIndent() writeText(validClass) } @@ -64,8 +65,6 @@ class CustomTaskTest : WithGradleTest.Kotlin() { task ktLint(type: LintTask) { source files('src') reports = ['plain': file('build/lint-report.txt')] - experimentalRules = true - disabledRules = ["final-newline"] } """ @@ -112,8 +111,6 @@ class CustomTaskTest : WithGradleTest.Kotlin() { task customizedLintTask(type: LintTask) { source files('src') reports = ['plain': file('build/lint-report.txt')] - experimentalRules = true - disabledRules = ["final-newline"] ignoreFailures = true } @@ -139,8 +136,6 @@ class CustomTaskTest : WithGradleTest.Kotlin() { task customizedFormatTask(type: FormatTask) { source files('src') - experimentalRules = true - disabledRules = ["final-newline"] } """.trimIndent() diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/ExtensionTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/ExtensionTest.kt index 5b7867c1..b5039e97 100644 --- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/ExtensionTest.kt +++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/ExtensionTest.kt @@ -77,36 +77,6 @@ internal class ExtensionTest : WithGradleTest.Kotlin() { assertTrue(report.readText().isNotEmpty()) } - @Test - fun `extension configures disabledRules`() { - projectRoot.resolve("build.gradle") { - // language=groovy - val script = - """ - kotlinter { - experimentalRules = true - disabledRules = ["filename", "experimental:unnecessary-parentheses-before-trailing-lambda"] - } - """.trimIndent() - appendText(script) - } - projectRoot.resolve("src/main/kotlin/FileName.kt") { - writeText(kotlinClass("DifferentClassName")) - } - projectRoot.resolve("src/main/kotlin/UnnecessaryParentheses.kt") { - writeText( - """ - val FAILING = "should not have '()'".count() { it == 'x' } - - """.trimIndent(), - ) - } - - build("lintKotlin").apply { - assertEquals(TaskOutcome.SUCCESS, task(":lintKotlinMain")?.outcome) - } - } - @Test fun `extension properties are evaluated only during task execution`() { projectRoot.resolve("build.gradle") { @@ -123,7 +93,7 @@ internal class ExtensionTest : WithGradleTest.Kotlin() { } kotlinter { - disabledRules = ["filename"] + ignoreFailures = true } """.trimIndent() diff --git a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/KotlinProjectTest.kt b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/KotlinProjectTest.kt index eb86d3fe..8c70f0de 100644 --- a/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/KotlinProjectTest.kt +++ b/src/test/kotlin/org/jmailen/gradle/kotlinter/functional/KotlinProjectTest.kt @@ -55,32 +55,6 @@ internal class KotlinProjectTest : WithGradleTest.Kotlin() { } } - @Test - fun `lintKotlinMain fails when lint errors for experimental rules are detected`() { - settingsFile() - buildFile() - - buildFile.appendText( - """ - - kotlinter { - experimentalRules = true - } - """.trimIndent(), - ) - - fileWithFailingExperimentalRule() - - buildAndFail("lintKotlinMain").apply { - assertTrue(output.contains(".*Lint error > \\[experimental:unnecessary-parentheses".toRegex())) - output.lines().filter { it.contains("Lint error") }.forEach { line -> - val filePath = pathPattern.find(line)?.groups?.get(1)?.value.orEmpty() - assertTrue(File(filePath).exists()) - } - assertEquals(FAILED, task(":lintKotlinMain")?.outcome) - } - } - @Test fun `lintKotlinMain succeeds when no lint errors detected`() { settingsFile()