Skip to content

Commit

Permalink
Add correct formatting of bun placeholders (#358)
Browse files Browse the repository at this point in the history
* Add correct formatting of bun placeholders

* fix: add tests, tweak behavior for ?

Co-authored-by: Ted Conbeer <[email protected]>
  • Loading branch information
Yorick Smilda and tconbeer authored Jan 17, 2023
1 parent aef3c3e commit 575d5bd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- sqlfmt now supports `create <object> ... clone` statements ([#313](https://github.com/tconbeer/sqlfmt/issues/313)).
- sqlfmt will now format all files that end with `*.sql` and `*.sql.jinja`, even those with other dots in their filenames ([#354](https://github.com/tconbeer/sqlfmt/issues/354) - thank you [@ysmilda](https://github.com/ysmilda)!).
- fixed a bug where `{% call %}` blocks with arguments like `{% call(foo) bar(baz) %}` would cause a parsing error ([#353](https://github.com/tconbeer/sqlfmt/issues/353) - thank you [@IgnorantWalking](https://github.com/IgnorantWalking)!).
- sqlfmt now supports [bun placeholders](https://bun.uptrace.dev/guide/placeholders.html) ([#356](https://github.com/tconbeer/sqlfmt/issues/356) - thank you [@ysmilda](https://github.com/ysmilda)!)

### Features

Expand Down
1 change: 1 addition & 0 deletions src/sqlfmt/rules/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
r"\$\d+", # pg placeholders
r"\$\w+", # variables
r"%(\([^%()]+\))?s", # psycopg placeholders
r"\?\d+", # bun placeholders
),
action=partial(actions.add_node_to_buffer, token_type=TokenType.NAME),
),
Expand Down
4 changes: 2 additions & 2 deletions tests/data/unformatted/110_other_identifiers.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
select
v.$1, v.$2
v.$1, v.$2, ?3, ?4
from
@my_stage( file_format => 'csv_format', pattern => '.*my_pattern.*') v
)))))__SQLFMT_OUTPUT__(((((
select v.$1, v.$2
select v.$1, v.$2, ?3, ?4
from @my_stage(file_format => 'csv_format', pattern => '.*my_pattern.*') v
3 changes: 3 additions & 0 deletions tests/unit_tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(CORE, "operator", "|&>"),
(CORE, "operator", "<^"),
(CORE, "operator", ">^"),
(CORE, "operator", "?"),
(CORE, "operator", "?#"),
(CORE, "operator", "?-"),
(CORE, "operator", "?|"),
Expand Down Expand Up @@ -196,6 +197,7 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule:
(MAIN, "name", "my_table_45"),
(MAIN, "name", "replace"),
(MAIN, "other_identifiers", "$2"),
(MAIN, "other_identifiers", "?2"),
(MAIN, "other_identifiers", "$email"),
(MAIN, "other_identifiers", "@my_unquoted_stage"),
(MAIN, "other_identifiers", "%s"),
Expand Down Expand Up @@ -353,6 +355,7 @@ def test_regex_exact_match(
(CORE, "quoted_name", "my_unquoted_name"),
(CORE, "quoted_name", "$bar$foo$baz$"),
(CORE, "double_colon", ":"),
(CORE, "other_identifiers", "?"),
(CORE, "operator", "."),
(MAIN, "word_operator", "using"),
(MAIN, "unterm_keyword", "lateral flatten"),
Expand Down

0 comments on commit 575d5bd

Please sign in to comment.