Skip to content

fix(reflow): use relevant untaken count for indent calculations#2069

Open
dhawkins1234 wants to merge 1 commit intoquarylabs:mainfrom
dhawkins1234:main
Open

fix(reflow): use relevant untaken count for indent calculations#2069
dhawkins1234 wants to merge 1 commit intoquarylabs:mainfrom
dhawkins1234:main

Conversation

@dhawkins1234
Copy link

Refactor indentation calculation logic to properly account for indent troughs when determining relevant untaken indents. Previously, the code used untaken_indents.len() directly, which didn't filter out irrelevant indents when a trough was present. I was getting thread errors and incorrect indentation, especially on larger .sql files, if the spacing_before = align was used, as in the sample configuration

[sqruff:layout:type:alias_expression]
spacing_before = align
align_within = select_clause
align_scope = bracketed

oracle_parsed.sql

Changes:

  • Add relevant_untaken_count() method to IndentPoint that mirrors the filtering logic in IndentLine::desired_indent_units()
  • Update lint_line_untaken_positive_indents() to use the new method
  • Update lint_line_untaken_negative_indents() to use the new method
  • Add .max(0) guards to prevent negative indent values

This fixes incorrect indentation calculations in cases where indent troughs are present, ensuring that only relevant untaken indents are considered when computing desired indentation levels.

@dhawkins1234 dhawkins1234 force-pushed the main branch 2 times, most recently from fab94aa to 5cfd389 Compare December 12, 2025 03:30
Refactor indentation calculation logic to properly account for indent
troughs when determining relevant untaken indents. Previously, the code
used `untaken_indents.len()` directly, which didn't filter out irrelevant
indents when a trough was present.

Changes:
- Add `relevant_untaken_count()` method to `IndentPoint` that mirrors
  the filtering logic in `IndentLine::desired_indent_units()`
- Update `lint_line_untaken_positive_indents()` to use the new method
- Update `lint_line_untaken_negative_indents()` to use the new method
- Add `.max(0)` guards to prevent negative indent values

This fixes incorrect indentation calculations in cases where indent
troughs are present, ensuring that only relevant untaken indents are
considered when computing desired indentation levels.
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.

1 participant