diff --git a/src/dbt_score/models.py b/src/dbt_score/models.py index 838e5b1..f644ac8 100644 --- a/src/dbt_score/models.py +++ b/src/dbt_score/models.py @@ -128,6 +128,8 @@ class Model: database: The database name of the model. schema: The schema name of the model. raw_code: The raw code of the model. + language: The language of the model, e.g. sql. + access: The access level of the model, e.g. public. alias: The alias of the model. patch_path: The yml path of the model, e.g. `package://model_dir/dir/file.yml`. tags: The list of tags attached to the model. @@ -149,6 +151,8 @@ class Model: database: str schema: str raw_code: str + language: str + access: str alias: str | None = None patch_path: str | None = None tags: list[str] = field(default_factory=list) @@ -200,6 +204,8 @@ def from_node( database=node_values["database"], schema=node_values["schema"], raw_code=node_values["raw_code"], + language=node_values["language"], + access=node_values["access"], alias=node_values["alias"], patch_path=node_values["patch_path"], tags=node_values["tags"], diff --git a/src/dbt_score/rules/generic.py b/src/dbt_score/rules/generic.py index c1b8c4b..ad37cd6 100644 --- a/src/dbt_score/rules/generic.py +++ b/src/dbt_score/rules/generic.py @@ -1,6 +1,6 @@ """All generic rules.""" -from dbt_score import Model, RuleViolation, rule +from dbt_score import Model, RuleViolation, Severity, rule @rule @@ -39,3 +39,13 @@ def sql_has_reasonable_size(model: Model, max_lines: int = 200) -> RuleViolation return RuleViolation( message=f"SQL query too long: {count_lines} lines (> {max_lines})." ) + + +@rule(severity=Severity.LOW) +def public_model_has_example_sql(model: Model) -> RuleViolation | None: + """The documentation of a public model should have an example query.""" + if model.language == "sql" and model.access == "public": + if "```sql" not in model.description: + return RuleViolation( + "The model description does not include an example SQL query." + ) diff --git a/tests/resources/manifest.json b/tests/resources/manifest.json index 6adba6f..b78113a 100644 --- a/tests/resources/manifest.json +++ b/tests/resources/manifest.json @@ -29,14 +29,16 @@ "alias": "model1_alias", "patch_path": "/path/to/model1.yml", "tags": [], - "depends_on": {} + "depends_on": {}, + "language": "sql", + "access": "protected" }, "model.package.model2": { "resource_type": "model", "unique_id": "model.package.model2", "name": "model2", "relation_name": "database.schema.model2", - "description": "Description2.", + "description": "A great model.\nExample use:\n```sql\nselect 1;\n```", "original_file_path": "/path/to/model2.sql", "config": {}, "meta": {}, @@ -57,7 +59,9 @@ "alias": "model2_alias", "patch_path": "/path/to/model2.yml", "tags": [], - "depends_on": {} + "depends_on": {}, + "language": "sql", + "access": "public" }, "test.package.test1": { "resource_type": "test",