Skip to content

feat: helper to find key in model block#5079

Merged
benfdking merged 1 commit intomainfrom
working_on_key_model_block
Jul 31, 2025
Merged

feat: helper to find key in model block#5079
benfdking merged 1 commit intomainfrom
working_on_key_model_block

Conversation

@benfdking
Copy link
Contributor

  • to be used by linter in the future

- to be used by linter in the future
@benfdking benfdking requested a review from Copilot July 31, 2025 11:03
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 adds a helper function to find the range of a specific key within a model block in SQL files. The function get_range_of_a_key_in_model_block is intended for future use by the linter to locate and validate specific model properties.

Key changes:

  • Added get_range_of_a_key_in_model_block function to find key positions in model blocks
  • Added comprehensive test coverage using the sushi example models

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
sqlmesh/core/linter/helpers.py Implements the new helper function to locate keys within model blocks
tests/core/linter/test_helpers.py Adds test coverage that validates the function against real model files

Comment on lines +195 to +202
key_token = next(
(
t
for t in tokens_of_interest
if t.token_type is TokenType.VAR and t.text.upper() == key.upper()
),
None,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a heads up that this looks good as a best-effort approach, just not sure if it guarantees you'll match the exact token. Think that the token corresponding to the property's key could appear elsewhere in the MODEL block

Probably not worth trying to further improve it, but a simple heuristic if you notice any issues would be to check if the previous token is a comma, since properties are comma-separated.

@benfdking benfdking merged commit 6724d96 into main Jul 31, 2025
27 checks passed
@benfdking benfdking deleted the working_on_key_model_block branch July 31, 2025 11:36
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