Conversation
There was a problem hiding this comment.
Pull request overview
Adds new condition-level formatting features to sql_beautifier: multiline expansion for IN (...) value lists and additional parenthesis unwrapping after a leading NOT, applied across SELECT/UPDATE/DELETE condition rendering paths.
Changes:
- Introduce
SqlBeautifier::InList.format_in_textto expandIN/NOT INlists (2+ items) into one-item-per-line formatting. - Extend condition unwrapping to reduce redundant parentheses following a leading
NOT. - Add/adjust specs and documentation examples covering both features.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
lib/sql_beautifier/in_list.rb |
New scanner-based formatter to expand IN lists while skipping quoted text and IN (SELECT ...) subqueries. |
lib/sql_beautifier/condition.rb |
Apply InList to leaf rendering; add NOT-prefix parenthesis unwrapping. |
lib/sql_beautifier/dml_rendering.rb |
Apply InList when rendering a single-leaf WHERE clause for DML queries. |
lib/sql_beautifier/clauses/condition_clause.rb |
Apply NOT-paren unwrapping + InList for single-condition WHERE/HAVING style clauses. |
lib/sql_beautifier.rb |
Require the new in_list module. |
spec/sql_beautifier/in_list.spec.rb |
New unit specs for InList.format_in_text. |
spec/sql_beautifier/formatter.spec.rb |
End-to-end coverage for IN list formatting + NOT ((...)) unwrapping. |
spec/sql_beautifier/condition_formatter.spec.rb |
Coverage for NOT paren unwrapping in multiline condition formatting. |
spec/sql_beautifier/condition.spec.rb |
Coverage for NOT paren unwrapping at the parsed condition-expression level. |
spec/sql_beautifier/clauses/where.spec.rb |
Update existing expectations + add more WHERE-focused cases for both features. |
spec/readme.spec.rb |
Locks README examples for both features. |
README.md |
Document new formatting behaviors with examples. |
CHANGELOG.md |
Note the new IN formatting and NOT-paren fix. |
Comments suppressed due to low confidence (1)
lib/sql_beautifier/condition.rb:61
Condition#renderformats leaf expressions withInList, but group conditions can still returnrender_inline, which currently builds fromchild.expression(noInListpass). That means anINlist inside a parenthesized group can remain inline when the group meetsinline_group_threshold, makingINformatting inconsistent depending on whether the group renders inline vs multiline. Consider applyingInListduringrender_inlineconstruction, or forcing multiline rendering when an inline group would contain an expandableINlist.
def render(indent_width:)
return InList.format_in_text(@expression, base_indent: indent_width) if leaf?
inline_version = render_inline
return inline_version if inline_version.length <= SqlBeautifier.config_for(:inline_group_threshold)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
This PR serves to add multiline formatting for
INvalue lists and strip redundant parentheses afterNOTin WHERE/HAVING conditions.INlists with 2+ items (e.g.WHERE status IN ('active', 'pending', 'banned')) are now expanded to one item per line with proper indentation. Single-item lists andIN (SELECT ...)subqueries are left inline. This is handled by a newInListmodule that follows the same scanner-based text transformation pattern used byCaseExpression.format_in_text.Redundant doubled parentheses after
NOT(e.g.NOT ((a = 1 OR b = 2))) are now reduced to the minimal necessary grouping (NOT (a = 1 OR b = 2)). The unwrapping preserves parens that are semantically required to group multiple conditions.Both features apply across SELECT, UPDATE, and DELETE queries through all three condition rendering code paths.