| name | mojo-lint-syntax |
| description | Validate Mojo syntax against current v0.26.1+ standards. Use to catch syntax errors before compilation. |
| category | mojo |
| mcp_fallback | none |
Lint Mojo Syntax
Validate Mojo code against v0.26.1+ syntax standards.
When to Use
- Writing new Mojo code before testing
- Reviewing Mojo code for syntax issues
- Migrating code from older Mojo versions
- Checking for deprecated patterns
- Pre-commit validation of Mojo files
Quick Reference
mojo build -I . file.mojo
mojo package shared
pixi run mojo format .
grep -r "inout self\|@value\|DynamicVector\|->" *.mojo | grep -v "result\|fn"
IMPORTANT: Library files with relative imports CANNOT be validated using mojo build - use mojo package instead.
Common Syntax Issues
Deprecated Patterns:
- ❌
inout self → ✅ out self in __init__, ✅ mut self in methods
- ❌
@value → ✅ @fieldwise_init with trait list
- ❌
DynamicVector → ✅ List
- ❌
-> (T1, T2) → ✅ -> Tuple[T1, T2]
Constructor Issues:
- Wrong parameter type in
__init__ (must be out self)
- Missing trait conformances (
Copyable, Movable)
- Incorrect initialization order
Type Issues:
- Missing type annotations (required in fn declarations)
- Mismatched types in assignments
- Invalid type parameters
Ownership Issues:
- Missing transfer operator
^ for non-copyable types
- Using
var parameter incorrectly
- Copy/move semantics violations
Validation Workflow
- Identify file type: Determine if file is library (has relative imports) or executable (has main())
- Check syntax: Run appropriate command:
- Executable files:
mojo build -I . file.mojo
- Library files: Skip standalone compilation (part of package)
- Fix format: Run
pixi run mojo format to auto-fix style
- Verify patterns: Check for deprecated patterns
- Type check: Ensure all types are correct
- Ownership check: Verify ownership semantics
- Package validation: Use
mojo package shared for library files
- Report issues: List all problems found
Output Format
Report syntax issues with:
- File - Which file has the issue
- Line - Line number of error
- Error - Syntax error message
- Pattern - What deprecated/wrong pattern was used
- Fix - How to correct it
- Severity - Critical (won't compile) or warning
Error Handling
| Problem | Solution |
|---|
| Compiler not found | Verify mojo is installed and in PATH |
| Module not found | Add -I . flag to include current directory |
| Encoding issues | Convert file to UTF-8 |
| Version mismatch | Check mojo version against v0.26.1+ |
| Large files | Process one file at a time |
Validation Checklist
Before committing Mojo code:
References
- See CLAUDE.md for v0.26.1+ syntax standards
- See validate-mojo-patterns for pattern validation
- See mojo-format skill for code formatting