-
Notifications
You must be signed in to change notification settings - Fork 2
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql-formatter crash on SQL casts, tilde, square brackets, $$
delimiter
#35
Comments
::jsonb
SQL cast
Oh interesting, I just upgraded to
|
Patching -const canonicalDialectName = dialectNameMap[cfg.language || 'sql'];
+const canonicalDialectName = dialectNameMap['postgresql']; Maybe the option is being recognized / passed incorrectly through |
$$
delimiter
Check #26 and the introduction of A bit of explanation: I want to make this plugin be able to format different languages (dialects) in a single file. If we're to support |
Why not |
Definitely a choice if we add Given the rationale in #26 and this issue. I'm thinking maybe we should disable the identifier -> dialect mapping by default and respect the |
Without knowing too many details, this seems like a good approach. It would apply const config = {
plugins: ['prettier-plugin-embed', 'prettier-plugin-sql'],
embeddedSqlIdentifiers: ['sql'],
language: 'postgresql',
};
What about instead discarding the auto mapping altogether and requiring the user to set |
The reason why I keep auto mapping is that I want this plugin to be able to format various dialects based on the identifiers in a single file. I will add a new option to control the auto mapping behavior and disable it by default. This is a breaking change but it seems more reasonable and intuitive given the confusion caused. I plan to release it in the official v0.3.0. Edit:
Oh wait, maybe I'm wrong 馃ゲ, we can use |
@karlhorky I made a PR #39. You can test that branch with the codesandebox-ci built package: https://ci.codesandbox.io/status/Sec-ant/prettier-plugin-embed/pr/39 |
It's working for me 馃檶 for the
"prettier-plugin-embed": "https://pkg.csb.dev/Sec-ant/prettier-plugin-embed/commit/dc1eb180/prettier-plugin-embed" |
Thanks for #39 and the merge + publish! I can confirm this is working in |
Hi @Sec-ant , hope you're well! 馃憢
(very similar to #34, maybe the same issue)
sql-formatter
crashes withprettier-plugin-embed
, embedded SQL in JavaScript/TypeScript template string andprettier-plugin-sql
, when a cast is used:a.sql
a.js
$ pnpm prettier a.sql --write a.sql 58ms $ pnpm prettier a.js --write a.js Error: Parse error: Unexpected "::jsonb;" at line 1 column 12 at TokenizerEngine.createParseError (file:///Users/k/p/project/node_modules/sql-formatter/lib/lexer/TokenizerEngine.js:53:12) at TokenizerEngine.tokenize (file:///Users/k/p/project/node_modules/sql-formatter/lib/lexer/TokenizerEngine.js:35:22) at Tokenizer.tokenize (file:///Users/k/p/project/node_modules/sql-formatter/lib/lexer/Tokenizer.js:16:47) at LexerAdapter.tokenize (file:///Users/k/p/project/node_modules/sql-formatter/lib/parser/createParser.js:16:76) at LexerAdapter.reset (file:///Users/k/p/project/node_modules/sql-formatter/lib/parser/LexerAdapter.js:17:24) at Parser.feed (/Users/k/p/project/node_modules/nearley/lib/nearley.js:281:15) at Object.parse (file:///Users/k/p/project/node_modules/sql-formatter/lib/parser/createParser.js:26:18) at Formatter.parse (file:///Users/k/p/project/node_modules/sql-formatter/lib/formatter/Formatter.js:32:49) at Formatter.format (file:///Users/k/p/project/node_modules/sql-formatter/lib/formatter/Formatter.js:25:22) at formatDialect (file:///Users/k/p/project/node_modules/sql-formatter/lib/sqlFormatter.js:78:57) a.js 40ms (unchanged)
Other casts that also fail:
Tildes
This also crashes similarly on the
~
(tilde) operator:Error:
Square brackets for PostgreSQL exact length arrays
Another failing pattern:
$$
delimiter$$
SQL delimiter聽#34At first, from the error messages, I thought it was the lack of support for casts or tilde operators or square brackets in
sql-formatter
, but they are all supported withprettier-plugin-sql
when used directly with.sql
files.My versions and config, maybe I've configured something incorrectly? 馃
package.json
prettier.config.mjs
cc @JounQin
The text was updated successfully, but these errors were encountered: