feat(rules): add LT14 rule for keyword clause newline enforcement#2324
Merged
benfdking merged 4 commits intoquarylabs:mainfrom Feb 16, 2026
Merged
feat(rules): add LT14 rule for keyword clause newline enforcement#2324benfdking merged 4 commits intoquarylabs:mainfrom
benfdking merged 4 commits intoquarylabs:mainfrom
Conversation
benfdking
requested changes
Feb 15, 2026
Collaborator
benfdking
left a comment
There was a problem hiding this comment.
Thanks for another nice contribution! This will need a bit of a rebase, and you'll also need to re-generate the docs.
Implement LT14 (layout.keyword_newline) using the reflow rebreak system, consistent with how LT01/LT02 work. The rule enforces that each SQL clause (SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT) starts on its own line. Also fix two latent bugs in the reflow rebreak system that prevented clause-level rebreak spans from working correctly: - identify_rebreak_spans: fix end_idx calculation for clause-level spans that stopped at the first End/Solo block instead of scanning to the actual last block within the scope - RebreakIndices::from_elements: add bounds checking for neighbor access in newline/pre_code scanning loops to prevent index out-of-bounds Closes quarylabs#2323
- Add clause types list to long_description for generated docs - Fix import: ahash::AHashMap -> hashbrown::HashMap - Regenerate docs
ddf46e2 to
60d69ea
Compare
Contributor
Author
|
@benfdking |
- Update config_unknown_rule.stderr to include LT14 and layout.keyword_newline in available rules list - Update playwright config test to handle multi-line format output when rules=all includes LT14
The placeholder test uses rules=all, so LT14 now enforces a newline before the WHERE clause.
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
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
layout.keyword_newline) that enforces each SQL keyword clause starts on its own linerebreaksystem (ReflowSequence::from_root().rebreak()), consistent with LT01/LT02identify_rebreak_spans: end_idx calculation for clause-level spans stopped at the firstEnd/Soloblock instead of scanning to the actual last block within the scopeRebreakIndices::from_elements: missing bounds checking for neighbor access in newline/pre_code scanning loopsDetails
Rule behavior
The rule targets SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY, and LIMIT clauses. It respects the reflow
line_positionconfig:alone(default): flags inconsistent newlines where some clauses have newlines but others don't. All-on-one-line queries are allowed.alone:strict: always enforces newlines between clauses, even for single-line queries.Rebreak bug fixes
identify_rebreak_spanshad a bug where clause-levelline_position_configsspans had incorrectend_idx. Within a clause likeWHERE a = 1, all blocks in the last code child (a,=,1) shareStackPositionType::Endat the parent level. The old code broke on the firstEndblock (a) instead of continuing to scan to the actual last one (1), producing truncated spans that caused incorrect rebreak behavior.RebreakIndices::from_elementshad missing bounds checks wherenewline_point_idx + dirandpre_code_point_idx + dircould exceed array bounds when spans reached the edge of the element buffer.Test plan
cargo test -p sqruff-lib --test rules -- -- "LT14.yml"— 12 test cases passcargo test -p sqruff-lib --test rules— all rule tests pass (CV09 jinja templater failure is pre-existing)cargo fmt --all -- --checkpassescargo clippy -p sqruff-libpasses with no warningsCloses #2323