Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/datamodel_code_generator/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def apply_black(self, code: str) -> str:
def apply_ruff_lint(self, code: str) -> str:
"""Run ruff check with auto-fix on code."""
result = subprocess.run(
("ruff", "check", "--fix", "-"),
("ruff", "check", "--fix", "--unsafe-fixes", "-"),
input=code.encode(self.encoding),
capture_output=True,
check=False,
Expand All @@ -361,7 +361,7 @@ def apply_ruff_check_and_format(self, code: str) -> str:
"""Run ruff check and format in a single pipeline for better performance."""
ruff_path = self._find_ruff_path()
check_proc = subprocess.Popen( # noqa: S603
[ruff_path, "check", "--fix", "-"],
[ruff_path, "check", "--fix", "--unsafe-fixes", "-"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand Down Expand Up @@ -407,7 +407,7 @@ def format_directory(self, directory: Path) -> None:
"""Apply ruff formatting to all Python files in a directory."""
if Formatter.RUFF_CHECK in self.formatters:
subprocess.run( # noqa: S603
("ruff", "check", "--fix", str(directory)),
("ruff", "check", "--fix", "--unsafe-fixes", str(directory)),
capture_output=True,
check=False,
cwd=self.settings_path,
Expand Down
12 changes: 8 additions & 4 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ def test_format_code_ruff_check_formatter(tmp_path: Path, monkeypatch: pytest.Mo

assert formatted_code == "output"
mock_run.assert_called_once_with(
("ruff", "check", "--fix", "-"), input=b"input", capture_output=True, check=False, cwd=str(tmp_path)
("ruff", "check", "--fix", "--unsafe-fixes", "-"),
input=b"input",
capture_output=True,
check=False,
cwd=str(tmp_path),
)


Expand Down Expand Up @@ -227,7 +231,7 @@ def test_format_directory_ruff_check(tmp_path: Path, monkeypatch: pytest.MonkeyP
formatter.format_directory(output_dir)

mock_run.assert_called_once_with(
("ruff", "check", "--fix", str(output_dir)),
("ruff", "check", "--fix", "--unsafe-fixes", str(output_dir)),
capture_output=True,
check=False,
cwd=str(tmp_path),
Expand Down Expand Up @@ -270,7 +274,7 @@ def test_format_directory_both_ruff_formatters(tmp_path: Path, monkeypatch: pyte

assert mock_run.call_count == 2
mock_run.assert_any_call(
("ruff", "check", "--fix", str(output_dir)),
("ruff", "check", "--fix", "--unsafe-fixes", str(output_dir)),
capture_output=True,
check=False,
cwd=str(tmp_path),
Expand Down Expand Up @@ -323,7 +327,7 @@ def test_generate_with_ruff_batch_formatting(tmp_path: Path) -> None:

assert mock_run.call_count == 2
mock_run.assert_any_call(
("ruff", "check", "--fix", str(output_dir)),
("ruff", "check", "--fix", "--unsafe-fixes", str(output_dir)),
capture_output=True,
check=False,
cwd=mock.ANY,
Expand Down
Loading