Releases: JohnnyMorganz/StyLua
Releases · JohnnyMorganz/StyLua
v0.9.2
[0.9.2] - 2021-06-20
Changed
- Bumped full-moon to
0.12.1to fix parsing bugs
Fixed
- Fixed parentheses around type assertions being classed as unnecessary and removed under the
luaufeature flag. - Fixed mistransformation of function type where arguments have comments under the
luaufeature flag. (#201) - Fixed comments in an assignment in between the equals token and the expression leading to a mistransformation. (#200)
v0.9.1
[0.9.1] - 2021-06-17
Added
- Added
--stdin-filepathoption to specify location of file being taken in from stdin. This is optional and is only used to determine where to find the configuration file. If not provided, we default to searching from current working directory. (#192)
Fixed
- Fixed empty functions with comments being incorrectly collapsed leading to syntax error. (#195)
v0.9.0
[0.9.0] - 2021-06-15
Added
- CLI will now look for
stylua.tomland its hidden counterpart,.stylua.toml. (#145) - Added CLI flag
--search-parent-directories. If enabled, we will look in parent directories for a configuration file, or look in$XDG_CONFIG_HOMEor$XDG_CONFIG_HOME/stylua. (#127, #146) - Updated full-moon: Added support for typed variadics, named function type args, and generic functions under the Luau feature flag
- Will now hang on equality operators within binary expressions, if over width.
- If a file path is explicitly provided to the CLI which doesn't end with
.luaending, the*.luaglob check is skipped. (#170) - Long type unions will now hang under the
luaufeature flag. (#165) - Added option
no_call_parentheses. Enabling this config will remove parentheses around function calls taking a single string/table as an argument. This config was added for adoption purposes. (#133)
Changed
- Long prefix expressions which are hangable and go over the line limit (e.g.
("foooo" .. "barrrrrrr" .. "bazzzzzz"):format(...)) will now hang multiline (#139) - Changed formatting for assignments. We will now try all tactics then determine the best one. Multiple assignments will now no longer attempt to hang a single expression first - we will hang the whole punctuated list. (#157)
- Function calls with single arguments are now possible to be expanded. This will allow the call to be expanded if the line goes over budget. (#156)
- StyLua will now firstly prefer hanging long arguments to function calls to try and fit under the width, before expanding them multiline. (#159)
- When hanging a binary expression, previously, we would always hang the "root" node of AST BinExp tree. Now we will check to see if is necessary (we are over width) before hanging (#163)
- StyLua will hug together table braces with function call parentheses when formatting a function call taking a single table as an argument. (#182)
- Function calls with more than one argument, where an argument is "complex", will now expand multiline. "complex" is an argument spanning multiple lines, but excludes a table or anonymous function, as we handle them explicitly. (#183)
- StyLua will always hang at the equals token for a multi-variable assignment. (#185)
- Tables with multiline fields (such as an anonymous function expression) should always expand if previously on single line. (#187)
- Function definitions (both normal and anonymous) with an empty body will now be kept on a single line. This is common for noop functions
local function noop() end. (#188)
Fixed
- Fixed 1 or 2 digit numerical escapes being incorrectly removed
- Fixed whitespace being lost before a multiline comment. We will now preserve a single space (e.g.
local test --[[foo]] = true->local test --[[foo]] = true) (#136) - Fixed the double formatting of a hanging call chain when it was being assigned to a variable causing it to be incorrectly formatted (#151)
- Fixed leading comments to a binop in a hanging expression being lost (#154)
- Fixed mistransformation of comments leading the RHS of a hanging binop. They are now moved to before the binop (#154)
- Fixed comments trailing unnecessary parentheses around expressions that were later removed not being preserved (#176)
- Fixed a double unary minus (
- -foo/-(-foo)) being formatted as--fooleading to a comment syntax error. Parentheses are now enforced:-(-foo)(#171) - Fixed semicolon being removed leading to
function call x new statementambiguity when next statement is an assignment with the first variable being a parentheses var expression (#173) - Fixed mistransformation of comments in
if condition thenorwhile condition dolines - improved assurance that they will hang multiline (#164) - Fixed indentation of comments leading a
thenordotoken whenif ... thenorwhile ... doare multiline. - Fixed mistransformation of comments in a generic declaration under the
luaufeature flag (#166) - Fixed trailing comma being added after comments in multiline type table under the
luaufeature flag (#166)
v0.8.1
[0.8.1] - 2021-04-30
Fixed
- Fixed bug where a hanging expression inside of parentheses would lead to function arguments being incorrectly formatted with a trailing comma - leading to a syntax error
v0.8.0
[0.8.0] - 2021-04-30
Added
- Parentheses around conditions are now removed, as they are not required in Lua.
if (foo and (not bar or baz)) then ... endturns toif foo and (not bar or baz) then ... end - Long multi-variable assignments which surpass the column width, even when hanging on the equals token, will now hang on multiple lines.
Changed
- Changed the heursitics for when parentheses are removed around expressions. Parentheses will now never be removed around a function call prefix (e.g.
("hello"):len()) - Changed formatting for comma-separated lists. Previously, we would buffer the comments to the end of the list, but now we keep the comments next to where they original were.
- Improved contextual formatting informattion when formatting deep in the AST. We can now better determine how much space is left on the current line, before we need to change formatting
- Improved formatting of function declarations. It will now properly take into account the amount of space left on the column width.
- Improve formatting for assignments with expressions such as function calls. The whole assignment is now taken into account, so we can better determine whether to split the expression.
Fixed
- Fixed trailing whitespace remaining on the last item of a multiline table (which was expanded from a singleline one)
v0.7.1
[0.7.1] - 2021-04-19
Fixed
- Fixed parentheses around a table being incorrectly removed leading to a syntax error, such as in
({}):foo()
v0.7.0
[0.7.0] - 2021-04-13
Added
- Added hanging for chained function calls. See #109
- Long function definitions (normally with parameters containing types and a return type) will now be split across multiple lines if they surpass the column limit
Changed
- Further improvements to the way binary expressions are hung on new lines
Fixed
- Fixed trailing comments at the end of multiline tables being lost
- Fixed panic "stmt trailing comments not implemented" occuring due to incomplete function
- Fixed trailing comments after semicolons at the end of last statements being lost when formatting
- Fixed function parameters collapsing when there is a comments at the end of function parameters, where the last parameter has a type specifier
- Fixed comments at the end of tables being indented one extra level
- Fixed trailing comments within if-elseif-else blocks not being correctly indented.
- Fixed
doin awhile ... dostatement not correctly indented when the condition spans multiple lines - Fixed multiline parameters for a function definition inside of an indent block (e.g. a table) not being correctly indented
v0.6.0
[0.6.0] - 2021-03-27
Added
- Added support for creating new
Configstructs when using StyLua as a library - Added configuration for quote style. There are four quote style options -
AutoPreferDouble,AutoPreferSingle,ForceDoubleandForceSingle.
For the auto styles, we will prefer the quote type specified, but fall back to the opposite if it means there are fewer escapes. For the
force styles, we will always use the quote type specified. - StyLua will now error when unknown fields are found in the configuration
stylua.tomlfile - Long lines of assignments, where the expressions aren't hangable, will now be put onto a newline, where a newline is created after the equal sign, and the expressions indented.
- Added initial support for Lua 5.2 syntax. StyLua can now format code containing
gotos and labels. See #87 to track further support for Lua 5.2 syntax.
Changed
- Function call heuristic have been further improve to decide when to expand the function call arguments onto multiple lines.
- StyLua now allows some arguments after a multiline table before forcing expansion. This makes sense for something like
setmetatable({ ... }, class), where
{ ... }is a multiline table, but we don't want to expand onto multiple lines. StyLua will not allow a mixture of multiline tables and small identifiers in between
(e.g.call({ ... }, foo, { ... })), in order to improve readability. - Empty newlines at the start and end of a block will now be removed as they are unnecessary
- Changed the default quote style from
ForceDoubletoAutoPreferDouble. We will now default to swapping quote type if it will reduce the number of escapes.
Fixed
- Fixed tables with internal comments (and no fields) incorrectly collapsing to a single line
- Fixed parentheses being incorrectly removed around a BinOp where first value was a UnOp
- Fixed indentation of leading comments bound to the end brace of a multiline table
- Fixed LastStmt (return/break etc.) still being formatted when it wasn't defined inside the range
- Fixed hanging expressions which are inside function calls being indented unnecessarily by one extra level
- Fixed parentheses being incorrectly removed around a function definition, which may be called like
(function() ... end)() - Fixed some string escapes being incorrectly deemed as unnecessary
- Fixed trailing comments after semicolons at the end of statements being lost when formatting
- Fixed formatting issues in relation to newline and whitespace when using range formatting.
- Fixed empty tables taking 2 formatting passes to format properly
v0.5.0
[0.5.0] - 2021-02-24
Added
- Added support for removing excess parentheses around expressions.
e.g.print((x))will be formatted toprint(x), as the parentheses are unnecessary. We also consider cases
where parentheses should not be removed, e.g.print((x()))- removing the parentheses changes the meaning of the code. - Added formatting of BinOp expressions within function calls. If there is a long expression as a function argument and it contains binops, it will now span multiple lines
- Added a
column_widthsetting, which is used to guide when StyLua should wrap lines. It defaults to120. - Added support for formatting ranges. You can now specificy ranges using
--range-start <num>and--range-end <num>(both optional, and both inclusive).
If a range is provided, only statements within the range will be formatted. Currently only supports ranges containing whole statements, and is not more granular. - Added support for ignore comments. If the line before a statement begins with the comment
-- stylua: ignore, then the statement will be ignored during formatting.
This currently only supports ignoring statement-level nodes
Changed
- Improved CLI
--checkoutput. We now use a more detailed output which should help in determining diffs - Improved calculations in places to determine when to wrap lines
Fixed
- Fixed an expression ending with an UnOp (e.g.
#foo) and a trailing comment forcing an unnecessary hanging expression - Fixed loss of comments trailing punctuation within function parameters
- Comments within function parameters now force the parameter to go mutliline, fixing syntax errors created from previous formatting
- Fixed incorrect indentation of body of expressions spanning multiple lines (e.g. anonymous functions/tables) when the expression is part of a hanging binop
- Fixed incorrect formatting of multiple long comma-separated assignment/returns causing the comma to be placed onto a new line
v0.4.1
[0.4.1] - 2021-02-05
Fixed
- Fixed function calls being incorrectly expanded due to a comment within the arguments.
We will now only check for leading/trailing comments for argument expressions to see if we need to keep it expanded or not.