Skip to content

Commit 0e9a655

Browse files
committed
initial commit
1 parent b1f9960 commit 0e9a655

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

sqlmesh/core/linter/rules/builtin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sqlmesh.core.linter.rule import Rule, RuleViolation
1010
from sqlmesh.core.linter.definition import RuleSet
1111
from sqlmesh.core.model import Model, SqlModel
12+
from pathlib import Path
1213

1314

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

5859

60+
class FilenameEqualsModelname(Rule):
61+
"""The filename should equal the model name"""
62+
63+
def check_model(self, model: Model) -> t.Optional[RuleViolation]:
64+
# Rule violated if the model's name (schema.table_name) does not match the file name (foo/bar/table_name.sql).
65+
full_model_name = model.name
66+
table_name = full_model_name.split(".", 1)[1]
67+
path = Path(model._path)
68+
return (
69+
self.violation()
70+
if (table_name != path.stem) and not model.kind.is_symbolic
71+
else None
72+
)
73+
5974
BUILTIN_RULES = RuleSet(subclasses(__name__, Rule, (Rule,)))

0 commit comments

Comments
 (0)