|
1 | 1 | # Linter |
2 | 2 |
|
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. |
4 | 4 |
|
5 | 5 | For more information regarding linter configuration visit the relevant [guide here](../guides/configuration.md). |
6 | 6 |
|
7 | 7 | # Rules |
8 | 8 |
|
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`: |
10 | 10 |
|
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): |
14 | 13 |
|
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.""" |
18 | 17 |
|
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.""" |
23 | 21 |
|
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 "" |
27 | 26 |
|
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 | + ``` |
29 | 32 |
|
30 | 33 | Thus, each `Rule` can be broken down to its vital components: |
31 | 34 | - The name (or code) of the rule is defined as its class name in lowercase. |
|
0 commit comments