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

fix: solve the problem of not being able to format wxml with Prettier #185

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

anjianshi
Copy link
Contributor

解决了什么问题:
现在配置 "minapp-vscode.wxmlFormatter": "prettier" 不生效。
检查 VSCode 日志,出现了 TypeError: u.replace is not a function 的错误,
向上追查,是因为此插件本应返回字符串的格式化结果但却返回了一个对象,
原因就是插件里调用了 prettier.format(),在新版 Prettier 里此方法返回的是 promise,需要 await 才能取得字符串结果。

Prettier 的相关文档:https://prettier.io/docs/en/api#prettierformatsource-options
Prettier 中此 API 变更的 Commit:prettier/prettier@c6d6b25

代码如何实现:
调用 Prettier 的地方改为了 await prettier.format()
不用担心这会导致旧版 Prettier 运行失败,因为 await 对于非 Promise 值会原样返回。

检查清单:

  • 本地测试通过

@iChenLei iChenLei changed the title 解决无法用 Prettier 格式化 wxml 的问题 fix: solve the problem of not being able to format wxml with Prettier Nov 23, 2024
Copy link
Member

@iChenLei iChenLei left a comment

Choose a reason for hiding this comment

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

LGTM

@iChenLei iChenLei merged commit 0240d63 into wx-minapp:main Nov 23, 2024
1 check passed
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.

2 participants