diff --git a/CHANGES.md b/CHANGES.md index 1b2e1a7f9b..6c081e6347 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ You might be looking for: ### Version 1.13.0-SNAPSHOT - TBD (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/snapshot/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/snapshot/), [snapshot repo](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/)) +* Add line and column numbers to ktlint errors. ([#251](https://github.com/diffplug/spotless/pull/251)) + ### Version 1.12.0 - May 14th 2018 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.11.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.12.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) * Fixed a bug in `LicenseHeaderStep` which caused an exception with some malformed date-aware licenses. ([#222](https://github.com/diffplug/spotless/pull/222)) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 7762d4bb1a..5f3dff5d86 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -101,13 +101,17 @@ FormatterFunc createFormat() throws Exception { Class function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2"); Class lintErrorClass = classLoader.loadClass("com.github.shyiko.ktlint.core.LintError"); Method detailGetter = lintErrorClass.getMethod("getDetail"); + Method lineGetter = lintErrorClass.getMethod("getLine"); + Method colGetter = lintErrorClass.getMethod("getCol"); Object formatterCallback = Proxy.newProxyInstance(classLoader, new Class[]{function2Interface}, (proxy, method, args) -> { Object lintError = args[0]; // com.github.shyiko.ktlint.core.LintError boolean corrected = (Boolean) args[1]; if (!corrected) { String detail = (String) detailGetter.invoke(lintError); - throw new AssertionError(detail); + int line = (Integer) lineGetter.invoke(lintError); + int col = (Integer) colGetter.invoke(lintError); + throw new AssertionError("Error on line: " + line + ", column: " + col + "\n" + detail); } return null; }); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index d5dc45392e..8cf862fde6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -2,6 +2,8 @@ ### Version 3.13.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-plugin-gradle/)) +* Add line and column numbers to ktlint errors. ([#251](https://github.com/diffplug/spotless/pull/251)) + ### Version 3.12.0 - May 14th 2018 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.11.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.11.0)) * Migrated `plugin-gradle`'s tests away from `TaskInternal#execute` to a custom method to help with Gradle 5.0 migration later on. ([#208](https://github.com/diffplug/spotless/pull/208)) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 931d5f7a65..258fad4677 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -33,7 +33,8 @@ public void behavior() throws Exception { .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testException("kotlin/ktlint/unsolvable.dirty", assertion -> { assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("Wildcard import"); + assertion.hasMessage("Error on line: 1, column: 1\n" + + "Wildcard import"); }); }