-
Notifications
You must be signed in to change notification settings - Fork 134
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
fix formatSQL error #1214
fix formatSQL error #1214
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Codecov Report
@@ Coverage Diff @@
## master #1214 +/- ##
==========================================
- Coverage 31.54% 22.34% -9.21%
==========================================
Files 291 164 -127
Lines 17104 14140 -2964
Branches 684 0 -684
==========================================
- Hits 5395 3159 -2236
+ Misses 11478 10750 -728
Partials 231 231
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
So what's wrong with the things produced by vite and esbuild? Are there bugs in esbuild? What is the real expected behavior? Is it possible to fix esbuild, or make workarounds in sql-formatter-plus-plus to skip the bug? |
I think so, I digged it but have no idea how to figure it out, I have reported issue to esbuild: evanw/esbuild#2181 (it seems has one reply now, let me have a look) |
Thanks for the esbuild issue reply, now I have an idea to resolve it by + import { format } from 'sql-formatter-plus-plus/dist/sql-formatter'
- import { format } from 'sql-formatter-plus-plus" we import from the bundled sql-formatter-plus-plus then we can avoid the dynamic require issue. I can forked the |
Cool! It would be better if we can dig into why esbuild cannot work with a library, by finding out a minimal reproducible example (i.e. a specific code pattern that causes the problem). In this way esbuild can be improved (if there are bugs) and the community can be benefited. |
Finally, forked the
See details from the PR work with esbuild and adjust tidb sql Also have tried fix the upstream |
// } | ||
|
||
import { format } from 'sql-formatter' | ||
import { format } from '@baurine/sql-formatter-plus' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should ensure that tests are contained in order to avoid regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will add them back in the dashboard. I added them in the @baurine/sql-formatter-plus
as well.
Fix formatSQL() error by
sql-formatter
and close #1157 as wellCurrently some SQLs are failed to format, and it reports the following error:
The root cause is discussed here: sql-formatter-org/sql-formatter#147 , and a forked repo - prettier-sql resolved it.
I did some comparisons between
sql-formatter
andsql-formatter-plus-plus
.Target SQL:
It reports the following error when formating the above target sql by
sql-formatter-plus-plus
with vite(dev/prod) and esbuild, reported issue to esbuild: evanw/esbuild#2181Target SQL:
It reports the beginning error by
sql-formatter
with all (webpack/vite/esbuild).About unit test.
I found it's not easy to do unit test when we using esbuild. if we use
jest
, it will bring babel back, and the test result may not be correct. See above table,sql-formatter-plus-plus
works fine with wepback but not with vite/esbuild.So I did some a simple way, test it directly under the method definition, but only run it in dev and CI mode.