Skip to content

feat: add position details to linter#4663

Merged
benfdking merged 1 commit intomainfrom
adding_range_to_linting_errors
Jun 5, 2025
Merged

feat: add position details to linter#4663
benfdking merged 1 commit intomainfrom
adding_range_to_linting_errors

Conversation

@benfdking
Copy link
Copy Markdown
Contributor

  • adds ability for linter to return range to specify where the error
    gets returned
  • maps that correctly over for the lsp
  • for the builtin selectstar rule, add the range

@benfdking benfdking force-pushed the adding_range_to_linting_errors branch from 8042afa to 0109528 Compare June 5, 2025 10:25
Comment thread sqlmesh/core/linter/definition.py Outdated
Comment thread sqlmesh/core/linter/helpers.py Outdated
Comment thread tests/core/linter/test_linter.py Outdated
Comment thread tests/lsp/test_diagnostics.py Outdated
Comment thread sqlmesh/core/linter/rule.py Outdated
Comment on lines +25 to +28
class Position(PydanticModel):
"""The position of a rule violation in a file, the position follows the LSP standard."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do these wrapper classes inherit from PydanticModel instead of making them data classes? I think the latter is more lightweight, so may be worth exploring if we don't care about serializing these objects.

Copy link
Copy Markdown
Contributor Author

@benfdking benfdking Jun 5, 2025

Choose a reason for hiding this comment

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

🤷 I think serializing could quickly become useful but as you say easier to add after.

Comment thread sqlmesh/core/linter/rule.py Outdated
Comment on lines +32 to +39
class Range(PydanticModel):
"""The range of a rule violation in a file. The range follows the LSP standard."""

start: Position
end: Position
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we document that this represents a [start, end) range?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To me this is really what I was hoping

The range follows the LSP standard.

^ I don't want to reinvent the wheel, I just want them to follow the LSP standard. So if you are confused, just go there.

Comment on lines +28 to +31
line: int
character: int
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does "character" mean column offset in the line? Why not use column or something similar so that the naming is consistent?

I also suggest we start documenting some details, like whether it's 1-based indexing and stuff, so reading the docstring makes it obvious to understand what's going on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

idem, just want to specify LSP standard

def _get_range(self, model: SqlModel) -> t.Optional[Range]:
"""Get the range of the violation if available."""
try:
if len(model.query.expressions) == 1 and isinstance(model.query.expressions[0], Star):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this instead call find(Star) on the model's query? Note that SQL like t.* won't be picked up by this check because the projection is a Column that contains a Star child in this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this can be improved, but I'm hesitant to do so right away because it adds complexity. For me, I'm just in the simplest case of returning a range, which I think we can expand on over time.

There's also a lot of other changes so rather do this later.

@benfdking benfdking force-pushed the adding_range_to_linting_errors branch 2 times, most recently from 747db1b to a6ee7b2 Compare June 5, 2025 11:23
Comment thread sqlmesh/core/linter/rules/builtin.py Outdated
Comment thread sqlmesh/core/linter/rules/builtin.py Outdated
Comment thread sqlmesh/core/linter/rules/builtin.py Outdated
@benfdking benfdking force-pushed the adding_range_to_linting_errors branch from a6ee7b2 to 7009d81 Compare June 5, 2025 11:36
@benfdking benfdking enabled auto-merge (squash) June 5, 2025 11:36
@benfdking benfdking force-pushed the adding_range_to_linting_errors branch from 7009d81 to bb2923f Compare June 5, 2025 12:00
- adds ability for linter to return range to specify where the error
  gets returned
- maps that correctly over for the lsp
- for the builtin selectstar rule, add the range
@benfdking benfdking force-pushed the adding_range_to_linting_errors branch from bb2923f to 9b23b60 Compare June 5, 2025 12:52
@benfdking benfdking merged commit 2595aca into main Jun 5, 2025
23 checks passed
@benfdking benfdking deleted the adding_range_to_linting_errors branch June 5, 2025 13:07
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