Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sqlmesh/core/linter/rules/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sqlmesh.core.linter.rule import Rule, RuleViolation
from sqlmesh.core.linter.definition import RuleSet
from sqlmesh.core.model import Model, SqlModel
from pathlib import Path


class NoSelectStar(Rule):
Expand Down Expand Up @@ -56,4 +57,16 @@ def check_model(self, model: Model) -> t.Optional[RuleViolation]:
return self.violation() if not model.audits and not model.kind.is_symbolic else None


class FilenameEqualsModelname(Rule):
"""The filename should equal the model name"""

def check_model(self, model: Model) -> t.Optional[RuleViolation]:
# Rule violated if the model's name (schema.table_name) does not match the file name (foo/bar/table_name.sql).
return (
self.violation()
if (model.name.split(".")[-1] != Path(model._path).stem) and not model.kind.is_symbolic
else None
)


BUILTIN_RULES = RuleSet(subclasses(__name__, Rule, (Rule,)))