feat(preview): auto format generated code in preview mode#1794
feat(preview): auto format generated code in preview mode#1794chilingling wants to merge 1 commit intoopentiny:developfrom
Conversation
- 在公共 AST 工具中增加对 Vue 和 Less 格式化的支持。 - 实现基于文件扩展名的 Prettier 解析器自动选择功能。 - 确保页面预览/应用预览中所有生成的代码文件(脚本、模板及配置文件)均经过格式化,以提升可读性。
WalkthroughThe pull request adds Vue and LESS formatting support to the codebase, refactors formatting infrastructure with a new file-based formatting utility, and applies these formatters to page code generation and preview file outputs. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/common/js/ast.ts (1)
144-163: Consider usingconsole.errorfor error logging.The error handling safely returns the original string on failure, which is the right fallback behavior. However, using
console.errorwould be more semantically appropriate for error cases.Suggested change
} catch (error) { const printer: Console = console - printer.log(error) + printer.error(error) return str }The same applies to
formatStringat line 138.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/common/js/ast.ts` around lines 144 - 163, The catch blocks in formatStringByFileName (and similarly formatString) log errors using console.log via a local printer variable; change these to use console.error directly to reflect error severity and remove the unnecessary printer variable—i.e., in formatStringByFileName and formatString catch clauses replace the printer.log(error) pattern with console.error(error) (or a message plus error) so failures are logged as errors while still returning the original string.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/common/js/ast.ts`:
- Around line 144-163: The catch blocks in formatStringByFileName (and similarly
formatString) log errors using console.log via a local printer variable; change
these to use console.error directly to reflect error severity and remove the
unnecessary printer variable—i.e., in formatStringByFileName and formatString
catch clauses replace the printer.log(error) pattern with console.error(error)
(or a message plus error) so failures are logged as errors while still returning
the original string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6783502b-2de2-4119-9cc2-f8bdc54b6d59
📒 Files selected for processing (3)
packages/common/composable/generateCode/index.tspackages/common/js/ast.tspackages/design-core/src/preview/src/preview/usePreviewData.ts
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
【before】
页面:https://opentiny.github.io/tiny-engine/?type=app&id=1&tenant=1&pageid=215
预览页面:https://opentiny.github.io/tiny-engine/preview.html?tenant=1&id=1&theme=light&framework=Vue&platform=1&pageid=215&previewType=page
【after】
页面:https://chilingling.github.io/tiny-engine/?type=app&id=1&tenant=1&pageid=215
预览页面:https://chilingling.github.io/tiny-engine/preview.html?tenant=1&id=1&theme=light&framework=Vue&platform=1&pageid=215&previewType=page
What is the current behavior?
Issue Number: #1748
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit