PoorMansTSqlFormatter
PoorMansTSqlFormatter copied to clipboard
"Remove Clutter" options or even profile when formatting autogenerated sql scripts
Dan Dover references the following article, and suggests the formatter could provide options for more aggressively "cleaning up" the SQL provided (at least for T-SQL, the main supported SQL dialect for the moment): http://michaeljswart.com/2017/09/remove-sql-junk-brackets-and-other-clutter/
The idea then would be to add options for:
- Removing comments (already an option for the minifier, but could be introduced in main formatter)
- Removing square brackets on everything that doesn't seem to be a reserved keyword or otherwise unsafe identifier (eg starts with a number?)
- Removing batch separators
- Removing DDL "ON [PRIMARY]" clauses
- Removing ASC keyword from any sorting specifications (index definition or ORDER BY clause)
There are also more "edgy" less safe-looking things going on in the example that I don't really want to consider:
- Removing "SET QUOTED_IDENTIFIER" script interpretation settings (you think you're being clever and succinct, but really you're just opening the door to horrendous obscure bugs! see https://stackoverflow.com/questions/8439460/stop-sql-server-management-studio-from-adding-ansi-nulls-and-quoted-identifier/8447220#8447220)
- Vertically aligned indenting (tracked elsewhere: Issue #64)
- Removing (non-default?) index properties
Assuming that these options made sense for this type of application (cleaning up / decluttering auto-generated scripts), there would also be a need for "formatting profiles" - for example an everyday "keep my comments and be paranoid about changing my semantics" profile, vs an occasional "radically clean up this autogenerated script" profile.
At least one aspect of this has previously been discussed, and I had forgotten: in Issue #133