Skip to content

Commit

Permalink
Merge pull request #251 from runningcode/no/col-lines
Browse files Browse the repository at this point in the history
Add line and column numbers to error messages in ktlint.
  • Loading branch information
nedtwigg authored Jun 1, 2018
2 parents c346971 + f681a17 commit 841ee92
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
}

Expand Down

0 comments on commit 841ee92

Please sign in to comment.