Skip to content

feat(editor): configurable SQL formatter rules - #3740

Merged
datlechin merged 4 commits into
mainfrom
feat/2529-formatter-rules
Oct 21, 2026
Merged

datlechin merged 4 commits into
mainfrom
feat/2529-formatter-rules

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Settings > Editor > Formatter: indent with spaces or tabs, indent width (or the editor's Tab width), keyword case (or the editor's), function case, comma position, line width, join condition placement, alias alignment, and a live preview in the editor theme.
  • Import… and Export… a rules file. Export writes resolved values, so another Mac with a different Tab width or Keyword case formats identically.
  • A .sql-formatter.json in a linked SQL folder applies to files opened from it: the nearest one from the file's folder up to the linked folder root. One that can't be read (bad value, not JSON, over 64 KB, not a regular file) stops Format Query with an error sheet naming it.
  • Formatter settings sync as their own formatter settings record, so an older build re-uploading the editor blob can't reset them. A Mac upgrading to this build fetches the zone once to pick up a formatter record it skipped.
  • Function case touches calls only (count(*), not a column named count), never on an engine whose dialect says function names are case-sensitive (ClickHouse), and never on a qualified name (dbo.len(x)).
  • Defaults format exactly as before. Formatter fixes that ship with the rework:
    • commas inside a function call no longer break the SELECT list (concat(a,\n b))
    • FROM, WHERE, ORDER BY, JOIN inside parentheses stay inline (EXTRACT(YEAR FROM d), FILTER (WHERE …), STRING_AGG(… ORDER BY …))
    • CHARACTER SET, WITH TIME ZONE and ON DELETE CASCADE no longer break a CREATE TABLE column list
    • EXPLAIN SELECT and EXPLAIN UPDATE no longer come out as EXPLAINSELECT
    • FOR UPDATE, ON DUPLICATE KEY UPDATE a = VALUES(a) and GRANT SELECT, INSERT stay on their line
    • a keyword beside a dot is a name: e.end no longer splits into e. and END, t.key keeps its case

Test plan

  • SQLFormatterServiceTests: exact output for every option, each fixed case, and idempotency under option sets. The fixed cases fail on main.
  • SQLFormatterRulesTests: rules file round trip, strict decode errors, size cap, symlink to /dev/zero refused, settings resolution, export on one Mac and import on another formats identically, storage and reset, sync category and upgrade refetch, linked folder lookup.
  • Old and new formatter run over a 40-statement corpus with default rules: byte-identical except the fixed cases.

Not in this PR

  • A comment inside a SELECT list leaves a whitespace-only line and the next column loses its alignment (same on main).
  • A subquery inside a SELECT list indents by block depth, not under its column (same on main).
  • NATURAL LEFT JOIN breaks after NATURAL (same on main).
  • Reset All Settings does not reset Notifications: AppSettingsManager.resetToDefaults() and AppSettingsStorage.resetToDefaults() skip it.

Fixes #2529

@datlechin
datlechin enabled auto-merge (squash) October 21, 2026 05:57
@datlechin
datlechin merged commit ee782b3 into main Oct 21, 2026
8 checks passed
@datlechin
datlechin deleted the feat/2529-formatter-rules branch October 21, 2026 08:50
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.

Configurable SQL formatter rules

1 participant