From 9bd34fdd9858dd95ecfaa73ab405cf61fb35897f Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Fri, 8 Nov 2019 16:59:20 +0300 Subject: [PATCH] Avoid printing (1 more lines that didn't fit) fixes https://github.com/diffplug/spotless/issues/467 --- .../integration/DiffMessageFormatter.java | 5 +- .../spotless/DiffMessageFormatterTest.java | 65 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) 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␊"); + } }