Add Prettier plugins to format SQL in JS / TS #293
Merged
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.
Our Prettier configuration has formatted almost all of the files that we use in our courses:
Formatting SQL in template literals has not been easy to achieve, I've been waiting years for this.
Challenges:
eslint-plugin-sql
witheslint-plugin-unicorn
exist in the ESLint ecosystem (lint problems on non-formatted strings, with auto-fix) we don't really want to require students to enable auto-fix in ESLint, because it's slowprettier-plugin-sql
,@potygen/prettier-plugin-pgsql
,prettier-plugin-pg
(not ready) do exist, but they do not format SQL code inside JavaScript/TypeScript tagged template literalssql
tagged template literals in Prettier core has been proposed a number of times and rejected or stagnated:Recently @Sec-ant announced a new amazing
prettier-plugin-embed
plugin in this comment, which works as follows for configuring withprettier-plugin-sql
:This PR adds support for formatting SQL in template literals using these new packages.
Upgrade eemo:
$ pnpm prettier --write .
Commit: upleveled/next-js-example-fall-2023-atvie@53a0971
Kapture.2023-10-30.at.17.45.09.mp4