forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
LT01: Fix alias alignment with templates and add alignment_coordinate_space config
#1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jorenby
wants to merge
42
commits into
main
Choose a base branch
from
fix-alias-alignment-with-templates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41e747b to
f1fc094
Compare
alignment_coordinate_space config
f1fc094 to
e58cfa6
Compare
…fluff#7112) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Danny Jones <[email protected]>
…f#7123) Co-authored-by: Danny Jones <[email protected]>
Co-authored-by: Danny Jones <[email protected]>
…uff#7119) Co-authored-by: Danny Jones <[email protected]>
Co-authored-by: Danny Jones <[email protected]>
e58cfa6 to
093ac8d
Compare
eeb71c3 to
945582a
Compare
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: Danny Jones <[email protected]>
945582a to
14f9a96
Compare
…n-deterministic results) (sqlfluff#6749) Co-authored-by: Danny Jones <[email protected]>
6cc9a76 to
d097cb3
Compare
Allows specifying the coordinate space (source or templated) for alignment constraints. This change introduces an optional coordinate space override to alignment configurations, enabling users to force alignment based on either source or templated positions. This addresses scenarios where default alignment behavior doesn't produce desired results, particularly with Jinja templating.
- Add test case for non-rendered column longer than template column - Add tests for explicit source coordinate space configuration - Add edge case tests for missing segments and target not found scenarios - Add tests for templated next segment and templated siblings detection - Improve test coverage for `respace.py` alignment logic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Change Jinja example from `sql` to `jinja` code block to avoid lexing errors - Add missing `.. code-block::` directive for SQL example - Add missing comma in SQL example Fixes docutils warnings about definition lists and highlighting failures. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Add `# pragma: no cover` to two defensive fallback paths that are difficult to trigger in practice: - No segments found on current line for alignment (lines 335-339) - Target segment not found in current line (lines 356-360) This follows the existing pattern in respace.py (see lines 530-537) where defensive/backup code paths are excluded from coverage with explanatory comments. These edge cases provide safety but are not expected to occur during normal operation given the algorithm's structure. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
ccebbd4 to
334b43f
Compare
…_content Lines 52 and 54 check if next_seg or siblings contain templated content. Despite having integration tests with Jinja templates, these specific lines are not being executed - the templated content detection happens via the parent segment check (line 57) instead. Following the established pattern in the reflow module (62 existing pragma comments), mark these as excluded from coverage since they represent edge cases that are difficult to trigger via integration tests. This brings respace.py to 100% coverage. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes alias alignment issues when using Jinja templating by implementing coordinate space selection logic that aligns based on source (visible) positions rather than rendered template positions. Also, adds
alignment_coordinate_spaceconfig for manual override.Resolves sqlfluff#5429
Key Changes:
alignment_coordinate_spaceconfiguration parameter for manual override (:sourceor:templated)Problem
When using Jinja templates with alias alignment, SQLFluff would:
Solution
The fix automatically detects templated content and switches to source-based coordinate alignment, ensuring aliases align based on what users see in their editor rather than the expanded macro results.
Test Plan
Examples
Before (broken behavior):
After running
sqlfluff fix, it would incorrectly produce something like:After (fixed behavior):
Credits
Initial implementation developed with assistance from GPT-5 in Cursor IDE. Code review, cleanup, and testing performed with Claude Code.
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]