Skip to content

Commit 23faec6

Browse files
committed
feat: add new api for indentation spaces vs. tabs
add deprecation warning for old api but keep supporting it Refs: #794, #2311
1 parent d052416 commit 23faec6

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.gradle.api.plugins.BasePlugin;
4848
import org.gradle.api.tasks.TaskProvider;
4949
import org.gradle.util.GradleVersion;
50+
import org.slf4j.Logger;
51+
import org.slf4j.LoggerFactory;
5052

5153
import com.diffplug.common.base.Preconditions;
5254
import com.diffplug.spotless.FormatExceptionPolicyStrict;
@@ -77,6 +79,9 @@
7779

7880
/** Adds a {@code spotless{Name}Check} and {@code spotless{Name}Apply} task. */
7981
public class FormatExtension {
82+
83+
private static final Logger logger = LoggerFactory.getLogger(FormatExtension.class);
84+
8085
final SpotlessExtension spotless;
8186
final List<Action<FormatExtension>> lazyActions = new ArrayList<>();
8287

@@ -484,25 +489,53 @@ public void endWithNewline() {
484489
}
485490

486491
/** Ensures that the files are indented using spaces. */
492+
public void leadingTabsToSpaces(int spacesPerTab) {
493+
addStep(IndentStep.Type.SPACE.create(spacesPerTab));
494+
}
495+
496+
@Deprecated
487497
public void indentWithSpaces(int numSpacesPerTab) {
488-
addStep(IndentStep.Type.SPACE.create(numSpacesPerTab));
498+
logDeprecation("indentWithSpaces", "leadingTabsToSpaces");
499+
leadingTabsToSpaces(numSpacesPerTab);
489500
}
490501

491502
/** Ensures that the files are indented using spaces. */
492-
public void indentWithSpaces() {
503+
public void leadingTabsToSpaces() {
493504
addStep(IndentStep.Type.SPACE.create());
494505
}
495506

507+
@Deprecated
508+
public void indentWithSpaces() {
509+
logDeprecation("indentWithSpaces", "leadingTabsToSpaces");
510+
leadingTabsToSpaces();
511+
}
512+
496513
/** Ensures that the files are indented using tabs. */
514+
public void leadingSpacesToTabs(int spacesPerTab) {
515+
addStep(IndentStep.Type.TAB.create(spacesPerTab));
516+
}
517+
518+
@Deprecated
497519
public void indentWithTabs(int tabToSpaces) {
498-
addStep(IndentStep.Type.TAB.create(tabToSpaces));
520+
logDeprecation("indentWithTabs", "leadingSpacesToTabs");
521+
leadingSpacesToTabs(tabToSpaces);
499522
}
500523

501524
/** Ensures that the files are indented using tabs. */
502-
public void indentWithTabs() {
525+
public void leadingSpacesToTabs() {
503526
addStep(IndentStep.Type.TAB.create());
504527
}
505528

529+
@Deprecated
530+
public void indentWithTabs() {
531+
logDeprecation("indentWithTabs", "leadingSpacesToTabs");
532+
leadingSpacesToTabs();
533+
}
534+
535+
private static void logDeprecation(String methodName, String replacement) {
536+
logger.warn("'{}' is deprecated, use '{}' in your gradle build script instead.", methodName, replacement);
537+
}
538+
506539
/** Ensures formatting of files via native binary. */
507540
public void nativeCmd(String name, String pathToExe, List<String> arguments) {
508541
addStep(NativeCmdStep.create(name, new File(pathToExe), arguments));

0 commit comments

Comments
 (0)