@prettier/plugin-ruby
Advanced tools
Changelog
[0.15.1] - 2019-11-05
bin/lex
for viewing the tokenized result of Ripper on Ruby code.if
, unless
, while
, or until
loop break the line, they should be aligned together. For example,if foooooo || barrrrrr
baz
end
If 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
if
, and unless
conditionals are now handled gracefully:if foo?
end
{ :[] => nil }
cannot be translated into []:
as that is an invalid symbol. Instead, it stays with the hash rocket syntax.
%x
).if
, unless
, while
, or until
nodes 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.if
, unless
, while
, or until
nodes 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 end
The 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.
ignored_nl
nodes.Changelog
[0.15.0] - 2019-08-06
while
or until
loop modifies a begin...end
statement, it must remain in the modifier form or else it changes sematic meaning. For example,begin
foo
end while bar
cannot be transformed into:
<!-- prettier-ignore -->while bar
foo
end
because that would never execute foo
if bar
is falsy, whereas in the initial example it would have.
Symbol#to_proc
syntax from within a list of arguments inside of an aref
node (i.e., foo[:bar.each
), we can't put the block syntax inside the brackets.return
keyword that broke the line were previously just printed as they were, which breaks if you have a block expression like an if
or while
. For example,return foo ? bar : baz
if the line was set to very short would be printed as:
<!-- prettier-ignore -->return if foo
bar
else
baz
end
which wouldn't work. Instead, they now get printed with parentheses around the value, as in:
<!-- prettier-ignore -->return(
if foo
bar
else
baz
end
)
"Foo \"Bar\" Baz"
would get formatted as:
<!-- prettier-ignore -->'Foo \"Bar\" Baz'
but now gets formatted as:
<!-- prettier-ignore -->'Foo "Bar" Baz'
Changelog
[0.14.0] - 2019-07-17
if foo
1
else
2
end.to_s
now correctly gets transformed into:
<!-- prettier-ignore -->(foo ? 1 : 2).to_s
if foo = 1
foo
end
must stay the same.
Changelog
[0.13.0] - 2019-07-05
locStart
and locEnd
functions to support --cursor-offset
.do...end
blocks that preceeded call
nodes were associating the comment with the var_ref
instead of the call
itself. For example,foo.each do |bar|
# comment
bar.baz
bar.baz
end
would get printed as
<!-- prettier-ignore -->foo.each do |bar|
# comment
bar
.baz
bar.baz
end
but now gets printed correctly.
{ foo: "bar", **baz }
would fail to print, but now works.
Changelog
[0.12.3] - 2019-05-16
@int
, access_ctrl
, assocsplat
, block_var
, else
, number_arg
, super
, undef
, var_ref
, and var_ref
as well as various call and symbol nodes into appropriate files.proc { |x,| }
would add an extra space, but now it does not.not
operator inside a ternary (e.g., a ? not(b) : c
) would break because it wouldn't add parentheses, but now it adds them.if
and unless
nodes used to not be able to handle if a comment was the only statement in the body. For example,if foo
# comment
end
would get printed as
<!-- prettier-ignore --># comment if foo
Now the if
and unless
printers check for the presence of single comments.
command
nodes within def
nodes would fail to format if it was only a single block argument. For example,def curry(&block)
new &block
end
would fail, but now works.
array[index] # comment
would previously result in array[]
, but now prints properly.
Changelog
[0.12.2] - 2019-04-30
=
, they cannot be transformed into hash labels.to_proc
syntax.Changelog
[0.12.1] - 2019-04-22
command
or command_call
node anywhere in the heirarchy, then it needs to use the higher-precedence { ... }
braces as opposed to the do ... end
delimiters.super
with a block and no args was causing the parser to fail when attempting to inspect lambda nodes.Changelog
[0.12.0] - 2019-04-18
lambda { ... }
method calls into -> { ... }
literals.Changelog
[0.11.0] - 2019-04-18
#!/usr/bin/env ruby
or #!/usr/bin/ruby
).when
predicates break at 80 chars and then wrap to be inline with the other predicates.def/begin/rescue/end/end
into def/rescue/end
.case/when
into its own file and added better documentation.begin/rescue
into its own file.to
is explicitly allowed to not indent to better support rspec.to_proc
transform so that it works with other argument handling appropriately.command
or command_call
node.Changelog
[0.10.0] - 2019-03-25