How do I format an EK9 file that does not parse?
← Code Formatting · Ref: Q624
Use the -ff flag (force format) to attempt formatting on files that cannot be parsed. Use -fF to force-format all project files.
FORCE FORMAT SINGLE FILE
ek9 -ff myfile.ek9
This attempts to reformat the file even if it contains syntax errors. The formatter applies what corrections it can based on the partial parse.
FORCE FORMAT ALL FILES
ek9 -fF myproject.ek9
This force-formats every .ek9 file in the project, attempting to fix unparseable files.
ALL FOUR FORMAT FLAGS
ek9 -f myfile.ek9 Format single file (must parse). ek9 -F myproject.ek9 Format all project files (must parse). ek9 -ff myfile.ek9 Force format single file (attempts fix). ek9 -fF myproject.ek9 Force format all project files (attempts fix).
WHEN TO USE FORCE FORMAT
- After pasting code from another language that needs significant restructuring.
- When a merge conflict leaves a file in a broken state.
- When indentation has become corrupted (tabs mixed with spaces, wrong levels).
- When AI-generated code has formatting issues that prevent parsing.
LIMITATIONS
Force format makes a best-effort attempt. If the file is severely broken (missing keywords, fundamentally wrong structure), the formatter cannot fully recover it. Always compile after force-formatting to verify the result.
See Q622 for standard single-file formatting. See Q623 for formatting all project files. See Q625 for why EK9 enforces a standard format.
Example
defines module qa.codeformatting.force defines function <?- A well-formatted function. After force-formatting a broken version, it would look like this. -?> sanitizeInput() as pure -> raw as String <- cleaned as String: raw.trim() isNonEmpty() as pure -> text as String <- result as Boolean: text? defines program ForceFormatDemo() stdout <- Stdout() userInput <- " hello world " cleaned <- sanitizeInput(userInput) hasContent <- isNonEmpty(cleaned) stdout.println(`Cleaned: '${cleaned}'`) stdout.println(`Has content: ${hasContent}`)
Common mistakes
E50001 — Removing the variable declaration means later references to the variable become unresolved, triggering E50001. See ek9 -h E50001 for details.
Incorrect:
sanitizeInput(userInput)
Correct:
cleaned <- sanitizeInput(userInput)
Other ways to ask this
- What does ek9 -ff do?
- How do I force-format a broken EK9 file?
- Can the formatter fix syntax errors in my code?
Coming from another language?
Go: gofmt requires valid Go syntax, no force mode. Rust: rustfmt requires valid Rust syntax, no force mode. Python: black requires valid Python syntax. JavaScript: prettier can handle some malformed code. EK9: ek9 -ff provides explicit force-format mode for broken files, a unique capability among language formatters.
Keywords: force, style, error, syntax, ff, indent, fix, recover, fF, format, broken, unparseable