Skip to content

Commit

Permalink
feat: add new api for indentation spaces vs. tabs
Browse files Browse the repository at this point in the history
add deprecation warning for old api but keep supporting it

Refs: #794, #2311
  • Loading branch information
simschla committed Nov 28, 2024
1 parent c292510 commit 8a11dd5
Showing 1 changed file with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.util.GradleVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.diffplug.common.base.Preconditions;
import com.diffplug.spotless.FormatterFunc;
Expand Down Expand Up @@ -77,6 +79,9 @@

/** Adds a {@code spotless{Name}Check} and {@code spotless{Name}Apply} task. */
public class FormatExtension {

private static final Logger logger = LoggerFactory.getLogger(FormatExtension.class);

final SpotlessExtension spotless;
final List<Action<FormatExtension>> lazyActions = new ArrayList<>();

Expand Down Expand Up @@ -505,25 +510,53 @@ public void endWithNewline() {
}

/** Ensures that the files are indented using spaces. */
public void leadingTabsToSpaces(int spacesPerTab) {
addStep(IndentStep.Type.SPACE.create(spacesPerTab));
}

@Deprecated
public void indentWithSpaces(int numSpacesPerTab) {
addStep(IndentStep.Type.SPACE.create(numSpacesPerTab));
logDeprecation("indentWithSpaces", "leadingTabsToSpaces");
leadingTabsToSpaces(numSpacesPerTab);
}

/** Ensures that the files are indented using spaces. */
public void indentWithSpaces() {
public void leadingTabsToSpaces() {
addStep(IndentStep.Type.SPACE.create());
}

@Deprecated
public void indentWithSpaces() {
logDeprecation("indentWithSpaces", "leadingTabsToSpaces");
leadingTabsToSpaces();
}

/** Ensures that the files are indented using tabs. */
public void leadingSpacesToTabs(int spacesPerTab) {
addStep(IndentStep.Type.TAB.create(spacesPerTab));
}

@Deprecated
public void indentWithTabs(int tabToSpaces) {
addStep(IndentStep.Type.TAB.create(tabToSpaces));
logDeprecation("indentWithTabs", "leadingSpacesToTabs");
leadingSpacesToTabs(tabToSpaces);
}

/** Ensures that the files are indented using tabs. */
public void indentWithTabs() {
public void leadingSpacesToTabs() {
addStep(IndentStep.Type.TAB.create());
}

@Deprecated
public void indentWithTabs() {
logDeprecation("indentWithTabs", "leadingSpacesToTabs");
leadingSpacesToTabs();
}

private static void logDeprecation(String methodName, String replacement) {
logger.warn("'{}' is deprecated, use '{}' in your gradle build script instead.", methodName, replacement);
}

/** Ensures formatting of files via native binary. */
public void nativeCmd(String name, String pathToExe, List<String> arguments) {
addStep(NativeCmdStep.create(name, new File(pathToExe), arguments));
Expand Down

0 comments on commit 8a11dd5

Please sign in to comment.