Skip to content

Commit ac391dc

Browse files
authored
Upgrade to ktlint 0.8.1 (#6)
1 parent a0dbd2b commit ac391dc

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
[![Build Status](https://api.travis-ci.org/jeremymailen/kotlinter-gradle.svg?branch=master)](https://travis-ci.org/jeremymailen/kotlinter-gradle)
44

5-
Gradle plugin for linting and formatting Kotlin source files using the awesome [ktlint](https://github.com/shyiko/ktlint) engine.
5+
Gradle plugin for linting and formatting Kotlin source files using the awesome [ktlint](https://ktlint.github.io) engine.
66

77
### Installation
88

99
Available on the Gradle Plugins Portal: https://plugins.gradle.org/plugin/org.jmailen.kotlinter
1010

1111
```groovy
1212
plugins {
13-
id 'org.jmailen.kotlinter' version '0.9.0'
13+
id 'org.jmailen.kotlinter' version '0.9.1'
1414
}
1515
```
1616

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repositories {
1212
}
1313

1414
dependencies {
15-
compile 'com.github.shyiko:ktlint:0.6.2'
15+
compile 'com.github.shyiko:ktlint:0.8.1'
1616
compileOnly 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-2'
1717
compileOnly 'com.android.tools.build:gradle:2.3.2'
1818
testCompile 'junit:junit:4.12'
@@ -21,7 +21,7 @@ dependencies {
2121
}
2222

2323

24-
version = '0.9.0'
24+
version = '0.9.1'
2525
group = 'org.jmailen.gradle'
2626
def pluginId = 'org.jmailen.kotlinter'
2727

src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/FormatTask.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jmailen.gradle.kotlinter.tasks
22

33
import com.github.shyiko.ktlint.core.KtLint
4+
import com.github.shyiko.ktlint.core.RuleSet
45
import org.gradle.api.logging.LogLevel
56
import org.gradle.api.tasks.OutputFile
67
import org.gradle.api.tasks.SourceTask
@@ -24,16 +25,16 @@ open class FormatTask : SourceTask() {
2425
logger.log(LogLevel.DEBUG, "checking format: $relativePath")
2526

2627
val formatFunc = when (file.extension) {
27-
"kt" -> KtLint::format
28-
"kts" -> KtLint::formatScript
28+
"kt" -> this::formatKt
29+
"kts" -> this::formatKts
2930
else -> {
3031
logger.log(LogLevel.DEBUG, "ignoring non Kotlin file: $relativePath")
3132
null
3233
}
3334
}
3435

3536
var wasFormatted = false
36-
val formattedText = formatFunc?.invoke(file.readText(), ruleSets) { (line, col, detail), corrected ->
37+
val formattedText = formatFunc?.invoke(file, ruleSets) { line, col, detail, corrected ->
3738
val errorStr = "$relativePath:$line:$col: $detail"
3839
val msg = when (corrected) {
3940
true -> "Format fixed > $errorStr"
@@ -56,4 +57,16 @@ open class FormatTask : SourceTask() {
5657
report.writeText("ok")
5758
}
5859
}
60+
61+
private fun formatKt(file: File, ruleSets: List<RuleSet>, onError: (line: Int, col: Int, detail: String, corrected: Boolean) -> Unit): String {
62+
return KtLint.format(file.readText(), ruleSets) { error, corrected ->
63+
onError(error.line, error.col, error.detail, corrected)
64+
}
65+
}
66+
67+
private fun formatKts(file: File, ruleSets: List<RuleSet>, onError: (line: Int, col: Int, detail: String, corrected: Boolean) -> Unit): String {
68+
return KtLint.formatScript(file.readText(), ruleSets) { error, corrected ->
69+
onError(error.line, error.col, error.detail, corrected)
70+
}
71+
}
5972
}

src/main/kotlin/org/jmailen/gradle/kotlinter/tasks/LintTask.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.jmailen.gradle.kotlinter.tasks
22

33
import com.github.shyiko.ktlint.core.KtLint
4+
import com.github.shyiko.ktlint.core.RuleSet
45
import org.gradle.api.GradleException
56
import org.gradle.api.logging.LogLevel
67
import org.gradle.api.tasks.Input
78
import org.gradle.api.tasks.OutputFile
89
import org.gradle.api.tasks.ParallelizableTask
910
import org.gradle.api.tasks.SourceTask
1011
import org.gradle.api.tasks.TaskAction
11-
import org.jmailen.gradle.kotlinter.KotlinterExtension
1212
import org.jmailen.gradle.kotlinter.support.resolveRuleSets
1313
import java.io.File
1414

@@ -32,15 +32,15 @@ open class LintTask : SourceTask() {
3232
logger.log(LogLevel.DEBUG, "linting: $relativePath")
3333

3434
val lintFunc = when (file.extension) {
35-
"kt" -> KtLint::lint
36-
"kts" -> KtLint::lintScript
35+
"kt" -> this::lintKt
36+
"kts" -> this::lintKts
3737
else -> {
3838
logger.log(LogLevel.DEBUG, "ignoring non Kotlin file: $relativePath")
3939
null
4040
}
4141
}
4242

43-
lintFunc?.invoke(file.readText(), ruleSets) { (line, col, detail) ->
43+
lintFunc?.invoke(file, ruleSets) { line, col, detail ->
4444
val errorStr = "$relativePath:$line:$col: $detail"
4545
logger.log(LogLevel.QUIET, "Lint error > $errorStr")
4646
errors += "$errorStr\n"
@@ -56,4 +56,16 @@ open class LintTask : SourceTask() {
5656
report.writeText("ok")
5757
}
5858
}
59+
60+
private fun lintKt(file: File, ruleSets: List<RuleSet>, onError: (line: Int, col: Int, detail: String) -> Unit) {
61+
KtLint.lint(file.readText(), ruleSets) { error ->
62+
onError(error.line, error.col, error.detail)
63+
}
64+
}
65+
66+
private fun lintKts(file: File, ruleSets: List<RuleSet>, onError: (line: Int, col: Int, detail: String) -> Unit) {
67+
KtLint.lintScript(file.readText(), ruleSets) { error ->
68+
onError(error.line, error.col, error.detail)
69+
}
70+
}
5971
}

0 commit comments

Comments
 (0)