Skip to content

Commit e2662c3

Browse files
committed
fix: add utf-8 encoding to JS line profiler read/write, scope encoding rule
1 parent a575c95 commit e2662c3

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

.claude/rules/code-style.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
- **Docstrings**: Do not add unless explicitly requested
99
- **Naming**: NEVER use leading underscores (`_function_name`) - Python has no true private functions, use public names
1010
- **Paths**: Always use absolute paths
11-
- **Encoding**: Always pass `encoding="utf-8"` to `open()`, `read_text()`, `write_text()`, etc. — Windows defaults to `cp1252` which breaks on non-ASCII content
11+
- **Encoding**: Always pass `encoding="utf-8"` to `open()`, `read_text()`, `write_text()`, etc. in new or changed code — Windows defaults to `cp1252` which breaks on non-ASCII content. Don't flag pre-existing code that lacks it unless you're already modifying that line.

codeflash/languages/javascript/function_optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def line_profiler_step(
175175
logger.warning(f"Language support for {self.language_support.language} doesn't support line profiling")
176176
return {"timings": {}, "unit": 0, "str_out": ""}
177177

178-
original_source = Path(self.function_to_optimize.file_path).read_text()
178+
original_source = self.function_to_optimize.file_path.read_text(encoding="utf-8")
179179
try:
180180
line_profiler_output_path = get_run_tmp_file(Path("line_profiler_output.json"))
181181

@@ -205,7 +205,7 @@ def line_profiler_step(
205205
logger.warning(f"Failed to run line profiling: {e}")
206206
return {"timings": {}, "unit": 0, "str_out": ""}
207207
finally:
208-
Path(self.function_to_optimize.file_path).write_text(original_source)
208+
self.function_to_optimize.file_path.write_text(original_source, encoding="utf-8")
209209

210210
def replace_function_and_helpers_with_optimized_code(
211211
self,

0 commit comments

Comments
 (0)