Skip to content
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

Split clauses into two groups: multiline & single line #483

Merged
merged 32 commits into from Oct 5, 2022
Merged

Conversation

nene
Copy link
Collaborator

@nene nene commented Oct 1, 2022

So far pretty much all SQL clauses have been formatted like so:

CLAUSE_NAME
  more sql here

However, for many clauses this is not really how one would normally format SQL. For example, one rarely formats SQL like so:

TRUNCATE TABLE
  customers;

Rather one would format this on a single line:

TRUNCATE TABLE customers;

This change makes it so, that by default all clauses get formatted in the latter way. i.e. all clauses for which we don't have specific tests as to how we'd want them to be formatted. Most dialects have this sort of kitchen-sink list of clauses that's just been copied there from documentation. So these are all now being formatted in this one-line style. This will also aligns more with how the default sql-dialect formatter handles unknown SQL syntax.

Also hand-picked a few clauses for which I wanted to intentionally apply this style:

  • TRUNCATE TABLE
  • SET SCHEMA
  • ALTER TABLE
  • DROP TABLE
  • DELETE FROM
  • UPDATE

As a bonus, this also:


// Contains the same data as DialectFormatOptions,
// but optimized for faster and more conventient lookup.
export interface ProcessedDialectFormatOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we not just use this as the default interface for DialectFormatOptions and add a wrapper function to transform the string[] into Record ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not only the onlineClauses field that differs. It's also the alwaysDenseOperators field which is originally optional, but then processed to be empty array if missing.

// but optimized for faster and more conventient lookup.
export interface ProcessedDialectFormatOptions {
alwaysDenseOperators: string[];
onelineClauses: Record<string, boolean>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be

Suggested change
onelineClauses: Record<string, boolean>;
onelineClauses: Record<string, true>;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that, but in this case TypeScript thinks that onlineClauses[anything] always evaluates to true.

@nene nene merged commit 274fb17 into master Oct 5, 2022
@nene nene deleted the oneline-clauses branch October 5, 2022 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FORMATTING] [MySQL] Newline after USE keyword causes syntax error
2 participants