Can AI help me improve code quality?
← Code Quality · Ref: Q323
EK9 is designed from the start for AI-assisted development. Multiple commands produce machine-readable output that AI tools can consume directly.
STEP 1: RICH ERROR MESSAGES (-E3)
ek9 -c -E3 mycode.ek9
The -E3 flag produces detailed error explanations with diagnosis, rationale, and fix examples. AI assistants can read these to understand exactly what went wrong and generate correct fixes.
STEP 2: JSON PROFILING AND COVERAGE (-t2p)
ek9 -t2p mycode.ek9
JSON output with profiling data, test results, and coverage. AI tools can parse this to identify undertested code, performance hotspots, and quality trends.
STEP 3: REFERENCE DATA (forAI.json)
The forAI.json file contains the complete EK9 knowledge base in machine-readable format. AI assistants can load this as context to understand EK9 syntax, operators, and patterns without guessing.
STEP 4: KNOWLEDGE SEARCH (-q)
ek9 -q "how to handle errors"
Search the Q&A knowledge base from the command line. AI tools can use this to find correct patterns for specific problems instead of hallucinating incorrect syntax.
STEP 5: TRAINING DATA DUMP (-Q)
ek9 -Q
Dumps the entire Q&A knowledge base in JSONL training format. This can fine-tune local AI models on EK9 patterns.
THE AI QUALITY WORKFLOW
1. Write code (or have AI generate it).
2. Compile with -E3 for rich feedback.
3. Fix errors using Q&A search (-q) for correct patterns.
4. Run tests with -t2p for JSON quality data.
5. Feed quality data back to AI for continuous improvement.
EK9 DESIGNED FOR AI
The compiler error messages are specifically designed as AI control signals. Each error produces a cascade that guides AI toward correct patterns. When the compiler is silent, the code has converged across all quality dimensions.
See Q281 for verifying AI-generated code. See Q252 for all compiler flags. See Q311 for quality checks catalog. See Q321 for the quality report.
See Q340 for AI-friendly transaction patterns.
Example
defines module qa.codequality.ai defines function <?- A function that demonstrates clean, AI-friendly code. Clear names, simple structure, obvious purpose. -?> categoriseResponse() as pure -> statusCode as Integer <- category as String: "unknown" successLower <- 200 successUpper <- 299 clientErrorLower <- 400 clientErrorUpper <- 499 serverErrorLower <- 500 serverErrorUpper <- 599 if statusCode >= successLower and statusCode <= successUpper category: "success" else if statusCode >= clientErrorLower and statusCode <= clientErrorUpper category: "client error" else if statusCode >= serverErrorLower and statusCode <= serverErrorUpper category: "server error" defines program AiCodeQualityDemo() stdout <- Stdout() okStatus <- 200 notFoundStatus <- 404 okCategory <- categoriseResponse(okStatus) errorCategory <- categoriseResponse(notFoundStatus) stdout.println(`Status ${okStatus}: ${okCategory}`) stdout.println(`Status ${notFoundStatus}: ${errorCategory}`)
Common mistakes
E50001 — Renaming the variable means later references to 'okCategory' become unresolved, triggering E50001. See ek9 -h E50001 for details.
Incorrect:
okCategoryXYZ <- categoriseResponse(okStatus)
Correct:
okCategory <- categoriseResponse(okStatus)
E50001 — Renaming the variable means later references to 'errorCategory' become unresolved, triggering E50001. See ek9 -h E50001 for details.
Incorrect:
errorCategoryXYZ <- categoriseResponse(notFoundStatus)
Correct:
errorCategory <- categoriseResponse(notFoundStatus)
Other ways to ask this
- How do I use AI with EK9 code quality?
- What EK9 commands help AI understand my code?
- How does EK9 support AI-assisted development?
Coming from another language?
Java: SonarQube has API output but requires separate server. IDE plugins provide some AI integration. No unified CLI workflow. Python: pylint has JSON output, coverage has JSON, but no unified AI workflow. Rust: clippy has JSON output with --message-format=json. No knowledge base. Go: go vet has JSON output. No integrated knowledge base. EK9: purpose-built for AI with -E3 rich errors, -t2p JSON quality data, forAI.json reference, -q knowledge search, -Q training dump, all from a single CLI.
Keywords: machine, forAI, metric, quality, E3, llm, ai, knowledge, assistant, json, training, clean-code, readable, workflow