+++ title = "Check Command" description = "Validate MLF lexicon files" weight = 4 +++ The `mlf check` command validates MLF lexicon files for syntax and type errors. ## Usage ```bash mlf check [INPUT]... ``` **Arguments:** - `[INPUT]...` - MLF lexicon file(s) to validate (glob patterns supported) If no input files are provided, `mlf check` will use the source directory from your `mlf.toml` configuration. ## Examples ### Check with Configuration If you have an `mlf.toml` file: ```toml [source] directory = "./lexicons" ``` Simply run: ```bash mlf check ``` This automatically checks all `.mlf` files in `./lexicons/`. ### Check Specific Files ```bash # Check a single file mlf check thread.mlf # Check multiple files mlf check thread.mlf profile.mlf reply.mlf ``` ### Check with Glob Patterns ```bash # Check all MLF files in a directory mlf check "lexicons/**/*.mlf" # Check files matching a pattern mlf check "src/*/schema.mlf" # Check all MLF files recursively mlf check "**/*.mlf" ``` ## Validation Checks The check command performs comprehensive validation: ### 1. **Syntax Validation** - Correct MLF syntax - Proper use of keywords - Valid identifiers and namespaces - Correct constraint syntax ### 2. **Type Validation** - All referenced types exist - Type constraints are valid - Required fields are properly marked - Array and object structures are correct ### 3. **Semantic Validation** - No duplicate definitions - Valid record keys - Proper XRPC method signatures - Correct union type usage ### 4. **Cross-Reference Validation** - External references resolve correctly - Import statements are valid - Prelude types are accessible - Fetched dependencies are available ## Output ### Success When all files are valid: ``` ✓ thread.mlf: Parsed successfully ✓ profile.mlf: Parsed successfully ✓ reply.mlf: Parsed successfully ✓ All lexicons are valid ``` ### Errors When errors are found, detailed diagnostics are shown: ``` × Undefined reference to 'ProfileView' ╭─[profile.mlf:5:12] 5 │ author: ProfileView, · ^^^^^^^^^^^ 'ProfileView' is not defined ╰──── help: Make sure this type is defined in the same file or imported via 'use'. ``` Each error includes: - Error message with context - Source code snippet - Exact location (line and column) - Helpful suggestions for fixing ## Working with Dependencies If your lexicons reference external types (e.g., from `app.bsky` or `com.atproto`), make sure to fetch them first: ```bash # Fetch dependencies mlf fetch # Then check your lexicons mlf check ``` The check command automatically loads lexicons from `.mlf/lexicons/mlf/` if they exist. ## Exit Codes - `0` - All files are valid - `1` - Validation errors found ## Common Issues ### Undefined Reference ``` × Undefined reference to 'SomeType' ``` **Solution:** - Define `SomeType` in the same file, or - Fetch the lexicon containing `SomeType` using `mlf fetch`, or - Add an import statement if needed ### Parse Error ``` × Expected 'constrained', found 'contsrained' ``` **Solution:** Fix the typo in your MLF file ### Type Mismatch ``` × Field 'count' expects integer, found string ``` **Solution:** Correct the field type to match the schema ## Tips 1. **Use configuration** - Set up `mlf.toml` to avoid typing paths repeatedly 2. **Check often** - Run `mlf check` frequently during development 3. **Version control** - Commit valid lexicons only 4. **Fetch first** - Always fetch dependencies before checking 5. **Read errors carefully** - MLF provides detailed error messages with helpful suggestions