feat: allow linter to return multiple violations#5026
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the SQLMesh linter to support multiple violations per rule and improves violation reporting by adding line numbers and sorting. The changes enable linter rules to return multiple violations in a single check and provide clearer output with line-based sorting.
- Modified the
Rule.check_modelmethod signature to return either a single violation or a list of violations - Updated violation processing logic to handle both single violations and lists of violations
- Enhanced violation display formatting to include line numbers and sort violations by line and rule name
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sqlmesh/core/linter/rule.py |
Updates abstract method signature to allow returning multiple violations |
sqlmesh/core/linter/definition.py |
Adds logic to handle both single violations and lists from rule checks |
sqlmesh/core/console.py |
Enhances violation display with line numbers and sorting functionality |
|
Need more context to understand this. How can a single model violate the same rule more than once? |
|
Ah, I guess in case of multiple missing external models we want to emit multiple violations. |
| violation = [violation] | ||
| if violation: | ||
| violations.append(violation) | ||
| violations.extend(violation) |
There was a problem hiding this comment.
This looks wrong. Are we adding the same violation twice? Haven't we added it on line 112 already?
There was a problem hiding this comment.
No it turns the RuleViolation into a t.List[RulationViolation] before adding it. and if it's None it doesn't get extended.
- also printed the line numbers
c3bc2ea to
cb863a1
Compare
Uh oh!
There was an error while loading. Please reload this page.