How do I format all EK9 source files in my project?
← Code Formatting · Ref: Q623
Use the -F flag (uppercase) to format all EK9 source files in the project at once.
BASIC USAGE
ek9 -F myproject.ek9
This discovers all .ek9 files referenced by the project and formats each one to canonical style. Every file must be parseable for this to succeed.
DIFFERENCE FROM -f
- ek9 -f myfile.ek9 formats a single named file.
- ek9 -F myproject.ek9 formats all files in the project.
Both require the files to parse successfully first.
TYPICAL WORKFLOW
After cloning a project or pulling changes:
ek9 -F myproject.ek9
This ensures your entire codebase follows the canonical format before you start editing.
After a code review or merge:
ek9 -F myproject.ek9
This normalises any formatting differences introduced during the merge.
IDEMPOTENCY
Running -F on an already-formatted project produces no changes. This makes it safe to run in CI to verify that all files are correctly formatted.
See Q622 for formatting a single file. See Q624 for force-formatting unparseable files. See Q625 for why EK9 enforces a standard format. See Q626 for integrating formatting into your workflow.
Example
defines module qa.codeformatting.allfiles defines function <?- Multiple functions representing a multi-file project. After ek9 -F, every file follows the same format. -?> add() as pure -> left as Integer right as Integer <- result as Integer: left + right multiply() as pure -> left as Integer right as Integer <- result as Integer: left * right defines program FormatAllDemo() stdout <- Stdout() sum <- add(3, 4) product <- multiply(3, 4) stdout.println(`Sum: ${sum}`) stdout.println(`Product: ${product}`)
Common mistakes
E50001 — Removing the variable declaration means later references to the variable become unresolved, triggering E50001. See ek9 -h E50001 for details.
Incorrect:
add(3, 4)
Correct:
sum <- add(3, 4)
E50060 — Integer has no toString() method; convert with the $ prefix operator ($product) or use string interpolation. See ek9 -h E50060 for details.
Incorrect:
stdout.println(product.toString())
Correct:
stdout.println(`Product: ${product}`)
Other ways to ask this
- How do I format an entire EK9 project at once?
- What does ek9 -F do?
- How do I bulk-format all .ek9 files?
Coming from another language?
Go: gofmt ./... formats all Go files in directory tree. Rust: cargo fmt formats all crate sources. Python: black . formats all Python files in directory. Java: google-java-format with glob patterns (manual setup). JavaScript: prettier --write . (external tool). EK9: ek9 -F formats all project sources in one command, built into the compiler.
Keywords: project, format, style, normalise, indent, bulk, all, canonical, files, F