Skip to content

Commit fd07b20

Browse files
authored
Merge pull request #634 from diffplug/feat/remove-questionable-defaults
Remove questionable default targets
2 parents 19b7c39 + d05f9ca commit fd07b20

File tree

15 files changed

+26
-66
lines changed

15 files changed

+26
-66
lines changed

lib/src/main/java/com/diffplug/spotless/cpp/CppDefaults.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2020 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ public class CppDefaults {
3030
* Filter based on Eclipse-CDT <code>org.eclipse.core.contenttype.contentTypes</code>
3131
* extension <code>cSource</code>, <code>cHeader</code>, <code>cxxSource</code> and <code>cxxHeader</code>.
3232
*/
33+
@Deprecated
3334
public static final List<String> FILE_FILTER = Collections.unmodifiableList(
3435
Arrays.asList("c", "h", "C", "cpp", "cxx", "cc", "c++", "h", "hpp", "hh", "hxx", "inc")
3536
.stream().map(s -> {

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1313
### Fixed
1414
* 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))
1515
* `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)).
16+
### Deprecated
17+
* 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).
1618

1719
## [4.4.0] - 2020-06-19
1820
### Added

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CppExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ protected void setupTask(SpotlessTask task) {
6565
* Hence file extension based filtering is used in line with the org.eclipse.core.contenttype.contentTypes<
6666
* defined by the CDT plugin.
6767
*/
68+
noDefaultTarget();
6869
target(CppDefaults.FILE_FILTER.toArray());
6970
}
7071
super.setupTask(task);

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,8 @@ public SpotlessApply createIndependentApplyTask(String taskName) {
671671

672672
return applyTask;
673673
}
674+
675+
protected void noDefaultTarget() {
676+
getProject().getLogger().warn("Spotless: no target set for " + formatName() + ", will be an error in the next release!");
677+
}
674678
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void propertiesFile(Object... files) {
6262
protected void setupTask(SpotlessTask task) {
6363
// defaults to all markdown files
6464
if (target == null) {
65+
noDefaultTarget();
6566
target = parseTarget("**/*.md");
6667
}
6768
super.setupTask(task);

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SqlExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private FormatterStep createStep() {
5757
protected void setupTask(SpotlessTask task) {
5858
if (target == null) {
5959
target("**/*.sql");
60+
noDefaultTarget();
6061
}
6162
super.setupTask(task);
6263
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ private void fixParserToTypescript() {
170170
protected void setupTask(SpotlessTask task) {
171171
// defaults to all typescript files
172172
if (target == null) {
173+
noDefaultTarget();
173174
target = parseTarget("**/*.ts");
174175
}
175176
super.setupTask(task);

plugin-maven/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1010
* `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)).
1111
* Added ANTLR4 support ([#326](https://github.com/diffplug/spotless/issues/326)).
1212
### Removed
13+
* **BREAKING** the default includes for `<typescript>` and `<cpp>` were removed, and will now generate an error if an `<include>` 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.
1314
* **BREAKING** the long-deprecated `<xml>` and `<css>` formats have been removed, in favor of the long-available [`<eclipseWtp>`](https://github.com/diffplug/spotless/tree/main/plugin-maven#eclipse-wtp) step which is available in every generic format.
1415
* This probably doesn't affect you, but if it does, you just need to change `<xml>...` into `<formats><format><eclipseWtp><type>XML</type>...`
1516
* In [`1.15.0` (released 2018-09-23)](#1150---2018-09-23), we added support for `xml` and `css` formats using the Eclipse WTP.

plugin-maven/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ Spotless requires Maven to be running on JRE 8+.
294294
```xml
295295
<configuration>
296296
<cpp>
297-
<!-- You have to set the target manually -->
298-
<includes>
297+
<includes> <!-- You have to set the target manually -->
299298
<include>src/native/**</inclue>
300299
</includes>
301300

@@ -359,8 +358,7 @@ Spotless requires Maven to be running on JRE 8+.
359358
```xml
360359
<configuration>
361360
<typescript>
362-
<!-- These are the defaults, you can override if you want -->
363-
<includes>
361+
<includes> <!-- You have to set the target manually -->
364362
<include>src/**/*.ts</include>
365363
</includes>
366364

plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ private List<File> collectFiles(FormatterFactory formatterFactory) throws MojoEx
148148
Set<String> configuredExcludes = formatterFactory.excludes();
149149

150150
Set<String> includes = configuredIncludes.isEmpty() ? formatterFactory.defaultIncludes() : configuredIncludes;
151+
if (includes.isEmpty()) {
152+
throw new MojoExecutionException("You must specify some files to include, such as '<includes><include>src/**</include></includes>'");
153+
}
151154

152155
Set<String> excludes = new HashSet<>(FileUtils.getDefaultExcludesAsList());
153156
excludes.add(withTrailingSeparator(buildDir.toString()));

0 commit comments

Comments
 (0)