diff --git a/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java b/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java index 3ab34ab28b..1492ea32e4 100644 --- a/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java +++ b/lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ public class CppDefaults { * Filter based on Eclipse-CDT org.eclipse.core.contenttype.contentTypes * extension cSource, cHeader, cxxSource and cxxHeader. */ + @Deprecated public static final List FILE_FILTER = Collections.unmodifiableList( Arrays.asList("c", "h", "C", "cpp", "cxx", "cc", "c++", "h", "hpp", "hh", "hxx", "inc") .stream().map(s -> { diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 9e5e1761f5..969825d999 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -13,6 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Fixed * LineEndings.GIT_ATTRIBUTES is now a bit more efficient, and paves the way for remote build cache support in Gradle. ([#621](https://github.com/diffplug/spotless/pull/621)) * `ratchetFrom` now ratchets from the merge base of `HEAD` and the specified branch. This fixes the surprising behavior when a remote branch advanced ([#631](https://github.com/diffplug/spotless/pull/631) fixes [#627](https://github.com/diffplug/spotless/issues/627)). +### Deprecated +* The default targets for `C/C++`, `freshmark`, `sql`, and `typescript` now generate a warning, asking the user to specify a target manually. There is no well-established convention for these languages in the gradle ecosystem, and the performance of the default target is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634). ## [4.4.0] - 2020-06-19 ### Added diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java index 74f43600ae..11791b3693 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java @@ -65,6 +65,7 @@ protected void setupTask(SpotlessTask task) { * Hence file extension based filtering is used in line with the org.eclipse.core.contenttype.contentTypes< * defined by the CDT plugin. */ + noDefaultTarget(); target(CppDefaults.FILE_FILTER.toArray()); } super.setupTask(task); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index b1158c46c0..d98b0a7c0b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -671,4 +671,8 @@ public SpotlessApply createIndependentApplyTask(String taskName) { return applyTask; } + + protected void noDefaultTarget() { + getProject().getLogger().warn("Spotless: no target set for " + formatName() + ", will be an error in the next release!"); + } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java index e8e130d6e2..187278798c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java @@ -62,6 +62,7 @@ public void propertiesFile(Object... files) { protected void setupTask(SpotlessTask task) { // defaults to all markdown files if (target == null) { + noDefaultTarget(); target = parseTarget("**/*.md"); } super.setupTask(task); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java index 5f2e0dc4ea..dbc3565d2c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java @@ -57,6 +57,7 @@ private FormatterStep createStep() { protected void setupTask(SpotlessTask task) { if (target == null) { target("**/*.sql"); + noDefaultTarget(); } super.setupTask(task); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 1378d7b0df..c370d992a5 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -170,6 +170,7 @@ private void fixParserToTypescript() { protected void setupTask(SpotlessTask task) { // defaults to all typescript files if (target == null) { + noDefaultTarget(); target = parseTarget("**/*.ts"); } super.setupTask(task); diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8603a0e0d3..f5304b2447 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `prettier` will now autodetect the parser (and formatter) to use based on the filename, unless you override this using `config` or `configFile` with the option `parser` or `filepath` ([#620](https://github.com/diffplug/spotless/pull/620)). * Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)). ### Removed +* **BREAKING** the default includes for `` and `` were removed, and will now generate an error if an `` is not specified. There is no well-established convention for these languages in the maven ecosystem, and the performance of the default includes is far worse than a user-provided one. If you dislike this change, please complain in [#634](https://github.com/diffplug/spotless/pull/634), it would not be a breaking change to bring the defaults back. * **BREAKING** the long-deprecated `` and `` formats have been removed, in favor of the long-available [``](https://github.com/diffplug/spotless/tree/main/plugin-maven#eclipse-wtp) step which is available in every generic format. * This probably doesn't affect you, but if it does, you just need to change `...` into `XML...` * In [`1.15.0` (released 2018-09-23)](#1150---2018-09-23), we added support for `xml` and `css` formats using the Eclipse WTP. diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 675ff23a9f..2782fbfee6 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -294,8 +294,7 @@ Spotless requires Maven to be running on JRE 8+. ```xml - - + src/native/** @@ -359,8 +358,7 @@ Spotless requires Maven to be running on JRE 8+. ```xml - - + src/**/*.ts diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 98ae47c788..caacf51e47 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -148,6 +148,9 @@ private List collectFiles(FormatterFactory formatterFactory) throws MojoEx Set configuredExcludes = formatterFactory.excludes(); Set includes = configuredIncludes.isEmpty() ? formatterFactory.defaultIncludes() : configuredIncludes; + if (includes.isEmpty()) { + throw new MojoExecutionException("You must specify some files to include, such as 'src/**'"); + } Set excludes = new HashSet<>(FileUtils.getDefaultExcludesAsList()); excludes.add(withTrailingSeparator(buildDir.toString())); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java index 49bd3e84a4..aca062425d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/cpp/Cpp.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,8 @@ */ package com.diffplug.spotless.maven.cpp; -import java.util.Arrays; -import java.util.Collection; +import java.util.Collections; import java.util.Set; -import java.util.stream.Collectors; import com.diffplug.spotless.cpp.CppDefaults; import com.diffplug.spotless.maven.FormatterFactory; @@ -31,15 +29,9 @@ * and cpp-specific (e.g. {@link Eclipse}) steps. */ public class Cpp extends FormatterFactory { - - private static final Set DEFAULT_INCLUDES = CppDefaults.FILE_FILTER - .stream().map(s -> { - return Arrays.asList("src/main/cpp/" + s, "src/test/cpp/" + s); - }).flatMap(Collection::stream).collect(Collectors.toSet()); - @Override public Set defaultIncludes() { - return DEFAULT_INCLUDES; + return Collections.emptySet(); } public void addEclipse(Eclipse eclipse) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java index e2cd953268..387f1e0a70 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/typescript/Typescript.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2020 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,9 @@ */ package com.diffplug.spotless.maven.typescript; +import java.util.Collections; import java.util.Set; -import com.diffplug.common.collect.ImmutableSet; import com.diffplug.spotless.maven.FormatterFactory; /** @@ -26,14 +26,11 @@ * It defines a formatter for typescript source files. */ public class Typescript extends FormatterFactory { - - private static final Set DEFAULT_INCLUDES = ImmutableSet.of("src/**/*.ts"); - private static final String LICENSE_HEADER_DELIMITER = null; @Override public Set defaultIncludes() { - return DEFAULT_INCLUDES; + return Collections.emptySet(); } @Override @@ -44,5 +41,4 @@ public String licenseHeaderDelimiter() { public void addTsfmt(Tsfmt tsfmt) { addStepFactory(tsfmt); } - } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 52211054df..7934cb3d69 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -119,7 +119,7 @@ protected void writePomWithCppSteps(String... steps) throws IOException { } protected void writePomWithTypescriptSteps(String... steps) throws IOException { - writePom(groupWithSteps("typescript", steps)); + writePom(groupWithSteps("typescript", including("**/*.ts"), steps)); } protected void writePomWithPrettierSteps(String includes, String... steps) throws IOException { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/cpp/CppTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/cpp/CppTest.java deleted file mode 100644 index 7a4f0a22e4..0000000000 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/cpp/CppTest.java +++ /dev/null @@ -1,42 +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.maven.cpp; - -import static org.junit.Assert.assertEquals; - -import org.codehaus.plexus.util.FileUtils; -import org.junit.Test; - -import com.diffplug.spotless.ResourceHarness; - -public class CppTest extends ResourceHarness { - - @Test - public void testDefaultIncludes() throws Exception { - Cpp cpp = new Cpp(); - cpp.defaultIncludes(); - - String includesString = String.join(",", cpp.defaultIncludes()); - setFile("src/main/cpp/file.c++").toContent(""); - setFile("src/file.c++").toContent(""); - setFile("src/main/cpp/file.dummy").toContent(""); - setFile("src/test/cpp/file.h").toContent(""); - setFile("src/test/cpp/file.dummy").toContent(""); - - assertEquals(2, FileUtils.getFiles(rootFolder(), includesString, "").size()); - - } -} diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java index 627b3e994b..ffdced0c98 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/generic/LicenseHeaderTest.java @@ -37,6 +37,7 @@ public void fromFileJava() throws Exception { public void fromContentCpp() throws Exception { String cppLicense = "//my license"; writePomWithCppSteps( + "src/**", "", " ", cppLicense,