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

Single dialect import #511

Merged
merged 9 commits into from
Nov 4, 2022
Merged

Single dialect import #511

merged 9 commits into from
Nov 4, 2022

Conversation

nene
Copy link
Collaborator

@nene nene commented Nov 2, 2022

New API for supporting import of a single dialect. As discussed in #484, I've added a separate formatting function that works a bit differently than the old one.

The old format() function works like before, with the exception that language parameter can only be string:

import { format } from "sql-formatter";

format("SELECT *", { language: "mysql" });

The new formatDialect() only works with explicitly imported dialect:

import { formatDialect, mysql } from "sql-formatter";

formatDialect("SELECT *", { dialect: mysql });

formatDialect() is also used under the hood by the old format() function.

I chose to name it formatDialect to make it clear that it accepts a dialect config option (instead of language). This also aligns with the naming of types, where the actual value is a DialectOptions object. (Originally I thought of using language option for both, but this seemed too confusing - an option expecting one type in one context and another type in another context - so I opted for clearly distinct option names).

Fixes #452

@nene nene requested a review from inferrinizzard November 2, 2022 12:59
nene added 2 commits November 2, 2022 15:03
Also add comment to avoid removing this syntax in the future
export * from './allDialects.js';

// NB! To re-export types the "export type" syntax is required by webpack.
// Otherwise webpack build will fail.
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's an eslint-typescript rule here we can leverage, use-consistent-type-exports

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can make a PR to update eslint rules soon

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good find. I added the rule on my own. Seems to work just as needed.

@nene nene merged commit c6d9fda into master Nov 4, 2022
@nene nene deleted the single-dialect-import branch November 4, 2022 17:00
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.

Explicitly include a single dialect
2 participants