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

Add Prettier plugins to format SQL in JS / TS #293

Merged
merged 1 commit into from
Oct 30, 2023

Conversation

karlhorky
Copy link
Member

@karlhorky karlhorky commented Oct 30, 2023

Our Prettier configuration has formatted almost all of the files that we use in our courses:

  • ✅ JavaScript and TypeScript w. JSX
  • ✅ CSS
  • ✅ CSS in template literals
  • ✅ GraphQL
  • ✅ GraphQL in template literals
  • ❌ SQL in template literals

Formatting SQL in template literals has not been easy to achieve, I've been waiting years for this.

Challenges:

  1. Although solutions like eslint-plugin-sql with eslint-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 slow
  2. Prettier plugins like prettier-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 literals
  3. Support for sql 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 with prettier-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

@karlhorky karlhorky merged commit 94c225a into main Oct 30, 2023
2 checks passed
@karlhorky karlhorky deleted the add-prettier-plugins-to-format-sql branch October 30, 2023 16:34
karlhorky added a commit to upleveled/next-js-example-fall-2023-atvie that referenced this pull request Oct 30, 2023
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.

None yet

1 participant