File tree Expand file tree Collapse file tree
sqlmesh/core/linter/rules Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99from sqlmesh .core .linter .rule import Rule , RuleViolation
1010from sqlmesh .core .linter .definition import RuleSet
1111from sqlmesh .core .model import Model , SqlModel
12+ from pathlib import Path
1213
1314
1415class 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+
5974BUILTIN_RULES = RuleSet (subclasses (__name__ , Rule , (Rule ,)))
You can’t perform that action at this time.
0 commit comments