diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java index 1e0ee03761..f32f232178 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java @@ -137,7 +137,10 @@ private void addFile(String arg) { // then we'll print the rest that can fit ListIterator iter = lines.listIterator(Math.min(MIN_LINES_PER_FILE, lines.size())); - while (iter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) { + // lines.size() - iter.nextIndex() == 1 means "just one line left", and we just print the line + // instead of "1 more lines that didn't fit" + while (iter.hasNext() && + (numLines < MAX_CHECK_MESSAGE_LINES || lines.size() - iter.nextIndex() == 1)) { addIntendedLine(DIFF_INDENT, iter.next()); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java index 8f55235fea..6c7ceb2aeb 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/DiffMessageFormatterTest.java @@ -393,4 +393,69 @@ public void longFile() throws Exception { " -47␍␊", " ... (1952 more lines that didn't fit)"); } + + @Test + public void oneMoreLineThatDidntFit() throws Exception { + // com.diffplug.spotless.extra.integration.DiffMessageFormatter.MAX_CHECK_MESSAGE_LINES + // defaults to 50, so we create a diff that would be exactly 50 lines long + // The test is to ensure diff does not contain "1 more lines that didn't fit" + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 25; ++i) { + builder.append(i); + builder.append(i < 1 ? "\n" : "\r\n"); + } + SpotlessTask task = create(setFile("testFile").toContent(builder.toString())); + assertTaskFailure(task, + " testFile", + " @@ -1,25 +1,25 @@", + " 0", + " -1␍␊", + " -2␍␊", + " -3␍␊", + " -4␍␊", + " -5␍␊", + " -6␍␊", + " -7␍␊", + " -8␍␊", + " -9␍␊", + " -10␍␊", + " -11␍␊", + " -12␍␊", + " -13␍␊", + " -14␍␊", + " -15␍␊", + " -16␍␊", + " -17␍␊", + " -18␍␊", + " -19␍␊", + " -20␍␊", + " -21␍␊", + " -22␍␊", + " -23␍␊", + " -24␍␊", + " +1␊", + " +2␊", + " +3␊", + " +4␊", + " +5␊", + " +6␊", + " +7␊", + " +8␊", + " +9␊", + " +10␊", + " +11␊", + " +12␊", + " +13␊", + " +14␊", + " +15␊", + " +16␊", + " +17␊", + " +18␊", + " +19␊", + " +20␊", + " +21␊", + " +22␊", + " +23␊", + " +24␊"); + } }