-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to configure newline after keywords #66
Comments
With #75 it should be possible to have the last layout specified, but it would need another bit of logic to inline the next top level keyword. |
Towards addressing shssoichiro#66 a bit more.
Towards addressing shssoichiro#66 a bit more.
Towards addressing shssoichiro#66 a bit more.
Towards addressing shssoichiro#66 a bit more.
Towards addressing shssoichiro#66 a bit more.
Now we have a mean to have a fairly compact formatting: fn it_formats_blocks_inline_or_not() {
let input = " UPDATE t SET o = ($5 + $6 + $7 + $8),a = CASE WHEN $2
THEN NULL ELSE COALESCE($3, b) END, b = CASE WHEN $4 THEN NULL ELSE
COALESCE($5, b) END, s = (SELECT true FROM bar WHERE bar.foo = $99),
c = CASE WHEN $6 THEN NULL ELSE COALESCE($7, c) END,
d = CASE WHEN $8 THEN NULL ELSE COALESCE($9, d) END,
e = (SELECT true FROM bar) WHERE id = $1";
let options = FormatOptions {
max_inline_arguments: Some(50),
max_inline_block: 100,
max_inline_top_level: Some(10),
..Default::default()
};
let expected = indoc!(
"
UPDATE t
SET
o = ($5 + $6 + $7 + $8),
a = CASE WHEN $2 THEN NULL ELSE COALESCE($3, b) END,
b = CASE WHEN $4 THEN NULL ELSE COALESCE($5, b) END,
s = (SELECT true FROM bar WHERE bar.foo = $99),
c = CASE WHEN $6 THEN NULL ELSE COALESCE($7, c) END,
d = CASE WHEN $8 THEN NULL ELSE COALESCE($9, d) END,
e = (SELECT true FROM bar)
WHERE id = $1"
);
assert_eq!(format(input, &QueryParams::None, &options), expected);
} I'm only unsure if |
Oh that's sweet! We're about to release Deno 2.2 next week, so it would be lovely if we could include that setting. |
It needs more tweaking and fixes, it doesn't yet return in the columnar mode correctly when limits are hit. |
The hack from last night was abusing the different rules pretty much twisting them to the opposite of what they should, if somebody wants to help we need to:
|
#[test]
fn it_formats_blocks_inline_or_not() {
let input: &str = " UPDATE t SET o = ($5 + $6 + $7 + $8),a = CASE WHEN $2
THEN NULL ELSE COALESCE($3, b) END, b = CASE WHEN $4 THEN NULL ELSE
COALESCE($5, b) END, s = (SELECT true FROM bar WHERE bar.foo = $99 AND bar.foo > $100),
c = CASE WHEN $6 THEN NULL ELSE COALESCE($7, c) END,
d = CASE WHEN $8 THEN NULL ELSE COALESCE($9, dddddddd) + bbbbb END,
e = (SELECT true FROM bar) WHERE id = $1";
let options: FormatOptions<'_> = FormatOptions {
max_inline_arguments: Some(60),
max_inline_block: 60,
max_inline_top_level: Some(60),
..Default::default()
};
let expected: &str = indoc!(
"
UPDATE t
SET
o = ($5 + $6 + $7 + $8),
a = CASE WHEN $2 THEN NULL ELSE COALESCE($3, b) END,
b = CASE WHEN $4 THEN NULL ELSE COALESCE($5, b) END,
s = (
SELECT true
FROM bar
WHERE bar.foo = $99
AND bar.foo > $100
),
c = CASE WHEN $6 THEN NULL ELSE COALESCE($7, c) END,
d = CASE
WHEN $8 THEN NULL
ELSE COALESCE($9, dddddddd) + bbbbb
END,
e = (SELECT true FROM bar)
WHERE id = $1"
);
assert_eq!(format(input, &QueryParams::None, &options), expected);
} Now we are getting closer. |
A query like this:
gets formatted as:
Would it be possible to configure the formatter to only add newline if there is more than one item following a keyword?
So in another example I'd like to be able to format this:
into this:
The text was updated successfully, but these errors were encountered: