Repository: pantsbuild/pants

Issue:
Deprecate using default `--fmt-transitive` and `--lint-transitive` in preparation for switching default to `--no-{fmt,lint}-transitive`
### Problem

Will close https://github.com/pantsbuild/pants/issues/8345.

These options cause tools like isort and Scalafmt to work on the transitive dependencies of the targets you specify, rather than only the targets specified. This is surprising and not how the tools work when called directly—you'd expect isort to only change the files you pass to it, for example.

We decided when adding this option to the V2 rules (https://github.com/pantsbuild/pants/pull/8660) that instead we should deprecate this misfeature.

However, we cannot simply deprecate the option in one fell-swoop because then people who are trying to prepare for the default behavior changing to `--no-transitive` will be met with a deprecation warning that the option will be removed. Leaving off the option so that there's no deprecation warning means that they will have a breaking behavior change in 1.25.0.dev2 when we no longer act transitively.

### Solution

For this deprecation cycle, only warn that the default will change if they are currently relying on the default.

In 1.25.0.dev2, after the default changes, _then_ we can safely deprecate the option outright.

### Result

Users who specified the option get this warning message:


> [WARN] /Users/eric/DocsLocal/code/projects/pants/src/python/pants/task/task.py:265: DeprecationWarning: DEPRECATED: Pants defaulting to --fmt-transitive and --lint-transitive will be removed in version 1.25.0.dev2.
  Pants will soon default to --no-fmt-transitive and --no-lint-transitive. Currently, Pants defaults to `--fmt-transitive` and `--lint-transitive`, which means that tools like isort and Scalafmt will work on transitive dependencies as well. This behavior is unexpected. Normally when running tools like isort, you'd expect them to only work on the files you specify.
> 
> To prepare, please add to your `pants.ini` under both the `fmt` and the `lint` sections the option `transitive: False`. If you want to keep the default, use `True`, although the option will be removed in Pants 1.27.0.dev2


Discussion:

Resolving patch:
diff --git a/src/python/pants/task/target_restriction_mixins.py b/src/python/pants/task/target_restriction_mixins.py
--- a/src/python/pants/task/target_restriction_mixins.py
+++ b/src/python/pants/task/target_restriction_mixins.py
@@ -23,20 +23,6 @@ class HasTransitiveOptionMixin:
 
   @property
   def act_transitively(self):
-    deprecated_conditional(
-      lambda: self.get_options().is_default("transitive"),
-      removal_version="1.25.0.dev2",
-      entity_description="Pants defaulting to `--fmt-transitive` and `--lint-transitive`",
-      hint_message="Pants will soon default to `--no-fmt-transitive` and `--no-lint-transitive`. "
-                   "Currently, Pants defaults to `--fmt-transitive` and `--lint-transitive`, which "
-                   "means that tools like isort and Scalafmt will work on transitive dependencies "
-                   "as well. This behavior is unexpected. Normally when running tools like isort, "
-                   "you'd expect them to only work on the files you specify.\n\nTo prepare, "
-                   "please add to your `pants.ini` under both the `fmt` and the `lint` "
-                   "sections the option `transitive: False`. If you want to keep the default, use "
-                   "`True`, although we recommend setting to `False` as the `--transitive` option "
-                   "will be removed in a future Pants version."
-    )
     return self.get_options().transitive
 
 
@@ -83,7 +69,24 @@ class HasSkipAndTransitiveOptionsMixin(HasSkipOptionMixin, HasTransitiveOptionMi
 
 class HasSkipAndTransitiveGoalOptionsMixin(GoalOptionsMixin, HasSkipAndTransitiveOptionsMixin):
   """A mixin for tasks that have a --transitive and a --skip option registered at the goal level."""
-  pass
+
+  @property
+  def act_transitively(self):
+    deprecated_conditional(
+      lambda: self.get_options().is_default("transitive"),
+      removal_version="1.25.0.dev2",
+      entity_description="Pants defaulting to `--fmt-transitive` and `--lint-transitive`",
+      hint_message="Pants will soon default to `--no-fmt-transitive` and `--no-lint-transitive`. "
+                   "Currently, Pants defaults to `--fmt-transitive` and `--lint-transitive`, which "
+                   "means that tools like isort and Scalafmt will work on transitive dependencies "
+                   "as well. This behavior is unexpected. Normally when running tools like isort, "
+                   "you'd expect them to only work on the files you specify.\n\nTo prepare, "
+                   "please add to your `pants.ini` under both the `fmt` and the `lint` "
+                   "sections the option `transitive: False`. If you want to keep the default, use "
+                   "`True`, although we recommend setting to `False` as the `--transitive` option "
+                   "will be removed in a future Pants version."
+    )
+    return self.get_options().transitive
 
 
 class SkipAndTransitiveOptionsRegistrar(SkipOptionRegistrar, TransitiveOptionRegistrar):


Test patch: