Skip to content

Commit d9b2c46

Browse files
committed
Wrap rule impl to snippet
1 parent 1b99906 commit d9b2c46

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

docs/concepts/linter.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
# Linter
22

3-
Linting enables you to validate the model definition, ensuring it adheres to best practices. When a project is loaded in SQLMesh, each model is checked against a set of rules to verify that its definitions complies with the project's standards; This improves code quality, consistency, and helps to detect issues early in the development cycle.
3+
Linting enables you to validate the model definition, ensuring it adheres to best practices. When a project is loaded in SQLMesh, each model is checked against a set of rules to verify that its definitions complies with the project's standards. This improves code quality, consistency, and helps to detect issues early in the development cycle.
44

55
For more information regarding linter configuration visit the relevant [guide here](../guides/configuration.md).
66

77
# Rules
88

9-
Each rule is responsible for detecting a specific issue or pattern in a model. Rules are defined as classes that implement the logic for validation by subclassing `Rule` (redacted form):
9+
Each rule is responsible for detecting a specific issue or pattern in a model. Rules are defined as classes that implement the logic for validation by subclassing `Rule`:
1010

11-
```Python3
12-
class Rule:
13-
"""The base class for a rule."""
11+
??? "Rule class implementation"
12+
This is an outline of the `Rule` class and it's critical parts, the actual implementation can be found [here](https://github.com/TobikoData/sqlmesh/blob/main/sqlmesh/core/linter/rule.py):
1413

15-
@abc.abstractmethod
16-
def check_model(self, model: Model) -> t.Optional[RuleViolation]:
17-
"""The evaluation function that'll check for a violation of this rule."""
14+
```Python3
15+
class Rule:
16+
"""The base class for a rule."""
1817

19-
@property
20-
def summary(self) -> str:
21-
"""A summary of what this rule checks for."""
22-
return self.__doc__ or ""
18+
@abc.abstractmethod
19+
def check_model(self, model: Model) -> t.Optional[RuleViolation]:
20+
"""The evaluation function that'll check for a violation of this rule."""
2321

24-
def violation(self, violation_msg: t.Optional[str] = None) -> RuleViolation:
25-
"""Create a RuleViolation instance for this rule"""
26-
return RuleViolation(rule=self, violation_msg=violation_msg or self.summary)
22+
@property
23+
def summary(self) -> str:
24+
"""A summary of what this rule checks for."""
25+
return self.__doc__ or ""
2726

28-
```
27+
def violation(self, violation_msg: t.Optional[str] = None) -> RuleViolation:
28+
"""Create a RuleViolation instance for this rule"""
29+
return RuleViolation(rule=self, violation_msg=violation_msg or self.summary)
30+
31+
```
2932

3033
Thus, each `Rule` can be broken down to its vital components:
3134
- The name (or code) of the rule is defined as its class name in lowercase.

0 commit comments

Comments
 (0)