Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/grafana-cloud/ai-tools/gcx/guides/lint-resources.md, or by sending Accept: text/markdown to https://grafana.com/docs/grafana-cloud/ai-tools/gcx/guides/lint-resources/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Lint resources with gcx
Use the Grafana CLI linter to verify that resources, such as dashboards and alert rules, comply with good practices and environment-specific policies.
Use the linter
To lint resources run:
gcx dev lint run ./resourcesThe following applies:
- Directories are recursively explored.
- All built-in rules are enabled by default.
Configure linter rules
For a finer control, you can configure the linter rules:
# Disable all rules for a resource type:
gcx dev lint run --disable-resource dashboard ./resources
# Disable all rules in a category:
gcx dev lint run --disable-category idiomatic ./resources
# Disable specific rules:
gcx dev lint run --disable uneditable-dashboard --disable panel-title-description ./resources
# Enable rules for specific resource types:
gcx dev lint run --disable-all --enable-resource dashboard ./resources
# Enable only some categories:
gcx dev lint run --disable-all --enable-category idiomatic ./resources
# Enable only specific rules:
gcx dev lint run --disable-all --enable uneditable-dashboard ./resourcesYou can modify the severity level of a rule by updating the custom.severity annotation. Valid values are warning and error.
Define custom linting rules
Custom and built-in rules are defined in Rego, the policy language used by Open Policy Agent (OPA). This ensures that resources comply with policies specific to your environment.
You can scaffold new custom rules with gcx:
# Creates a new "dashboard" linter rule in the current directory:
gcx dev lint new dashboard custom-ruleThis generates a file with the bootstrapped rule:
# METADATA
# description: Briefly describe the rule here.
# custom:
# severity: warning
package custom.gcx.rules.dashboard.idiomatic["custom-rule"]
import data.gcx.result
import data.gcx.utils
# Dashboard v1
report contains violation if {
utils.resource_is_dashboard_v1(input)
input.spec.timezone != "utc"
violation := result.fail(rego.metadata.chain(), sprintf("timezone is '%s', expected 'utc'", input.spec.timezone))
}
# Dashboard v2
report contains violation if {
utils.resource_is_dashboard_v2(input)
input.spec.timeSettings.timezone != "utc"
violation := result.fail(rego.metadata.chain(), sprintf("timezone is '%s', expected 'utc'", input.spec.timeSettings.timezone))
}Refer to the existing Built-in rules for inspiration to write custom ones.
Rules for other resources
You can create rules for other resource types than dashboards, or in categories other than idiomatic:
# Creates a new "alertrule" linter rule, categorized under "bug":
gcx dev lint new alertrule custom-rule -c bugWas this page helpful?
Related resources from Grafana Labs


