Skip to content

Commit 213cd28

Browse files
Ensure utf-8 encoding is used (#34)
* Fix issue where a certain .cgx file was making this ruff-cgx crash Related Issue #32
1 parent aacde78 commit 213cd28

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

ruff_cgx/linter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ def lint_file(path, fix=False):
9494

9595
assert fix is True
9696
# Run ruff check with fix
97-
_, fixed_content = run_ruff_check(virtual_content, fix=fix)
98-
assert fixed_content
97+
result, fixed_content = run_ruff_check(virtual_content, fix=fix)
98+
assert fixed_content, (
99+
f"ruff check --fix returned no output (exit code {result.returncode}). "
100+
f"stderr: {result.stderr}"
101+
)
99102

100103
# Apply fixes if we got fixed content
101104
fixed_file_content = _apply_fixes_to_file(

ruff_cgx/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ def is_isort_configured() -> bool:
247247
try:
248248
# Print ruff settings
249249
ruff_output = subprocess.run(
250-
["ruff", "check", "--show-settings"], capture_output=True, text=True
250+
["ruff", "check", "--show-settings"],
251+
capture_output=True,
252+
text=True,
253+
encoding="utf-8",
251254
).stdout
252255

253256
# Get both the enabled + should_fix sections
@@ -312,6 +315,7 @@ def run_ruff_format(
312315
input=source,
313316
capture_output=True,
314317
text=True,
318+
encoding="utf-8",
315319
)
316320
# Use the fixed output if available, otherwise use original
317321
if result.returncode == 0 or result.stdout:
@@ -345,6 +349,7 @@ def run_ruff_format(
345349
input=source,
346350
capture_output=True,
347351
text=True,
352+
encoding="utf-8",
348353
)
349354

350355
if result.returncode == 0 or not check:
@@ -387,6 +392,7 @@ def run_ruff_check(
387392
input=source,
388393
capture_output=True,
389394
text=True,
395+
encoding="utf-8",
390396
timeout=30,
391397
)
392398

0 commit comments

Comments
 (0)