Repository navigation
Don't add a space before a parenthesis or bracket that continues an expression (quantile(0.9)(x), splitByChar(',', s)[1], col[1]) - #992
Closed
MunMunMiao wants to merge 1 commit into
Conversation
…xpression
A parenthesis directly after a function call (the arguments of a ClickHouse
parametric aggregate function, `quantile(0.9)(x)`) and brackets directly
after a function call, a parenthesis, a quoted identifier, a property access
or another subscript (`splitByChar(',', s)[1]`, `"col"[1]`) were separated
from the previous expression by a space. Only `col[1]` with an unquoted
identifier was handled, through the ARRAY_IDENTIFIER token.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The formatter cannot distinguish adjacent syntax from whitespace-separated expressions and may alter query semantics.
1 open finding
What changed in this PR
Updates expression formatting so chained calls and subscripts render without an intervening space.
Changes:
- Detects parentheses and brackets that follow compatible expression nodes.
- Adds ClickHouse, BigQuery, and PostgreSQL regression tests.
| File | Description |
|---|---|
src/formatter/ExpressionFormatter.ts |
Adds continuation-spacing logic. |
test/clickhouse.test.ts |
Tests chained calls and subscripts. |
test/bigquery.test.ts |
Tests function and identifier subscripts. |
test/postgresql.test.ts |
Tests several subscript forms. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+213
to
+217
| const prev = this.nodes[this.index - 1]; | ||
| // Only for a node of this list, not for the parenthesis that belongs to a function call | ||
| if (!prev || this.nodes[this.index] !== node) { | ||
| return false; | ||
| } |
Author
|
Closing for now: I'm going to handle the formatting on my side instead. Thanks for the library. |
MunMunMiao
deleted the
format-subscript-and-chained-call-without-space
branch
October 14, 2026 04:17
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.

Problem
A parenthesis or bracket that directly continues the previous expression gets a space in front of it when that expression is a function call, a parenthesis, a quoted identifier, a property access or a subscript. Only an unquoted identifier is handled (
c[1], through theARRAY_IDENTIFIERtoken).Before (15.9.0,
language: 'clickhouse'):After:
It is not limited to ClickHouse: BigQuery gives
SPLIT(s, ',') [OFFSET(1)]and`col` [0], and PostgreSQL gives"col" [1]andstring_to_array(s, ',') [1].Change
ExpressionFormatter.formatParenthesisnow removes the space in front of the node when it directly follows another node of the same list and(and the previous node is a function call (quantile(0.9)(x)), or[and the previous node is a function call, a parenthesis, a quoted identifier, a property access or a subscript.A parenthesis or bracket after a keyword is not affected, so
x IN [1, 2],IN (1, 2)andOVER (...)look as before. The parenthesis that belongs to a function call is handled as before, because it is not a node of the list.I tried a grammar change first, but the parser rejects ambiguous grammars and
f(a) (b)is already valid as two expressions. Looking at the previous node in the formatter avoids that.Tests
x IN [1, 2]keeps its space.pnpm exec jestpasses for all dialects (5890 passed, 1 skipped). No existing expectation changed.tsc --noEmit,prettier --checkandeslintare clean.Fixes #991.
This change was prepared with Claude Code (an AI coding assistant) and checked by running the full test suite locally.