JohnnyMorganz / StyLua

An opinionated Lua code formatter
Mozilla Public License 2.0
1.53k stars 68 forks source link

feat: Support LuaCATS comment formatting #851

Open UtkarshVerma opened 8 months ago

UtkarshVerma commented 8 months ago

LuaCATS offers a way to specify the types through comments. Currently, stylua does not format it. For example, the code below:

---@param server string
---@param cond fun( root_dir, config): boolean
function M.disable(server, cond) end

should be formatted as:

---@param server string
---@param cond fun(root_dir, config): boolean
function M.disable(server, cond) end
JohnnyMorganz commented 8 months ago

It will be somewhat difficult to support this. We currently don't bother formatting comments at all, since comments could consist of anything.

We could support formatting specifically doc comments, however there is no "standardised" way of defining documentation comments in Lua (luadoc, emmylua, LuaCATs, moonwave, etc.), so it isn't clear which one, if any, we should support.

lewis6991 commented 4 months ago

At the very minimum, we could enforce consistent whitespace in doc comments:

---text1
--- text2
--- @param a
---@return string

becomes:

--- text1
--- text2
--- @param a
--- @return string

Where the padding maybe configurable.

seflue commented 3 months ago

Also line-breaks would be very nice to have. If I write some longer API documentation, it would be great, if stylua could at least wrap long lines to what was specified in column_width.