Releases: JohnnyMorganz/StyLua
Releases · JohnnyMorganz/StyLua
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 ... end
turns 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
do
in awhile ... do
statement 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
Config
structs when using StyLua as a library - Added configuration for quote style. There are four quote style options -
AutoPreferDouble
,AutoPreferSingle
,ForceDouble
andForceSingle
.
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.toml
file - 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
goto
s 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
ForceDouble
toAutoPreferDouble
. 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_width
setting, 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
--check
output. 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.
v0.4.0
[0.4.0] - 2021-02-05
Added
- Added formatting for number literals which begin with a decimal. For consistency, a "0" will be prepended (i.e.
.5
turns to0.5
) - Long expressions in a return statement will now hang onto multiple lines if necessary
- StyLua will now handle expressions in parentheses if they are long, by breaking them down further.
- Added support for ambiguous syntax. StyLua will now keep the semicolon and format as required
Fixed
- Fixed "then" and "do" tokens not being correctly indented when if-then and while-do statements are pushed onto multiple lines
- Fixed incorrect newline formatting when a return type is present for an anonymous function in Luau
- Fixed multiline expressions where the binop has a trailing comment being incorrectly formatted, breaking code
- Fixed a trailing comment at the end of a whole binop expression unnecessarily forcing a hanging expression
v0.3.0
[0.3.0] - 2021-01-15
Added
- StyLua will now test escapes of characters other than quotes in strings to see if they are unnecessary and remove them if so
- Adds wrapping for large expressions to push them onto multiple lines. Statements with line of longer than 120 characters will trigger expression wrapping where possible.
The expression will be split at its Binary Operators, excluding relational operators.
Fixed
- Fixed
.styluaignore
file extension matching not working due to the default override glob - Cleaned up descriptions of options when running
stylua --help
- Fixed issue with
stylua.toml
requiring a complete configuration file with all options set - Fixed issue with escapes unrelated to quotes inside of strings not being preserved
- Fixed incorrect formatting when trailing comments are present in function arguments and other locations.
In function arguments, it will remain expanded if there is a comment present. Similarly, comments are now preserved in punctuated sequencues.
v0.2.1
[0.2.1] - 2021-01-03
Fixed
- Fixed
until
token in a repeat block not being correctly indented - Fixed regression causing the first and last item of an expanded table to not be correctly indented
v0.2.0
[0.2.0] - 2020-12-31
Changed
- Changed heuristics for expanding function arguments. StyLua will now check through the arguments and look out for expanded tables
or anonymous functions, and if found, will not expand the function call. However, if there are any other type of expression mixed between,
then the function call will remain expanded. - Change internals of the formatter by reducing amount of cloning of AST nodes. Improves performance by 22%