mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Add support for ruff-ecosystem
format comparisons with black
(#8419)
Extends https://github.com/astral-sh/ruff/pull/8416 activating the `black-and-ruff` and `black-then-ruff` formatter comparison modes for ecosystem checks allowing us to compare changes to Black across the ecosystem.
This commit is contained in:
parent
2f7e2a8de3
commit
ebad36da06
8 changed files with 75 additions and 48 deletions
|
@ -49,7 +49,7 @@ class CommandOptions(Serializable, abc.ABC):
|
|||
return type(self)(**{**dataclasses.asdict(self), **kwargs})
|
||||
|
||||
@abc.abstractmethod
|
||||
def to_cli_args(self) -> list[str]:
|
||||
def to_ruff_args(self) -> list[str]:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ class CheckOptions(CommandOptions):
|
|||
# Limit the number of reported lines per rule
|
||||
max_lines_per_rule: int | None = 50
|
||||
|
||||
def to_cli_args(self) -> list[str]:
|
||||
def to_ruff_args(self) -> list[str]:
|
||||
args = ["check", "--no-cache", "--exit-zero"]
|
||||
if self.select:
|
||||
args.extend(["--select", self.select])
|
||||
|
@ -88,13 +88,13 @@ class CheckOptions(CommandOptions):
|
|||
@dataclass(frozen=True)
|
||||
class FormatOptions(CommandOptions):
|
||||
"""
|
||||
Ruff format options.
|
||||
Format ecosystem check options.
|
||||
"""
|
||||
|
||||
preview: bool = False
|
||||
exclude: str = ""
|
||||
|
||||
def to_cli_args(self) -> list[str]:
|
||||
def to_ruff_args(self) -> list[str]:
|
||||
args = ["format"]
|
||||
if self.exclude:
|
||||
args.extend(["--exclude", self.exclude])
|
||||
|
@ -102,6 +102,14 @@ class FormatOptions(CommandOptions):
|
|||
args.append("--preview")
|
||||
return args
|
||||
|
||||
def to_black_args(self) -> list[str]:
|
||||
args = []
|
||||
if self.exclude:
|
||||
args.extend(["--exclude", self.exclude])
|
||||
if self.preview:
|
||||
args.append("--preview")
|
||||
return args
|
||||
|
||||
|
||||
class ProjectSetupError(Exception):
|
||||
"""An error setting up a project."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue