All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- @petevk, @kddeisz - Use braces for block format iff it was originally a brace block, otherwise you could be changing precedence. For example:
expect do
field 1 do
"foo"
end
end.to raise_errorshould maintain its do...end and not switch to inline braces otherwise the brace might get associated with the 1.
0.18.0 - 2020-03-17
- @kddeisz - Support for the
nokw_paramnode for specifying when methods should no accept keywords, as in:
def foo(**nil); end- @kddeisz - Support for the
args_forwardnode for forwarding all types of arguments, as in:
def foo(...)
bar(...)
end%table.table.is-striped.is-hoverable- @ftes, @kddeisz - Better handling of indentation of
if/elsif/else,unless/elsif/else, andcase/whenbranches, as in:
.column.is-12
- if true
TRUE
- else
FALSE- @tobyndockerill - Format numbers with underscores after 4 digits, as opposed to 3.
- @ianks - Improve performance by using
--disable-gems. - @flyerhzm - Calls are grouped such that after an end parenthesis the following call will not be indented, as in:
Config::Download.new(
'prettier',
filename: 'prettier.yml', url: 'https://raw.githubusercontent.com/...'
)
.performwill now be printed as:
Config::Download.new(
'prettier',
filename: 'prettier.yml', url: 'https://raw.githubusercontent.com/...'
).perform- @pje, @kddeisz - Method definition bodies (on
defsnodes) should dedent if a helper method is called. As in:
private def self.foo
'bar'
endshould instead be indented as:
private def self.foo
'bar'
end- [@masqita], @kddeisz - Inline variable assignment within a predicate should force the conditional to break, as in:
array.each do |element|
if index = difference.index(element)
difference.delete_at(index)
end
end- @hafley66, @kddeisz - Handle empty
whileanduntilblocks. - @Fruetel, @kddeisz - Simplify string escape pattern by locking on any escape sequence.
- @flyerhzm, @kddeisz - Properly handle string quotes on symbols in hash keys.
0.17.0 - 2019-12-12
- @matt-wratt - Better support for explicit
returnnodes with empty arrays or arrays with a single element. - @jrdioko, @kddeisz - Alignment of
not_tois explicitly allowed to not indent to better support rspec.
- @gin0606 - The max buffer being passed into the Ruby process is now up to 10MB.
0.16.0 - 2019-11-14
- @mmainz, @kddeisz - Support for extra commas in multiple assignment, as it changes the meaning. For example,
a, = [1, 2, 3]would previously get printed as a = [1, 2, 3], which changes the value of a from 1 to the value of the entire array.
- @kddeisz - Experimental support for the HAMtemplate language.
- @github0013, @kddeisz - Support proper string escaping when the original string in the source is wrapped in
%q|...|. For example,%q|\'|should get printed as"\'", where previously it was dropping the backslash. - @jamescostian, @kddeisz - Force ternary breaking when using the lower-precendence operators
andandor. For example,
if x.nil?
puts 'nil' and return
else
x
endthe previous expression was being transformed into a ternary which was invalid ruby. Instead it now stays broken out into an if/else block.
- @localhostdotdev, @joeyjoejoejr, @eins78, @kddeisz - Better support for embedded expressions inside heredocs. For example,
<<-HERE
foo bar baz
#{qux}
foo bar baz
HEREshould remain formatted as it is. Whereas previously due to the way the lines were split, you would sometimes end up with it breaking after #{.
- @jamescostian, @kddeisz - Fix up
returnnode printing. When returning multiple values, you need to return an array literal as opposed to using parentheses.
0.15.1 - 2019-11-05
- @AlanFoster - Add
bin/lexfor viewing the tokenized result of Ripper on Ruby code. - @jakeprime, @kddeisz - When predicates from within an
if,unless,while, oruntilloop break the line, they should be aligned together. For example,
if foooooo || barrrrrr
baz
endIf the line was set to very short, the binary node should be aligned to 3 spaces from the left of the file (which aligns with the if, it would be more for unless). So it would look like:
if foooooo ||
barrrrrr
baz
end- @jamescostian, @AlanFoster - Empty
if, andunlessconditionals are now handled gracefully:
if foo?
end- @mmainz, @kddeisz - Hash keys are not converted to keyword syntax if they would make invalid symbols. For example,
{ :[] => nil }cannot be translated into []: as that is an invalid symbol. Instead, it stays with the hash rocket syntax.
- @cldevs, @kddeisz - Do not attempt to format the insides of xstring literals (string that get sent to the command line surrounded by backticks or
%x). - @cldevs, @kddeisz - When predicates for
if,unless,while, oruntilnodes contain an assignment, we can't know for sure that it doesn't modify the body. In this case we need to always break and form a multi-line block. - @MarcManiez, @kddeisz - When the return value of
if,unless,while, oruntilnodes are assigned to anything other than a local variable, we need to wrap them in parentheses if we're changing to the modifier form. This is because the following expressions have different semantic meaning:
hash[:key] = break :value while false
hash[:key] = while false do break :value endThe first one will not result in an empty hash, whereas the second one will result in { key: nil }. In this case what we need to do for the first expression to align is wrap it in parens, as in:
hash[:key] = (break :value while false)That will guarantee that the expressions are equivalent.
- @AlanFoster - Fix crashes that were happening with
ignored_nlnodes.
0.15.0 - 2019-08-06
- @dudeofawesome, @kddeisz - If xstring literals (command line calls surrounded by backticks) break, then we indent and place the command on a new line. Previously, this was resulting in new lines getting added each time the code was formatted. Now this happens correctly.
- @krachtstefan, @kddeisz - When a
whileoruntilloop modifies abegin...endstatement, it must remain in the modifier form or else it changes sematic meaning. For example,
begin
foo
end while barcannot be transformed into:
while bar
foo
endbecause that would never execute foo if bar is falsy, whereas in the initial example it would have.
- @jviney, @kddeisz - When transforming a block into the
Symbol#to_procsyntax from within a list of arguments inside of anarefnode (i.e.,foo[:bar].each), we can't put the block syntax inside the brackets. - @jakeprime, @kddeisz - Values for the
returnkeyword that broke the line were previously just printed as they were, which breaks if you have a block expression like aniforwhile. For example,
return foo ? bar : bazif the line was set to very short would be printed as:
return if foo
bar
else
baz
endwhich wouldn't work. Instead, they now get printed with parentheses around the value, as in:
return(
if foo
bar
else
baz
end
)- @jakeprime, @kddeisz - When switching from a double-quoted string to a single-quoted string that contained escaped double quotes, the backslashes would stay in the string. As in:
"Foo \"Bar\" Baz"would get formatted as:
'Foo \"Bar\" Baz'but now gets formatted as:
'Foo "Bar" Baz'0.14.0 - 2019-07-17
- @kddeisz - Support for pattern matching for variables and array patterns. Currently waiting on Ripper support for hash patterns. For examples, check out the test/js/patterns.test.js file.
- @jviney, @kddeisz - if/else blocks that had method calls on the end of them that were also transformed into ternaries need to have parens added to them. For example,
if foo
1
else
2
end.to_snow correctly gets transformed into:
(foo ? 1 : 2).to_s- @acrewdson, @kddeisz - Fixed a bug where multiple newlines at the end of the file would cause a crash.
- @jviney, @kddeisz - If a variable is assigned inside of the predicate of a conditional, then we can't change it into the single-line version as this breaks. For example,
if foo = 1
foo
endmust stay the same.
0.13.0 - 2019-07-05
- @kddeisz - Added
locStartandlocEndfunctions to support--cursor-offset.
- @xipgroc, @kddeisz - Comments inside of
do...endblocks that preceededcallnodes were associating the comment with thevar_refinstead of thecallitself. For example,
foo.each do |bar|
# comment
bar.baz
bar.baz
endwould get printed as
foo.each do |bar|
# comment
bar
.baz
bar.baz
endbut now gets printed correctly.
{ foo: "bar", **baz }would fail to print, but now works.
0.12.3 - 2019-05-16
- @kddeisz - Move arg, assign, constant, flow, massign, operator, scope, and statement nodes into their own files.
- @kddeisz - Move
@int,access_ctrl,assocsplat,block_var,else,number_arg,super,undef,var_ref, andvar_refas well as various call and symbol nodes into appropriate files. - @kddeisz - Better support for excessed commas in block args. Previously
proc { |x,| }would add an extra space, but now it does not. - @kddeisz - Add a lot more documentation to the parser.
- @glejeune, @kddeisz - Previously, the unary
notoperator inside a ternary (e.g.,a ? not(b) : c) would break because it wouldn't add parentheses, but now it adds them. - @kddeisz -
ifandunlessnodes used to not be able to handle if a comment was the only statement in the body. For example,
if foo
# comment
endwould get printed as
# comment if fooNow the if and unless printers check for the presence of single comments.
- @JoshuaKGoldberg, @kddeisz - Fixes an error where
commandnodes withindefnodes would fail to format if it was only a single block argument. For example,
def curry(&block)
new &block
endwould fail, but now works.
- @xipgroc, @kddeisz - Comments on lines with array references were previously deleting the array references entirely. For example,
array[index] # commentwould previously result in array[], but now prints properly.
0.12.2 - 2019-04-30
- @kddeisz - When symbol literal hash keys end with
=, they cannot be transformed into hash labels. - @xipgroc, @kddeisz - Fixed when blocks on methods with no arguments are transformed into
to_procsyntax.
0.12.1 - 2019-04-22
- @kddeisz - If a lambda literal is nested under a
commandorcommand_callnode anywhere in the heirarchy, then it needs to use the higher-precedence{ ... }braces as opposed to thedo ... enddelimiters. - @jpickwell, @kddeisz - Calling
superwith a block and no args was causing the parser to fail when attempting to inspect lambda nodes. - @kddeisz - Support better breaking within interpolation by grouping the interpolated content.
0.12.0 - 2019-04-18
- @kddeisz - Automatically convert
lambda { ... }method calls into-> { ... }literals.
0.11.0 - 2019-04-18
- @kddeisz - Support for parsing things with a ruby shebang (e.g.,
#!/usr/bin/env rubyor#!/usr/bin/ruby). - @kddeisz - Big tests refactor.
- @kddeisz - Make multiple
whenpredicates break at 80 chars and then wrap to be inline with the other predicates. - @kddeisz - Automatically add underscores in large numbers that aren't already formatted.
- @AlanFoster - Better support for inline access control modifiers.
- @jpickwell, @kddeisz - Better support for heredocs in hash literals.
- @kddeisz - Better support for heredocs in array literals.
- @kddeisz - Support automatically transforming
def/begin/rescue/end/endintodef/rescue/end.
- @deecewan - Fixed support for dynamic string hash keys.
- @kddeisz - Moved
case/wheninto its own file and added better documentation. - @kddeisz - Moved
begin/rescueinto its own file. - @AlanFoster - Automatically add newlines around access modifiers.
- @kddeisz - Alignment of command calls with arguments is fixed.
- @aaronjensen, @kddeisz - Alignment of
tois explicitly allowed to not indent to better support rspec. - @kddeisz - Fix up the
to_proctransform so that it works with other argument handling appropriately. - @kddeisz - Fixed regression on regexp comments.
- @CodingItWrong, @kddeisz - Fix up block delimiters when nested inside a
commandorcommand_callnode. - @kddeisz - Moved hashes into its own file.
0.10.0 - 2019-03-25
- @kddeisz - Support for block-local variables.
- @kddeisz - Support for dyna-symbols that are using single quotes.
- @kddeisz - Force method calls after arrays, blocks, hashes, and xstrings to hang onto the end of the previous nodes.
- @kddeisz - Check before anything else for an invalid ruby version.
0.9.1 - 2019-03-24
- @kddeisz - Better support string quotes by favoring what the user chose if the string contains escape patterns.
- @kddeisz - Better support heredocs within method calls.
0.9.0 - 2019-03-18
- @kddeisz - Support the
hasPragmafunction. - @kddeisz - Support the new
number_argnode type in Ruby 2.7.
- @kddeisz - Limit the number of nodes that are allowed to turn into ternary expressions.
0.8.0 - 2019-03-08
- @kddeisz - Add
eslintand fix up existing violations. - @AlanFoster - Add the infra for the
prettierruby gem. - @kddeisz - Add a
raketask for easier process integration for the ruby gem. - @kddeisz - Handle direct interpolation of strings with %w array literals (i.e.,
["#{foo}"]should not be transformed into a %w array).
- @kddeisz - Fix string escaping for hex digit bit patterns when there's only one character after the "x".
- @AlanFoster - Don't allow line breaks between brace block params.
- @johnschoeman - Switch over the array.rb test case to minitest.
- @AlanFoster - Test improvements to allow running in parallel.
- @johnschoeman - Switch over assign.rb test case to minitest.
- @AlanFoster - Add a contributing guide.
- @AlanFoster - Handle longer command nodes.
- @kddeisz - Changed the ruby executable within the
prettiergem torbprettierfor easier autocomplete.
- @kddeisz - All instances of the spread (
...) operator so that we can support older versions of node.
0.7.0 - 2019-02-24
- @kddeisz - Support checking for escaping within strings to force double quotes (e.g., "\n").
- @RossKinsella, @kddeisz - Handle cases with empty class and module declarations that need to break.
- @AlanFoster - Align the
bin/printandbin/sexpAPto supportbin/printtaking a filepath. - @AndrewRayCode, @kddeisz - Support lambdas that don't break and are inline.
- @AlanFoster - Switch over the numbers.rb test to minitest.
- @AlanFoster - Switch over the kwargs.rb test to minitest.
- @AlanFoster - Bail out early if the Ruby input is invalid.
- @kddeisz - Support
__END__content. - @AlanFoster - Fix up issue with whitespace being added within regexp that are multiline.
- @AlanFoster - Better support for destructuring within multi assignment.
- @kddeisz - Switch
nexttest over to minitest. - @kddeisz - Handle multiple arguments to
nextwith a space between. - @AndrewRayCode, @kddeisz - Handle multi-line conditional predicate (should align with keyword).
- @aaronjensen, @kddeisz - Properly support adding trailing commas with and without blocks.
- @AlanFoster, @kddeisz - Fix regression of handling comments within arrays on array literals.
- @AlanFoster - Support multiple arguments to
undef.
0.6.3 - 2019-02-18
- @kddeisz - Switch over
binaryfixture to minitest. - @kddeisz - Reconfigure parser into multiple layer modules so that it's easier to understand and manage.
- @kddeisz - Handle comments from within
begin,rescue,ensure,while, anduntilnodes. - @kddeisz - Properly indent heredocs without taking into account current indentation level.
0.6.2 - 2019-02-17
- @AlanFoster - Handle regexp suffixes.
- @kddeisz - Add support for testing the test fixtures with minitest.
- @kddeisz - Switch over
aliasandregexptests to minitest. - @aaronjensen, @kddeisz - Break up method args to split into multiple lines.
- @christoomey, @kddeisz - Handle blocks args when trailing commas are on.
0.6.1 - 2019-02-15
- @meleyal, @kddeisz - Fix Ruby 2.5 inline comments on
args_add_blocknodes. - @meleyal, @kddeisz - Support passing
super()explicitly with no arguments.
0.6.0 - 2019-02-14
- @kddeisz - Handle non UTF-8 comments.
- @kddeisz - Handle non UTF-8 identifiers.
- @kddeisz - Handle non UTF-8 strings.
- @kddeisz - Handle empty parens.
- @kddeisz - Handle rescue with splats preceeding the exception names.
- @kddeisz - Use
JSON::fast_generateto get the s-expressions back from the parser. - @NoahTheDuke, @kddeisz - Handle broken lambdas from within
commandandcommand_callnodes.
0.5.2 - 2019-02-13
- @kddeisz - Support embedded expressions within strings that contain only keywords, as in
"#{super}".
0.5.1 - 2019-02-13
- @yuki24, @kddeisz - Force
doblocks that we know have to bedoblocks to break. - @kmcq, @kddeisz - Handle
commandandcommand_callnodesdoblocks by forcing them to break. - @ashfurrow, @kddeisz - Attach comments to full hash association nodes, not just the value.
0.5.0 - 2019-02-13
- @kddeisz - Automatically convert arrays of all string literals to %w arrays.
- @kddeisz - Automatically convert arrays of all symbol literals to %i arrays.
- @kddeisz - Move the
args_addandargs_newhandling into the parser. - @uri, @kddeisz - Change
command_callnodes to properly indent when broken and to not add a trailing comma. - @kddeisz - Rename the
trailingCommaoption toaddTrailingCommasto not conflict with the JS option.
0.4.1 - 2019-02-12
- @kddeisz - Provide the
makeListutility for the nodes that are lists from within ripper. - @awinograd, @kddeisz - Again, this time for real, properly escape strings.
- @kddeisz - Fix up trailing commas on command calls.
0.4.0 - 2019-02-12
- @Overload119, @kddeisz - Support the
trailingCommaconfiguration option (defaults tofalse).
- @NoahTheDuke, @kddeisz - Pass the code to be formatted over
stdin.
0.3.7 - 2019-02-11
- @kddeisz - Split up statements even if they started on the same line with
;s unless they are within an embedded expression. - @kddeisz - Properly handle escaped quotes within strings.
0.3.6 - 2019-02-10
- @AlanFoster, @kddeisz - Support the
notoperator properly. - @AlanFoster, @kddeisz - Handle comments properly inside
if,unless, andwhennodes.
0.3.5 - 2019-02-09
- @kddeisz - Handle lonely operators in Ruby
2.5.
0.3.4 - 2019-02-09
- @kddeisz - Comments are now properly attached inside
defsnodes. - @kddeisz - Support multiple inline comments on nodes.
- @kddeisz - Support inline comments from within the
EXPR_END|EXPR_LABELlexer state. - @cbothner - Stop transforming multistatement blocks with
to_proc. - @kddeisz -
doblocks necessarily need to break their parent nodes. - @eins78, @kddeisz - Handle
nextnode edge case withargs_addas the body.
0.3.3 - 2019-02-09
- @bugthing, @kddeisz - Command nodes within conditionals now break parents to disallow them from being turned into ternary expressions.
- @awinograd, @kddeisz - Properly escape double quotes when using
preferSingleQuotes: false.
0.3.2 - 2019-02-09
- @kddeisz - Don't define duplicated methods in the parser.
- @kddeisz - Let prettier know about
.rband.rakefiles so you don't have to specify the parser when running. - @kddeisz - Renamed the package to [@prettier]/plugin-ruby.
0.3.1 - 2019-02-07
- @kddeisz - Automatically add parens to method declarations.
- @kddeisz - Handle comments on bare hash assocs.
- @kddeisz - Handle
method_add_blocknodes where the statements may be nested one more level. - @kddeisz - Handle heredocs nested no matter how many levels deep.
0.3.0 - 2019-02-07
- @kddeisz - Ignore current indentation when creating embdocs so that
=beginis always at the beginning of the line. - @kddeisz - Move
regexp_addandregexp_newhandling into the parser. - @kddeisz - Move
xstring_addandxstring_newhandling into the parser. - @kddeisz - Move
string_addandstring_contenthandling into the parser. - @kddeisz - Move
mrhs_addandmrhs_newhandling into the parser. - @kddeisz - Move
mlhs_addandmlhs_newhandling into the parser.
0.2.1 - 2019-02-06
- @kddeisz - Handle brace blocks on commands properly.
- @kddeisz - Break parent and return
doblocks when called from acommandnode. - @kddeisz - Handle edge cases with
ifstatements where there is no body of the if (so it can't be converted to a ternary).
0.2.0 - 2019-02-06
- @kddeisz - Handle
methrefnodes from Ruby2.7. - @kddeisz - Allow
modulenodes to shorten using;when the block is empty.
- @kddeisz - Handle splat within an array, as in
[1, 2, *foo]. - @kddeisz - Disallow comments from being attached to intermediary regex nodes.
- @kddeisz - Fix
to_proctransforms to reference the method called as opposed to the parameter name. - @kddeisz - Change statement lists to be generated within the parser instead of the printer, thereby allowing finer control over comments.
- @kddeisz - Completely revamp comment parsing by switching off the internal lexer state from
ripper. This should drastically increase accuracy of comment parsing in general, and set us up for success in the future. - @kddeisz - Allow comments to be attached to
CHARnodes. - @kddeisz - Disallow comments from being attached to
args_newnodes. - @kddeisz - Track start and end lines so we can better insert block comments.
- @kddeisz - Handle intermediary array nodes in the parse for better comment handling.
0.1.2 - 2019-02-05
- @kddeisz - Handle guard clauses that return with no parens.
0.1.1 - 2019-02-05
- @kddeisz - Handle class method calls with the
::operator. - @kddeisz - Handle strings with apostrophes when using
preferSingleQuote. - @kddeisz - Have travis run multiple ruby versions.
- @kddeisz - Explicitly fail if ruby version is <
2.5. - @kddeisz - Disallow comments from being attached to intermediary string nodes.
0.1.0 - 2019-02-04
- Initial release 🎉