Skip to content

feat: File Name Equals Model Name Linter #4534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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,)))