Skip to content

feat: allow linter to return multiple violations#5026

Merged
benfdking merged 1 commit intomainfrom
linter_return_multiple_entries
Jul 27, 2025
Merged

feat: allow linter to return multiple violations#5026
benfdking merged 1 commit intomainfrom
linter_return_multiple_entries

Conversation

@benfdking
Copy link
Contributor

@benfdking benfdking commented Jul 25, 2025

  • also printed the line numbers
❯ sqlmesh lint
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/customers.sql:
 - nomissingaudits at line 1: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/marketing.sql:
 - nomissingaudits at line 1: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/active_customers.sql:
 - nomissingaudits at line 1: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/customer_revenue_lifetime.sql:
 - nomissingaudits at line 6: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/blueprint.sql:
 - nomissingowner: All models should have an owner specified.
 - nomissingaudits at line 1: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/blueprint.sql:
 - nomissingowner: All models should have an owner specified.
 - nomissingaudits at line 1: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/customer_revenue_by_day.sql:
 - nomissingaudits at line 2: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/latest_order.sql:
 - nomissingowner: All models should have an owner specified.
 - nomissingaudits at line 1: Model `audits` must be configured to test data quality.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/external_models.yaml:
 - nomissingowner: All models should have an owner specified.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/external_models/model1/model1.yaml:
 - nomissingowner: All models should have an owner specified.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/external_models/model2/model2.yaml:
 - nomissingowner: All models should have an owner specified.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/order_items.py:
 - nomissingowner: All models should have an owner specified.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/orders.py:
 - nomissingaudits: Model `audits` must be configured to test data quality.
 - nomissingowner: All models should have an owner specified.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/raw_marketing.py:
 - nomissingaudits: Model `audits` must be configured to test data quality.
 - nomissingowner: All models should have an owner specified.
Linter errors for /Users/benjaminking/Developer/sqlmesh/examples/sushi/models/items.py:
 - nomissingowner: All models should have an owner specified.
Error: Linter detected errors in the code. Please fix them before proceeding.

@benfdking benfdking requested a review from Copilot July 25, 2025 17:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_model method 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

@izeigerman
Copy link
Collaborator

Need more context to understand this. How can a single model violate the same rule more than once?

@izeigerman
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. Are we adding the same violation twice? Haven't we added it on line 112 already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@benfdking benfdking force-pushed the linter_return_multiple_entries branch from c3bc2ea to cb863a1 Compare July 27, 2025 18:43
@benfdking benfdking merged commit 0690311 into main Jul 27, 2025
27 checks passed
@benfdking benfdking deleted the linter_return_multiple_entries branch July 27, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants