maddyblue / sqlfmt

SQL formatter with width-aware output
https://sqlfum.pt
Apache License 2.0
411 stars 20 forks source link

How to configure with vim? #68

Open coolaj86 opened 6 days ago

coolaj86 commented 6 days ago

I tried to configure this with vim based on... the LLM that shall not be named... but when I add this to my ~/.vimrc it deletes the file and replaces it with the error message on error.

" Auto-format SQL files with sqlfmt on save
autocmd BufWritePre *.sql execute ':silent %!sqlfmt'

A misplaced comma like this

CREATE TABLE IF NOT EXISTS "customers" (
    "id" UUID PRIMARY KEY,
    "nickname" VARCHAR(255),
);

becomes

at or near ")": syntax error
maddyblue commented 6 days ago

Ah! sqlfmt should be changed to exit with non-zero in this case to communicate to tools that...there was an error. Or it should have a cli flag that ignores errors and outputs the input unchanged. Or it does everything: non-zero exit code, copies input directly to stdout, prints error on stderr. That'd enable tools to decide what to do on error. I'm unlikely to make this change, but would review such a PR.