|
| 1 | +--- |
| 2 | +title: "How to use lightdash lint" |
| 3 | +sidebarTitle: "Linting your code" |
| 4 | +description: "Validate your Lightdash Code files against JSON schemas before deploying to catch errors early." |
| 5 | +--- |
| 6 | + |
| 7 | +The `lightdash lint` command validates your Lightdash Code files (models, charts, dashboards) against JSON schemas. This helps you catch configuration errors before deploying changes. |
| 8 | + |
| 9 | +## Why use linting? |
| 10 | + |
| 11 | +Linting is especially valuable when: |
| 12 | + |
| 13 | +- **Developing with AI tools** - AI copilots like Cursor, Claude Code, or Kilo Code can generate Lightdash YAML files, but may produce invalid configurations. Running `lightdash lint` after each change validates the output. |
| 14 | +- **Working with dashboards as code** - When editing chart or dashboard YAML files manually, linting catches typos and structural errors. |
| 15 | +- **CI/CD pipelines** - Add linting to your deployment workflow to prevent invalid configurations from reaching production. |
| 16 | + |
| 17 | +## Basic usage |
| 18 | + |
| 19 | +Validate all Lightdash Code files in the current directory: |
| 20 | + |
| 21 | +```bash |
| 22 | +lightdash lint |
| 23 | +``` |
| 24 | + |
| 25 | +Validate a specific file: |
| 26 | + |
| 27 | +```bash |
| 28 | +lightdash lint --path ./lightdash/charts/revenue-by-month.yml |
| 29 | +``` |
| 30 | + |
| 31 | +Validate a specific directory: |
| 32 | + |
| 33 | +```bash |
| 34 | +lightdash lint --path ./lightdash |
| 35 | +``` |
| 36 | + |
| 37 | +## Output formats |
| 38 | + |
| 39 | +### CLI output (default) |
| 40 | + |
| 41 | +The default output shows errors in a human-readable format with file paths and line numbers: |
| 42 | + |
| 43 | +```bash |
| 44 | +lightdash lint |
| 45 | +``` |
| 46 | + |
| 47 | +Example output: |
| 48 | + |
| 49 | +``` |
| 50 | +✗ ./lightdash/charts/my-chart.yml |
| 51 | + Line 15: metricQuery.dimensions must be array |
| 52 | +
|
| 53 | +Found 1 error in 1 file |
| 54 | +``` |
| 55 | + |
| 56 | +### Verbose output |
| 57 | + |
| 58 | +Use `--verbose` to see all validated files, including those that passed: |
| 59 | + |
| 60 | +```bash |
| 61 | +lightdash lint --verbose |
| 62 | +``` |
| 63 | + |
| 64 | +### SARIF JSON output |
| 65 | + |
| 66 | +For CI/CD integration, use SARIF (Static Analysis Results Interchange Format) output: |
| 67 | + |
| 68 | +```bash |
| 69 | +lightdash lint --format json |
| 70 | +``` |
| 71 | + |
| 72 | +This outputs results in [SARIF format](https://sarifweb.azurewebsites.net/), which is supported by GitHub Actions, VS Code, and other tools. |
| 73 | + |
| 74 | +## What gets validated |
| 75 | + |
| 76 | +The lint command validates three types of files against their JSON schemas: |
| 77 | + |
| 78 | +| File type | Identified by | Schema | |
| 79 | +|-----------|---------------|--------| |
| 80 | +| Models | `type: model` in YAML | [model-as-code-1.0.json](https://github.com/lightdash/lightdash/blob/main/packages/common/src/schemas/json/model-as-code-1.0.json) | |
| 81 | +| Charts | `metricQuery` property | [chart-as-code-1.0.json](https://github.com/lightdash/lightdash/blob/main/packages/common/src/schemas/json/chart-as-code-1.0.json) | |
| 82 | +| Dashboards | `tiles` property | [dashboard-as-code-1.0.json](https://github.com/lightdash/lightdash/blob/main/packages/common/src/schemas/json/dashboard-as-code-1.0.json) | |
| 83 | + |
| 84 | +The command automatically detects the file type based on its content and applies the appropriate schema. |
| 85 | + |
| 86 | +## Using lint with AI coding tools |
| 87 | + |
| 88 | +<Note> |
| 89 | +**Recommended: Install Lightdash Skills first.** Before manually configuring your AI tool, run `lightdash install-skills` to install the [Lightdash Skills](/get-started/develop-in-lightdash/install-skills). The skills already know to use `lightdash lint` for validation, so you don't need to configure anything manually. |
| 90 | +</Note> |
| 91 | + |
| 92 | +If you're using Lightdash Skills, your AI copilot will automatically run `lightdash lint` to validate YAML files as part of its workflow. The skills include best practices for schema validation built-in. |
| 93 | + |
| 94 | +### Manual configuration (without skills) |
| 95 | + |
| 96 | +If you're not using Lightdash Skills, you can manually configure your AI copilot to use linting: |
| 97 | + |
| 98 | +1. **Prompt the AI to run lint after changes** - Add instructions like "Always run `lightdash lint` after making changes to validate the YAML." |
| 99 | + |
| 100 | +2. **Provide schema references** - Give your AI tool the schema URLs so it understands the expected format: |
| 101 | + - Models: `https://raw.githubusercontent.com/lightdash/lightdash/main/packages/common/src/schemas/json/model-as-code-1.0.json` |
| 102 | + - Charts: `https://raw.githubusercontent.com/lightdash/lightdash/main/packages/common/src/schemas/json/chart-as-code-1.0.json` |
| 103 | + - Dashboards: `https://raw.githubusercontent.com/lightdash/lightdash/main/packages/common/src/schemas/json/dashboard-as-code-1.0.json` |
| 104 | + |
| 105 | +3. **Iterate on errors** - When lint reports errors, have the AI fix them before proceeding. |
| 106 | + |
| 107 | +<Tip> |
| 108 | +AI tools can run `lightdash lint` to validate their own output. This creates a feedback loop that catches errors automatically. |
| 109 | +</Tip> |
| 110 | + |
| 111 | +## CI/CD integration |
| 112 | + |
| 113 | +Add linting to your CI/CD pipeline to prevent invalid configurations from being deployed. |
| 114 | + |
| 115 | +### GitHub Actions example |
| 116 | + |
| 117 | +```yaml |
| 118 | +name: Validate Lightdash Code |
| 119 | + |
| 120 | +on: |
| 121 | + pull_request: |
| 122 | + paths: |
| 123 | + - 'lightdash/**' |
| 124 | + |
| 125 | +jobs: |
| 126 | + lint: |
| 127 | + runs-on: ubuntu-latest |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v3 |
| 130 | + |
| 131 | + - name: Install Lightdash CLI |
| 132 | + run: npm install -g @lightdash/cli |
| 133 | + |
| 134 | + - name: Lint Lightdash Code files |
| 135 | + run: lightdash lint --path ./lightdash |
| 136 | +``` |
| 137 | +
|
| 138 | +### Using SARIF with GitHub Code Scanning |
| 139 | +
|
| 140 | +To integrate lint results with GitHub's code scanning: |
| 141 | +
|
| 142 | +```yaml |
| 143 | +- name: Lint with SARIF output |
| 144 | + run: lightdash lint --format json > lint-results.sarif |
| 145 | + |
| 146 | +- name: Upload SARIF results |
| 147 | + uses: github/codeql-action/upload-sarif@v2 |
| 148 | + with: |
| 149 | + sarif_file: lint-results.sarif |
| 150 | +``` |
| 151 | +
|
| 152 | +## Common errors and fixes |
| 153 | +
|
| 154 | +### Missing required properties |
| 155 | +
|
| 156 | +``` |
| 157 | +metricQuery.exploreName is required |
| 158 | +``` |
| 159 | + |
| 160 | +**Fix:** Add the missing property to your YAML file. |
| 161 | + |
| 162 | +### Invalid property type |
| 163 | + |
| 164 | +``` |
| 165 | +metricQuery.dimensions must be array |
| 166 | +``` |
| 167 | + |
| 168 | +**Fix:** Ensure the property value matches the expected type. |
| 169 | + |
| 170 | +### Unknown properties |
| 171 | + |
| 172 | +``` |
| 173 | +should NOT have additional property 'unknownField' |
| 174 | +``` |
| 175 | + |
| 176 | +**Fix:** Remove the unrecognized property or check for typos. |
| 177 | + |
| 178 | +## Related |
| 179 | + |
| 180 | +- [Lightdash YAML](/guides/lightdash-yaml) - Define your semantic layer in YAML without dbt |
| 181 | +- [Dashboards as code](/guides/developer/dashboards-as-code) - Manage charts and dashboards as YAML files |
| 182 | +- [Lightdash CLI reference](/references/lightdash-cli#lightdash-lint) - Full command reference |
0 commit comments