Formatting indenting issue #1

Closed
opened 2026-07-15 13:41:58 +00:00 by warkanum · 2 comments
Owner
  • The then should follow on the same level as the if when on a newline.
  • The set/where should also follow on the same level of indent for update/insert/delete statements.

Broken:

 if r_lp.total > 0
    and r_lp.totaldone >= r_lp.total
  then
  update core.process u 
    set status = 'done'
    where u.rid_process = r_lp.rid_process
      and nv(u.status) <> 'done';
elsif r_lp.total > 0
  then
  update core.process u
    set status = 'open'
    where u.rid_process = r_lp.rid_process
      and nv(u.status) <> 'open';

end if;

Correct:

if r_lp.total > 0
  and r_lp.totaldone >= r_lp.total
then
  update core.process u
  set status = 'done'
  where
      u.rid_process = r_lp.rid_process
  and nv(u.status) <> 'done';
elsif r_lp.total > 0
then
  update core.process u
  set status = 'open'
  where
      u.rid_process = r_lp.rid_process
  and nv(u.status) <> 'open';

end if;

Remember to keep the indent level in context of parent if/with/loop etc statements.

- The then should follow on the same level as the if when on a newline. - The set/where should also follow on the same level of indent for update/insert/delete statements. Broken: ```sql if r_lp.total > 0 and r_lp.totaldone >= r_lp.total then update core.process u set status = 'done' where u.rid_process = r_lp.rid_process and nv(u.status) <> 'done'; elsif r_lp.total > 0 then update core.process u set status = 'open' where u.rid_process = r_lp.rid_process and nv(u.status) <> 'open'; end if; ``` Correct: ```sql if r_lp.total > 0 and r_lp.totaldone >= r_lp.total then update core.process u set status = 'done' where u.rid_process = r_lp.rid_process and nv(u.status) <> 'done'; elsif r_lp.total > 0 then update core.process u set status = 'open' where u.rid_process = r_lp.rid_process and nv(u.status) <> 'open'; end if; ``` Remember to keep the indent level in context of parent if/with/loop etc statements.
Member

Implemented in PR #2: #2

Branch: issue-1-formatting-indenting
Commit: 5cba6beeb1

Verification:

  • PASS: go test ./pkg/format -run TestFormatIssue1PLpgSQLIndenting -count=1
  • PASS: go test ./pkg/format -count=1
  • PASS: go build ./cmd/pgtidy
  • PASS: go vet ./...
  • CAVEAT: go test ./... currently fails in pkg/lsp TestFormatting with timeout waiting for response. The same test passed once in isolation earlier during this run, then timed out on later retries; formatting package tests pass consistently.

Notes:

  • Aligns standalone PL/pgSQL THEN with IF/ELSIF indentation.
  • Realigns top-level UPDATE/DELETE SET/WHERE/AND/OR lines inside PL/pgSQL while preserving nested subquery indentation.
  • Updated affected corpus golden output.
Implemented in PR #2: https://git.warky.dev/wdevs/PgTidy/pulls/2 Branch: issue-1-formatting-indenting Commit: 5cba6beeb1d3c56225c36dae036063f3daf2c657 Verification: - PASS: go test ./pkg/format -run TestFormatIssue1PLpgSQLIndenting -count=1 - PASS: go test ./pkg/format -count=1 - PASS: go build ./cmd/pgtidy - PASS: go vet ./... - CAVEAT: go test ./... currently fails in pkg/lsp TestFormatting with timeout waiting for response. The same test passed once in isolation earlier during this run, then timed out on later retries; formatting package tests pass consistently. Notes: - Aligns standalone PL/pgSQL THEN with IF/ELSIF indentation. - Realigns top-level UPDATE/DELETE SET/WHERE/AND/OR lines inside PL/pgSQL while preserving nested subquery indentation. - Updated affected corpus golden output.
Author
Owner

merged

merged
Sign in to join this conversation.
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wdevs/PgTidy#1