max_code_lines
Rule: max_code_lines
max_code_lines details
This rule enforces a maximum line count for dbt code objects, helping to maintain code readability and encourage modular design. Objects with empty code will also be flagged by this rule.
Configuration
- type: Must be
max_code_lines. - max_lines: (optional) The maximum number of lines allowed for the code. Defaults to
150. - applies_to: (optional) List of dbt object types to include.
- Default:
["models", "snapshots", "macros"] - Options:
models,snapshots,macros
- Default:
Common Rule Config
- name: Human-readable name of the rule.
- severity:
"error"(fail) or"warning"(warn only).- (optional, defaults to
"error"if not specified)
- (optional, defaults to
- description: Human-readable explanation of the rule.
- category: Override the default rule category. Included in structured output (JSON, CSV, NDJSON) but not in the CLI table. Each rule has a built-in default (e.g.
documentation,naming,testing,governance,structure,performance).- (optional, defaults to the rule type's built-in category)
- includes: List of patterns to explicitly include for this rule. See Includes & Excludes for pattern syntax and examples.
- excludes: List of patterns to explicitly exclude from this rule. See Includes & Excludes for pattern syntax and examples.
- model_materializations: Filter models by materialization type. Only applies when
applies_toincludesmodels.- (optional, if not specified all materializations are included)
- Built-in types:
table,view,incremental,ephemeral,materialized_view. Custom materializations are also supported. - Example:
["table", "incremental"]
Example Config
manifest_tests:
- name: "models_max_100_lines"
type: "max_code_lines"
max_lines: 100
description: "Models should not exceed 100 lines of code."
# severity: "warning" (optional)
# applies_to: ['models', 'snapshots'] (optional)
# includes: ["path/to/include/*"]
# excludes: ["path/to/exclude/*"][[manifest_tests]]
name = "models_max_100_lines"
type = "max_code_lines"
max_lines = 100
description = "Models should not exceed 100 lines of code."
# severity = "warning" # (optional)
# applies_to = ["models", "snapshots"] # (optional)
# includes = ["path/to/include/*"]
# excludes = ["path/to/exclude/*"][[tool.dbtective.manifest_tests]]
name = "models_max_100_lines"
type = "max_code_lines"
max_lines = 100
description = "Models should not exceed 100 lines of code."
# severity = "warning" # (optional)
# applies_to = ["models", "snapshots"] # (optional)
# includes = ["path/to/include/*"]
# excludes = ["path/to/exclude/*"]Relevant dbt code
-- models/short_model.sql (PASS)
SELECT
id,
name
FROM users
-- models/very_long_model.sql (FAIL - exceeds max_lines)
SELECT
id,
name,
email,
...
-- 101+ lines of SQL
...
FROM users
-- models/empty_model.sql (FAIL - empty code)
-- No contentUse cases
- Enforce code modularity by limiting file size
- Prevent overly complex transformations in single files
- Encourage breaking down large models into smaller, reusable CTEs or models
- Maintain consistent code readability across the project
- Catch accidentally empty SQL files