From be2150cdc1f136ae53b9cd8a6f223ffd621f65c4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 2 Jan 2021 21:49:56 -0800 Subject: [PATCH] Fix prettier bug StringIndexOutOfBoundsException on empty files (noted in #751). --- CHANGES.md | 1 + .../java/com/diffplug/spotless/npm/PrettierFormatterStep.java | 4 ++-- plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ed5a5f0316..14facc6c1a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * fix typo in javadoc comment for SQL\_FORMATTER\_INDENT\_TYPE ([#753](https://github.com/diffplug/spotless/pull/753)) ### Fixed * ktfmt v0.19+ with dropbox-style works again ([#765](https://github.com/diffplug/spotless/pull/765)). +* prettier no longer throws errors on empty files ([#751](https://github.com/diffplug/spotless/pull/751)). ## [2.10.2] - 2020-11-16 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index c65fcf8b8c..ceb6d923b6 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,7 +113,7 @@ public PrettierFilePathPassingFormatterFunc(String prettierConfigOptions, Pretti @Override public String applyWithFile(String unix, File file) throws Exception { - FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length() - 1)) + "[...]' in file '" + file + "'"); + FormattedPrinter.SYSOUT.print("formatting String '" + unix.substring(0, Math.min(50, unix.length())) + "[...]' in file '" + file + "'"); final String prettierConfigOptionsWithFilepath = assertFilepathInConfigOptions(file); return restService.format(unix, prettierConfigOptionsWithFilepath); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c346cffce0..735eecdc9a 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -13,6 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * `ratchetFrom` now works with git-submodule ([#746](https://github.com/diffplug/spotless/issues/746)) * ktfmt v0.19+ with dropbox-style works again ([#765](https://github.com/diffplug/spotless/pull/765)). +* prettier no longer throws errors on empty files ([#751](https://github.com/diffplug/spotless/pull/751)). ## [5.8.2] - 2020-11-16 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fdc7a530c3..0e995edf91 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -15,6 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `ratchetFrom` now works with git-submodule ([#746](https://github.com/diffplug/spotless/issues/746)) * Fix broken test for spotlessFiles parameter on windows ([#737](https://github.com/diffplug/spotless/pull/737)) * ktfmt v0.19+ with dropbox-style works again ([#765](https://github.com/diffplug/spotless/pull/765)). +* prettier no longer throws errors on empty files ([#751](https://github.com/diffplug/spotless/pull/751)). ## [2.6.1] - 2020-11-16 ### Fixed