-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from usefulness/updates
- Loading branch information
Showing
14 changed files
with
452 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 19 additions & 8 deletions
27
ktlint-gradle-plugin/src/main/kotlin/io/github/usefulness/KtlintGradleExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,35 @@ | ||
package io.github.usefulness | ||
|
||
import io.github.usefulness.support.versionProperties | ||
import io.github.usefulness.tasks.listProperty | ||
import io.github.usefulness.tasks.property | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
|
||
public open class KtlintGradleExtension internal constructor( | ||
objectFactory: ObjectFactory, | ||
) { | ||
|
||
public open class KtlintGradleExtension { | ||
internal companion object { | ||
const val DEFAULT_IGNORE_FAILURES = false | ||
const val DEFAULT_EXPERIMENTAL_RULES = false | ||
const val DEFAULT_CHUNK_SIZE = 50 | ||
val DEFAULT_DISABLED_RULES = emptyArray<String>() | ||
val DEFAULT_DISABLED_RULES = emptyList<String>() | ||
} | ||
|
||
public var ignoreFailures: Boolean = DEFAULT_IGNORE_FAILURES | ||
public var ignoreFailures: Property<Boolean> = objectFactory.property(default = DEFAULT_IGNORE_FAILURES) | ||
|
||
public var reporters: ListProperty<String> = objectFactory.listProperty(default = emptyList()) | ||
|
||
public var reporters: Array<String> = emptyArray() | ||
public var experimentalRules: Property<Boolean> = objectFactory.property(default = DEFAULT_EXPERIMENTAL_RULES) | ||
|
||
public var experimentalRules: Boolean = DEFAULT_EXPERIMENTAL_RULES | ||
public var disabledRules: ListProperty<String> = objectFactory.listProperty(default = DEFAULT_DISABLED_RULES) | ||
|
||
public var disabledRules: Array<String> = DEFAULT_DISABLED_RULES | ||
public var ktlintVersion: Property<String> = objectFactory.property(default = versionProperties.ktlintVersion()) | ||
|
||
public var ktlintVersion: String = versionProperties.ktlintVersion() | ||
public var chunkSize: Property<Int> = objectFactory.property(default = DEFAULT_CHUNK_SIZE) | ||
|
||
public var chunkSize: Int = DEFAULT_CHUNK_SIZE | ||
public var baselineFile: RegularFileProperty = objectFactory.fileProperty() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ktlint-gradle-plugin/src/main/kotlin/io/github/usefulness/support/BaselineUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.usefulness.support | ||
|
||
import com.pinterest.ktlint.core.LintError | ||
import com.pinterest.ktlint.core.api.Baseline | ||
import com.pinterest.ktlint.core.api.loadBaseline | ||
import java.io.File | ||
|
||
internal fun File.readKtlintBaseline(): Map<String, List<LintError>>? { | ||
val baseline = loadBaseline(absolutePath) | ||
when (baseline.status) { | ||
Baseline.Status.VALID -> Unit | ||
Baseline.Status.NOT_FOUND, | ||
Baseline.Status.INVALID, | ||
-> return null | ||
} | ||
|
||
return baseline.lintErrorsPerFile | ||
} | ||
|
||
internal fun File.getBaselineKey(projectDir: File) = | ||
toRelativeString(projectDir).replace(File.separatorChar, '/') | ||
|
||
/** | ||
* Same as ktlint, avoids unnecessary incompatibility issues | ||
*/ | ||
internal fun List<LintError>.doesNotContain(lintError: LintError) = | ||
none { | ||
it.col == lintError.col && | ||
it.line == lintError.line && | ||
it.ruleId == lintError.ruleId | ||
} |
Oops, something went wrong.