Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message if you try to format a file outside the project directory. #588

Merged
merged 2 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Users can now run `spotlessCheck` and `spotlessApply` in the same build. ([#584](https://github.com/diffplug/spotless/pull/584))
* Fixed intermittent `UnsatisfiedLinkError` in nodejs-based steps. ([#586](https://github.com/diffplug/spotless/pull/586))
* Also, a shared library used by the nodejs steps used to be extracted into the user home directory, but now it is extracted into `{rootProject}/build/spotless-nodejs-cache`.
* Starting in `4.0`, it is no longer possible for a project to format files which are not within its project folder (for example, `:a` can no longer format files in `:b`). We did not explicitly note this in the changelog entry for `4.0`, and we gave a very confusing error message if users tried. We now give a more helpful error message, and this breaking change has been retroactively noted in the changelog for `4.0.0`. ([#588](https://github.com/diffplug/spotless/pull/588))

## [4.0.1] - 2020-05-21
### Fixed
Expand All @@ -21,6 +22,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* Support for the gradle build cache. ([#576](https://github.com/diffplug/spotless/pull/576))
* The local cache will work great, but the remote cache will always miss until [#566](https://github.com/diffplug/spotless/issues/566) is resolved.
### Removed
* **BREAKING** it used to be possible for any project to format files in any other project. For example, `:a` could format files in `:b`. It is now only possible to format files within the project directory. It is okay (but not advised) to format files in subprojects, since they are within the project directory.
* (Power users only) **BREAKING** `void SpotlessTask::setCheck()` and `setApply()` have been removed. ([#576](https://github.com/diffplug/spotless/pull/576))
* Previously, the `check` and `apply` tasks were just marker tasks, and they called `setCheck` and `setApply` on the "worker" task. Now `check` and `apply` are real tasks in their own right, so the marker-task kludge is no longer necessary.
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.gradle.api.tasks.incremental.IncrementalTaskInputs;

import com.diffplug.common.base.Errors;
import com.diffplug.common.base.StringPrinter;
import com.diffplug.spotless.FormatExceptionPolicy;
import com.diffplug.spotless.FormatExceptionPolicyStrict;
import com.diffplug.spotless.Formatter;
Expand Down Expand Up @@ -245,7 +246,11 @@ private void deletePreviousResult(File input) throws IOException {
private File getOutputFile(File input) {
String outputFileName = FormatExtension.relativize(getProject().getProjectDir(), input);
if (outputFileName == null) {
outputFileName = input.getAbsolutePath();
throw new IllegalArgumentException(StringPrinter.buildString(printer -> {
printer.println("Spotless error! All target files must be within the project root. In project " + getProject().getPath());
printer.println(" root dir: " + getProject().getProjectDir().getAbsolutePath());
printer.println(" target: " + input.getAbsolutePath());
}));
}
return new File(outputDirectory, outputFileName);
}
Expand Down