diff --git a/CHANGES.md b/CHANGES.md index b38125d63b..a4854266c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ You might be looking for: ### Version 1.27.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/)) +* Revert the change in console display of errors from 1.26.0 ([#485](https://github.com/diffplug/spotless/pull/485)) because [of these problems](https://github.com/diffplug/spotless/pull/485#issuecomment-552925932). + ### Version 1.26.0 - November 11th 2019 (javadoc [lib](https://diffplug.github.io/spotless/javadoc/spotless-lib/1.26.0/) [lib-extra](https://diffplug.github.io/spotless/javadoc/spotless-lib-extra/1.26.0/), artifact [lib]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib), [lib-extra]([jcenter](https://bintray.com/diffplug/opensource/spotless-lib-extra))) * Fix project URLs in poms. ([#478](https://github.com/diffplug/spotless/pull/478)) diff --git a/README.md b/README.md index 1f1f507601..e30742dc81 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,6 @@ Once someone has filled in one square of the formatter/build system matrix, it's - Thanks to [Simon Gamma](https://github.com/simschla) for [adding support for npm-based formatters](https://github.com/diffplug/spotless/pull/283), including `prettier` and `tsfmt`. - Thanks to [Frank Vennemeyer](https://github.com/fvgh) for [Groovy support via greclipse](https://github.com/diffplug/spotless/issues/13), [C++ support via CDT](https://github.com/diffplug/spotless/issues/232), [XML support via WTP](https://github.com/diffplug/spotless/pull/241) and a huge body of work with other eclipse-based formatters. - Thanks to [Konstantin Lutovich](https://github.com/lutovich) for [implementing the maven plugin](https://github.com/diffplug/spotless/pull/188). -- Thanks to [Vladimir Sitnikov](https://github.com/vlsi) for [improving our format error messages](https://github.com/diffplug/spotless/pull/485). - Thanks to [Kevin Brooks](https://github.com/k-brooks) for [updating all eclipse-based formatters to 4.13](https://github.com/diffplug/spotless/pull/482). - Thanks to [Joan Goyeau](https://github.com/joan38) for [fixing scalafmt integration](https://github.com/diffplug/spotless/pull/260). - Thanks to [Nick Sutcliffe](https://github.com/nsutcliffe) for [fixing scalafmt post-2.0](https://github.com/diffplug/spotless/pull/416). 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 449b5b121a..398ccca1ad 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 @@ -18,18 +18,19 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.List; import java.util.ListIterator; import java.util.Objects; +import org.eclipse.jgit.diff.DiffFormatter; import org.eclipse.jgit.diff.EditList; -import org.eclipse.jgit.diff.HistogramDiff; +import org.eclipse.jgit.diff.MyersDiff; import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawTextComparator; +import com.diffplug.common.base.CharMatcher; import com.diffplug.common.base.Errors; import com.diffplug.common.base.Preconditions; import com.diffplug.common.base.Splitter; @@ -138,10 +139,7 @@ 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())); - // 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)) { + while (iter.hasNext() && numLines < MAX_CHECK_MESSAGE_LINES) { addIntendedLine(DIFF_INDENT, iter.next()); } @@ -170,8 +168,7 @@ private void addIntendedLine(String indent, String line) { * sequence (\n, \r, \r\n). */ private static String diff(Builder builder, File file) throws IOException { - Charset encoding = builder.formatter.getEncoding(); - String raw = new String(Files.readAllBytes(file.toPath()), encoding); + String raw = new String(Files.readAllBytes(file.toPath()), builder.formatter.getEncoding()); String rawUnix = LineEnding.toUnix(raw); String formattedUnix; if (builder.isPaddedCell) { @@ -179,21 +176,62 @@ private static String diff(Builder builder, File file) throws IOException { } else { formattedUnix = builder.formatter.compute(rawUnix, file); } - String formatted = builder.formatter.computeLineEndings(formattedUnix, file); - return visualizeDiff(raw, formatted); + + if (rawUnix.equals(formattedUnix)) { + // the formatting is fine, so it's a line-ending issue + String formatted = builder.formatter.computeLineEndings(formattedUnix, file); + return diffWhitespaceLineEndings(raw, formatted, false, true); + } else { + return diffWhitespaceLineEndings(rawUnix, formattedUnix, true, false); + } } - private static String visualizeDiff(String raw, String formattedBytes) throws IOException { - RawText a = new RawText(raw.getBytes(StandardCharsets.UTF_8)); - RawText b = new RawText(formattedBytes.getBytes(StandardCharsets.UTF_8)); - EditList edits = new HistogramDiff().diff(RawTextComparator.DEFAULT, a, b); + /** + * Returns a git-style diff between the two unix strings. + * + * Output has no trailing newlines. + * + * Boolean args determine whether whitespace or line endings will be visible. + */ + private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException { + dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings); + clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings); + + RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8)); + RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8)); + EditList edits = new EditList(); + edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b)); + ByteArrayOutputStream out = new ByteArrayOutputStream(); - // defaultCharset is here so the formatter could select "fancy" or "simple" - // characters for whitespace visualization based on the capabilities of the console - // For instance, if the app is running with file.encoding=ISO-8859-1, then - // the console can't encode fancy whitespace characters, and the formatter would - // resort to simple "\\r", "\\n", and so on - new WriteSpaceAwareDiffFormatter(out, Charset.defaultCharset()).format(edits, a, b); - return new String(out.toByteArray(), StandardCharsets.UTF_8); + try (DiffFormatter formatter = new DiffFormatter(out)) { + formatter.format(edits, a, b); + } + String formatted = out.toString(StandardCharsets.UTF_8.name()); + + // we don't need the diff to show this, since we display newlines ourselves + formatted = formatted.replace("\\ No newline at end of file\n", ""); + return NEWLINE_MATCHER.trimTrailingFrom(formatted); } + + private static final CharMatcher NEWLINE_MATCHER = CharMatcher.is('\n'); + + /** + * Makes the whitespace and/or the lineEndings visible. + * + * MyersDiff wants inputs with only unix line endings. So this ensures that that is the case. + */ + private static String visibleWhitespaceLineEndings(String input, boolean whitespace, boolean lineEndings) { + if (whitespace) { + input = input.replace(' ', MIDDLE_DOT).replace("\t", "\\t"); + } + if (lineEndings) { + input = input.replace("\n", "\\n\n").replace("\r", "\\r"); + } else { + // we want only \n, so if we didn't replace them above, we'll replace them here. + input = input.replace("\r", ""); + } + return input; + } + + private static final char MIDDLE_DOT = '\u00b7'; } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/WriteSpaceAwareDiffFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/WriteSpaceAwareDiffFormatter.java deleted file mode 100644 index a1c1ba3f5e..0000000000 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/WriteSpaceAwareDiffFormatter.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2016 DiffPlug - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.diffplug.spotless.extra.integration; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.StandardCharsets; - -import org.eclipse.jgit.diff.Edit; -import org.eclipse.jgit.diff.EditList; -import org.eclipse.jgit.diff.RawText; -import org.eclipse.jgit.util.IntList; -import org.eclipse.jgit.util.RawParseUtils; - -/** - * Formats the diff in Git-like style, however it makes whitespace visible for - * edit-like diffs (when one fragment is replaced with another). - */ -class WriteSpaceAwareDiffFormatter { - private static final int CONTEXT_LINES = 3; - private static final String MIDDLE_DOT = "\u00b7"; - private static final String CR = "\u240d"; - private static final String LF = "\u240a"; - private static final String TAB = "\u21e5"; - private static final byte[] MIDDLE_DOT_UTF8 = MIDDLE_DOT.getBytes(StandardCharsets.UTF_8); - private static final byte[] CR_UTF8 = CR.getBytes(StandardCharsets.UTF_8); - private static final byte[] LF_UTF8 = LF.getBytes(StandardCharsets.UTF_8); - private static final byte[] TAB_UTF8 = TAB.getBytes(StandardCharsets.UTF_8); - private static final byte[] SPACE_SIMPLE = new byte[]{' '}; - private static final byte[] CR_SIMPLE = new byte[]{'\\', 'r'}; - private static final byte[] LF_SIMPLE = new byte[]{'\\', 'n'}; - private static final byte[] TAB_SIMPLE = new byte[]{'\\', 't'}; - - private final ByteArrayOutputStream out; - private final byte[] middleDot; - private final byte[] cr; - private final byte[] lf; - private final byte[] tab; - - /** - * Creates the formatter. - * @param out output stream for the resulting diff. The diff would have \n line endings - * @param charset the charset that will be used when printing the results for the end user - */ - public WriteSpaceAwareDiffFormatter(ByteArrayOutputStream out, Charset charset) { - this.out = out; - CharsetEncoder charsetEncoder = charset.newEncoder(); - this.middleDot = replacementFor(charsetEncoder, MIDDLE_DOT, MIDDLE_DOT_UTF8, SPACE_SIMPLE); - this.cr = replacementFor(charsetEncoder, CR, CR_UTF8, CR_SIMPLE); - this.lf = replacementFor(charsetEncoder, LF, LF_UTF8, LF_SIMPLE); - this.tab = replacementFor(charsetEncoder, TAB, TAB_UTF8, TAB_SIMPLE); - } - - private static byte[] replacementFor(CharsetEncoder charsetEncoder, String value, byte[] fancy, byte[] simple) { - return charsetEncoder.canEncode(value) ? fancy : simple; - } - - /** - * Formats the diff. - * @param edits the list of edits to format - * @param a input text a, with \n line endings, with UTF-8 encoding - * @param b input text b, with \n line endings, with UTF-8 encoding - * @throws IOException if formatting fails - */ - public void format(EditList edits, RawText a, RawText b) throws IOException { - IntList linesA = RawParseUtils.lineMap(a.getRawContent(), 0, a.getRawContent().length); - IntList linesB = RawParseUtils.lineMap(b.getRawContent(), 0, b.getRawContent().length); - boolean firstLine = true; - for (int i = 0; i < edits.size(); i++) { - Edit edit = edits.get(i); - int lineA = Math.max(0, edit.getBeginA() - CONTEXT_LINES); - int lineB = Math.max(0, edit.getBeginB() - CONTEXT_LINES); - - final int endIdx = findCombinedEnd(edits, i); - final Edit endEdit = edits.get(endIdx); - - int endA = Math.min(a.size(), endEdit.getEndA() + CONTEXT_LINES); - int endB = Math.min(b.size(), endEdit.getEndB() + CONTEXT_LINES); - - if (firstLine) { - firstLine = false; - } else { - out.write('\n'); - } - header(lineA, endA, lineB, endB); - - boolean showWhitespace = edit.getType() == Edit.Type.REPLACE; - - while (lineA < endA || lineB < endB) { - if (lineA < edit.getBeginA()) { - // Common part before the diff - line(' ', a, lineA, linesA, false); - lineA++; - lineB++; - } else if (lineA < edit.getEndA()) { - line('-', a, lineA, linesA, showWhitespace); - lineA++; - } else if (lineB < edit.getEndB()) { - line('+', b, lineB, linesB, showWhitespace); - lineB++; - } else { - // Common part after the diff - line(' ', a, lineA, linesA, false); - lineA++; - lineB++; - } - - if (lineA == edit.getEndA() && lineB == edit.getEndB() && i < endIdx) { - i++; - edit = edits.get(i); - showWhitespace = edit.getType() == Edit.Type.REPLACE; - } - } - } - } - - /** - * There might be multiple adjacent diffs, so we need to figure out the latest one in the group. - * @param edits list of edits - * @param i starting edit - * @return the index of the latest edit in the group - */ - private int findCombinedEnd(EditList edits, int i) { - for (; i < edits.size() - 1; i++) { - Edit current = edits.get(i); - Edit next = edits.get(i + 1); - if (current.getEndA() - next.getBeginA() > 2 * CONTEXT_LINES && - current.getEndB() - next.getBeginB() > 2 * CONTEXT_LINES) { - break; - } - } - return i; - } - - private void header(int lineA, int endA, int lineB, int endB) { - out.write('@'); - out.write('@'); - range('-', lineA + 1, endA - lineA); - range('+', lineB + 1, endB - lineB); - out.write(' '); - out.write('@'); - out.write('@'); - } - - private void range(char prefix, int begin, int length) { - out.write(' '); - out.write(prefix); - if (length == 0) { - writeInt(begin - 1); - out.write(','); - out.write('0'); - } else { - writeInt(begin); - if (length > 1) { - out.write(','); - writeInt(length); - } - } - } - - private void writeInt(int num) { - String str = Integer.toString(num); - for (int i = 0, len = str.length(); i < len; i++) { - out.write(str.charAt(i)); - } - } - - private void line(char prefix, RawText a, int lineA, IntList lines, boolean showWhitespace) throws IOException { - out.write('\n'); - out.write(prefix); - if (!showWhitespace) { - a.writeLine(out, lineA); - return; - } - byte[] bytes = a.getRawContent(); - for (int i = lines.get(lineA + 1), end = lines.get(lineA + 2); i < end; i++) { - byte b = bytes[i]; - if (b == ' ') { - out.write(middleDot); - } else if (b == '\t') { - out.write(tab); - } else if (b == '\r') { - out.write(cr); - } else if (b == '\n') { - out.write(lf); - } else { - out.write(b); - } - } - } -} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index bfc56873c1..3a6f0afc80 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -2,6 +2,8 @@ ### Version 3.27.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/)) +* Revert the change in console display of errors from 3.26.0 ([#485](https://github.com/diffplug/spotless/pull/485)) because [of these problems](https://github.com/diffplug/spotless/pull/485#issuecomment-552925932). + ### Version 3.26.0 - November 11th 2019 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-plugin-gradle/3.26.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-plugin-gradle/3.26.0)) * Fix project URLs in poms. ([#478](https://github.com/diffplug/spotless/pull/478)) 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 6c7ceb2aeb..a46f9f9824 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 @@ -77,12 +77,12 @@ public void lineEndingProblem() throws Exception { assertTaskFailure(task, " testFile", " @@ -1,3 +1,3 @@", - " -A␍␊", - " -B␍␊", - " -C␍␊", - " +A␊", - " +B␊", - " +C␊"); + " -A\\r\\n", + " -B\\r\\n", + " -C\\r\\n", + " +A\\n", + " +B\\n", + " +C\\n"); } @Test @@ -95,85 +95,12 @@ public void whitespaceProblem() throws Exception { assertTaskFailure(task, " testFile", " @@ -1,3 +1,3 @@", - " -A·␊", - " -B⇥␊", - " -C··␊", - " +A␊", - " +B␊", - " +C␊"); - } - - @Test - public void whitespaceProblem2() throws Exception { - SpotlessTask task = create(setFile("testFile").toContent( - "u0\nu 1\nu 2\nu 3\n" + - "\t leading space\n" + - "trailing space\t \n" + - "u 4\n" + - " leading and trailing space \n" + - "u 5\nu 6")); - task.addStep(FormatterStep.createNeverUpToDate("trimTrailing", input -> { - Pattern pattern = Pattern.compile("(^[ \t]+)|([ \t]+$)", Pattern.UNIX_LINES | Pattern.MULTILINE); - return pattern.matcher(input).replaceAll(""); - })); - assertTaskFailure(task, - " testFile", - " @@ -2,9 +2,9 @@", - " u 1", - " u 2", - " u 3", - " -⇥·leading·space␊", - " -trailing·space⇥·␊", - " +leading·space␊", - " +trailing·space␊", - " u 4", - " -··leading·and·trailing·space··␊", - " +leading·and·trailing·space␊", - " u 5", - " u 6"); - } - - @Test - public void singleLineCr() throws Exception { - SpotlessTask task = create(setFile("testFile").toContent( - "line without line ending")); - task.addStep(FormatterStep.createNeverUpToDate("trimTrailing", - input -> input.endsWith("\n") ? input : input + "\n")); - assertTaskFailure(task, - " testFile", - " @@ -1 +1 @@", - " -line·without·line·ending", - " +line·without·line·ending␊"); - } - - @Test - public void singleLineUnnecessaryCr() throws Exception { - SpotlessTask task = create(setFile("testFile").toContent( - "line without line ending\r\n")); - task.addStep(FormatterStep.createNeverUpToDate("trimTrailing", - input -> input.replaceAll("[\r\n]+$", ""))); - assertTaskFailure(task, - " testFile", - " @@ -1 +1 @@", - " -line·without·line·ending␍␊", - " +line·without·line·ending"); - } - - @Test - public void trailingWhitespaceAndCRLF() throws Exception { - SpotlessTask task = create(setFile("testFile").toContent( - "line 1\ntrailing whitespace \nline with CRLF\r\nline 2")); - task.addStep(FormatterStep.createNeverUpToDate("trimTrailing", - input -> input.replaceAll("[\r ]+\n", "\n"))); - assertTaskFailure(task, - " testFile", - " @@ -1,4 +1,4 @@", - " line 1", - " -trailing·whitespace··␊", - " -line·with·CRLF␍␊", - " +trailing·whitespace␊", - " +line·with·CRLF␊", - " line 2"); + " -A·", + " -B\\t", + " -C··", + " +A", + " +B", + " +C"); } @Test @@ -184,15 +111,15 @@ public void multipleFiles() throws Exception { assertTaskFailure(task, " A", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " B", " @@ -1,2 +1,2 @@", - " 3", - " -4␍␊", - " +4␊"); + " 3\\n", + " -4\\r\\n", + " +4\\n"); } @Test @@ -205,56 +132,56 @@ public void manyFiles() throws Exception { assertTaskFailure(task, " 0.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 1.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 2.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 3.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 4.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 5.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 6.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 7.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 8.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", + " -1\\r\\n", + " -2\\r\\n", " ... (2 more lines that didn't fit)", "Violations also present in:", " 9.txt", @@ -278,56 +205,56 @@ public void manyManyFiles() throws Exception { assertTaskFailure(task, " 0.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 1.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 2.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 3.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 4.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 5.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 6.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 7.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", - " +1␊", - " +2␊", + " -1\\r\\n", + " -2\\r\\n", + " +1\\n", + " +2\\n", " 8.txt", " @@ -1,2 +1,2 @@", - " -1␍␊", - " -2␍␊", + " -1\\r\\n", + " -2\\r\\n", " ... (2 more lines that didn't fit)", "Violations also present in " + DiffMessageFormatter.MAX_FILES_TO_LIST + " other files."); } @@ -343,119 +270,54 @@ public void longFile() throws Exception { assertTaskFailure(task, " testFile", " @@ -1,1000 +1,1000 @@", - " -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␍␊", - " -25␍␊", - " -26␍␊", - " -27␍␊", - " -28␍␊", - " -29␍␊", - " -30␍␊", - " -31␍␊", - " -32␍␊", - " -33␍␊", - " -34␍␊", - " -35␍␊", - " -36␍␊", - " -37␍␊", - " -38␍␊", - " -39␍␊", - " -40␍␊", - " -41␍␊", - " -42␍␊", - " -43␍␊", - " -44␍␊", - " -45␍␊", - " -46␍␊", - " -47␍␊", + " -0\\r\\n", + " -1\\r\\n", + " -2\\r\\n", + " -3\\r\\n", + " -4\\r\\n", + " -5\\r\\n", + " -6\\r\\n", + " -7\\r\\n", + " -8\\r\\n", + " -9\\r\\n", + " -10\\r\\n", + " -11\\r\\n", + " -12\\r\\n", + " -13\\r\\n", + " -14\\r\\n", + " -15\\r\\n", + " -16\\r\\n", + " -17\\r\\n", + " -18\\r\\n", + " -19\\r\\n", + " -20\\r\\n", + " -21\\r\\n", + " -22\\r\\n", + " -23\\r\\n", + " -24\\r\\n", + " -25\\r\\n", + " -26\\r\\n", + " -27\\r\\n", + " -28\\r\\n", + " -29\\r\\n", + " -30\\r\\n", + " -31\\r\\n", + " -32\\r\\n", + " -33\\r\\n", + " -34\\r\\n", + " -35\\r\\n", + " -36\\r\\n", + " -37\\r\\n", + " -38\\r\\n", + " -39\\r\\n", + " -40\\r\\n", + " -41\\r\\n", + " -42\\r\\n", + " -43\\r\\n", + " -44\\r\\n", + " -45\\r\\n", + " -46\\r\\n", + " -47\\r\\n", " ... (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␊"); - } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ad0e91695c..9ecbe1418e 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -2,6 +2,8 @@ ### Version 1.27.0-SNAPSHOT - TBD ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/spotless/spotless-maven-plugin/)) +* Revert the change in console display of errors from 1.26.0 ([#485](https://github.com/diffplug/spotless/pull/485)) because [of these problems](https://github.com/diffplug/spotless/pull/485#issuecomment-552925932). + ### Version 1.26.0 - November 11th 2019 ([javadoc](https://diffplug.github.io/spotless/javadoc/spotless-maven-plugin/1.26.0/), [jcenter](https://bintray.com/diffplug/opensource/spotless-maven-plugin/1.26.0)) * Fix project URLs in poms. ([#478](https://github.com/diffplug/spotless/pull/478))