-
Notifications
You must be signed in to change notification settings - Fork 0
Add Stylua Support for Lua Formatting #5
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
Conversation
- Create new Stylua formatter module following existing patterns - Update formatter registry to use Stylua for Lua files - Update configuration defaults to include Stylua for Lua - Update README documentation to mention Stylua requirements This replaces the previous fallback to Python formatter (autopep8) for Lua files with proper Stylua formatting, which is more appropriate for Lua code. Fixes #4 Co-authored-by: Li Haoyuan <[email protected]>
136aa0b
to
50d8d30
Compare
Code Review: Stylua Support ImplementationOverview The PR successfully adds Stylua support for Lua formatting, replacing the Python formatter fallback. The implementation follows existing patterns and maintains backward compatibility. Detailed Review
Follows established patterns: Inherits from BaseFormatter correctly a) Security concern - Command injection vulnerability: -- Current implementation (stylua.lua:50) b) Missing Stylua configuration support: No way to pass Stylua configuration options When formatting fails, the original text is returned silently Clean registration of Stylua for Lua files Inconsistent formatter mapping: Lines 18-22 still map Java, JavaScript, JSON, ActionScript, and Ruby to Python formatter. This seems like a legacy mapping that might need review. Clean addition of Stylua to default formatters Clear requirements section updated with Stylua local cmd = {"stylua", "-"} if vim.v.shell_error ~= 0 then return vim.trim(result) -- Look for .stylua.toml in project root local result = vim.fn.system(cmd, text) Approval Recommendation: ✅ Approve with minor fixes - The security issue should be addressed before merging, but this is a good addition to the codebase. Great! @claude Help me improve the code based on this review. |
- Fix security vulnerability by using table-based command instead of string - Add automatic .stylua.toml and stylua.toml configuration detection - Improve error handling with user notifications on formatting failures - Update documentation with Stylua configuration examples - Maintain backward compatibility with existing functionality Security fixes: - Replace vim.fn.system(cmd, text) with vim.fn.system({stylua, -}, text) - Add proper argument escaping through table-based command construction Configuration improvements: - Auto-detect .stylua.toml and stylua.toml in project hierarchy - Support both dotted and non-dotted configuration filenames - Add comprehensive documentation and examples Co-authored-by: Li Haoyuan <[email protected]>
- Add caching mechanism for Stylua configuration file paths - Cache config paths per working directory to avoid repeated lookups - Improve performance by reducing file system operations - Maintain compatibility with existing API and behavior Co-authored-by: Li Haoyuan <[email protected]>
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.
Good job
This PR adds full Stylua support to reform.nvim, replacing the previous Python formatter fallback for Lua files.
Changes
Benefits
Fixes #4
🤖 Generated with Claude Code