Repository navigation
fix: stability fixes, more tests and a corpus runner - #15
Merged
Merged
Conversation
BigQuery and Snowflake allow `SELECT a, b, FROM t`, whose FROM was read as a column after the change that keeps a column named like a clause (ex. `offset`) in its list.
- specs for syntax no spec reached: subquery aliases, BETWEEN within conditions, comments before END, ELSE and EXCEPTION, lateral views, LOCK IN SHARE MODE, TOP PERCENT, SELECT AS STRUCT, MATCH_RECOGNIZE, number and quoted string literals, unfinished procedural code and unformattable bodies - specs for the casing and legacy uppercase options together, explicit preserve, joins as top level within a subquery, and range formatting in SQL Server, MySQL and PostgreSQL - give the specs whose input was already formatted messy input, so they check formatting rather than only stability - unit tests for checking the line breaks between joined strings and template tags in place, and a test of CRLF output
…E operands Found by formatting the corpus of real projects: - keep a block comment against the value after it (ex. MySQL's `/*!50705 x,*/'a'`), which once gained a space the second time - keep a `%` against the word after it (ex. `SELECT %x`, a Databricks `%python` magic), which once gained a space the second time - don't read a SET statement as a SQL*Plus command once its `=` is spaced (ex. `SET AUTOCOMMIT=0`), which refused to format it - don't break the branches of a CASE onto lines because its operand broke
`deno run -A scripts/corpus.ts` fetches only the .sql files of 14 projects pinned to commits (sqlfluff's fixtures, PostgreSQL's regression tests, pgTAP, SQL Server samples, the First Responder Kit, Ola Hallengren's maintenance solution, Oracle's sample schemas, test_db, sakila, chinook, bigquery-utils, Snowflake quickstarts, jaffle_shop and dbt-utils) and formats each in its own dialect, or in all of them with --all-dialects. It reports panics, refusals, unstable output, timeouts and slow files, and --compare <ref> writes how the output differs from the formatter at another ref. It isn't run in CI.
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.
These are the follow-ups to #14 that weren't pushed before it was merged.
Fixes
FROM:SELECT a, b, FROM t(valid in BigQuery and Snowflake) leftFROMon the list's line. This was a regression from the change that keeps a column named like a clause (ex.offset) in its list./*!50705 x,*/'2014-09-25'gained a space.SELECT %xbecame% x. Fixing this also keeps Databricks%pythonmagics and Exasol%jarintact.CASEwhose operand broke across lines at a narrow width moved its branches onto their own lines.SET AUTOCOMMIT=0;was refused, because once formatted it reads as a SQL*Plus command.Tests
BETWEENwithin other conditionsEND,ELSEandEXCEPTION, after an opening bracket, and after a list's last itemLOCK IN SHARE MODE,TOP (n) PERCENT,SELECT AS STRUCTandMATCH_RECOGNIZEq'<..>'strings$$bodiescasingand the legacyuppercasetogether, andcasing: preserveset explicitlyjoinsAsTopLevelwithin a subquerySpec-only line coverage goes from 94.1% to 95.3%.
Corpus runner
deno run -A scripts/corpus.tsfetches only the.sqlfiles of 14 projects pinned to commits, and formats each in its own dialect:It reports panics, refusals, unstable output, timeouts and slow files.
--all-dialectsformats every file in every dialect.--line-width 30,120formats at several widths.--compare <ref>writes how the output differs from the formatter at another ref.It isn't run in CI. How to use it is documented in
CLAUDE.md.It found the four bugs listed above. With them fixed, all 4,304 files run clean in every dialect at widths 30 and 120: no panics, refusals, unstable output or timeouts.