Skip to content

Commit c7cdc17

Browse files
author
Nelson Osacky
committed
Add line and column numbers to error messages in ktlint.
Fixes #249
1 parent c346971 commit c7cdc17

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ FormatterFunc createFormat() throws Exception {
101101
Class<?> function2Interface = classLoader.loadClass("kotlin.jvm.functions.Function2");
102102
Class<?> lintErrorClass = classLoader.loadClass("com.github.shyiko.ktlint.core.LintError");
103103
Method detailGetter = lintErrorClass.getMethod("getDetail");
104+
Method lineGetter = lintErrorClass.getMethod("getLine");
105+
Method colGetter = lintErrorClass.getMethod("getCol");
104106
Object formatterCallback = Proxy.newProxyInstance(classLoader, new Class[]{function2Interface},
105107
(proxy, method, args) -> {
106108
Object lintError = args[0]; // com.github.shyiko.ktlint.core.LintError
107109
boolean corrected = (Boolean) args[1];
108110
if (!corrected) {
109111
String detail = (String) detailGetter.invoke(lintError);
110-
throw new AssertionError(detail);
112+
int line = (Integer) lineGetter.invoke(lintError);
113+
int col = (Integer) colGetter.invoke(lintError);
114+
throw new AssertionError("Error on line: " + line + " col " + col + "\n" + detail);
111115
}
112116
return null;
113117
});

0 commit comments

Comments
 (0)