Skip to content

fix: pass language to format_generated_code for correct temp file extension#1896

Merged
mohammedahmed18 merged 1 commit intomainfrom
cf-fix-formatter-temp-file-extension
Mar 25, 2026
Merged

fix: pass language to format_generated_code for correct temp file extension#1896
mohammedahmed18 merged 1 commit intomainfrom
cf-fix-formatter-temp-file-extension

Conversation

@mohammedahmed18
Copy link
Copy Markdown
Contributor

Summary

  • format_generated_code was called without the language parameter in process_review(), defaulting to "python". This created temp files with .py extension when formatting JS/TS code, causing npx prettier --write to fail on 73/1026 Strapi optimization runs.
  • Pass language=code_lang (from self.function_to_optimize.language) to both call sites.

Trace IDs

11e9745d, 1578f081, 158297d4, 7e8abab2 (73 affected logs total)

Test plan

  • Added unit tests verifying correct file extensions for JavaScript, TypeScript, and Python
  • All 46 formatter tests pass
  • prek passes

🤖 Generated with Claude Code

…ension

format_generated_code was called without the language parameter in
process_review(), defaulting to "python". This created temp files with
.py extension when formatting JS/TS code, causing prettier to fail.

Trace IDs: 11e9745d, 1578f081, 7e8abab2 (73 affected logs total)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 25, 2026

Claude finished @mohammedahmed18's task in 2m 47s —— View job


PR Review Summary

Prek Checks

All checks pass (ruff lint, ruff format).

Code Review

Fix is correct. Both call sites of format_generated_code in process_review() now pass language=code_lang, where code_lang = self.function_to_optimize.language (a str). This matches the parameter type (language: str = "python") in the formatter. No other call sites exist — confirmed via grep.

Minor: Unused variables in test (tests/test_formatter.py, lines 1405–1406)

captured_paths = []              # never used
original_apply = format_code.__module__  # never used

These appear to be leftover from an earlier draft of test_format_generated_code_uses_correct_extension_for_javascript. They don't affect correctness but are dead code. Fix this →

Duplicate Detection

No duplicates detected — format_generated_code has exactly 2 call sites and both are fixed in this PR.

Test Coverage

Three new unit tests added covering JavaScript, TypeScript, and Python default extension. Tests correctly mock apply_formatter_cmds and assert on the temp file path suffix passed to it.


Last updated: 2026-03-25T16:08Z

@mohammedahmed18 mohammedahmed18 merged commit 607200a into main Mar 25, 2026
28 of 29 checks passed
@mohammedahmed18 mohammedahmed18 deleted the cf-fix-formatter-temp-file-extension branch March 25, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants