ruby-formatter / rufo Goto Github PK
View Code? Open in Web Editor NEWThe Ruby Formatter
License: MIT License
The Ruby Formatter
License: MIT License
@gingermusketeer pointed out that we should probably notify users where they are likely to be affected by incorrect squiggly heredoc formatting due to a Ripper bug:
@mjago Given that this bug causes rufo to change the behaviour of the code and users may not pick it up if they do not check the changes carefully. Do you think we need to alert users to this bug if they are running a version of ruby with this issue?
Perhaps we should raise an exception, warn or skip the file if there is a squiggly heredoc present and they are running an unpatched version of ruby?
Affected Ruby versions are 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.4.0, 2.4.1
Should we detect squiggly heredoc usage on these versions and flag a warning to stderr? Or something else?
The above is only relevant once PR #33 is merged - currently Rufo crashes in these circumstances, but with PR #33 the squiggly heredoc is potentially formatted incorrectly (since Ripper loses information).
The fix is to upgrade to 2.3.5 or 2.4.2 where fixes to Ripper have been backported.
Related issue: #6
We have 2 test failures on ruby-head:
https://travis-ci.org/ruby-formatter/rufo/jobs/275214575
Rufo::Bug:
Unhandled node: kwrest_param at [[2, 12], :on_rparen, ")"]
Reproduce with:
#ERRORS
<<~HTML
There are #{blah} #{bloop}
HTML
Replace ~
with -
and the formatter works fine
#OK
<<~HTML
There are #{blah} #{bloop}
HTML
Delete one interpolation and the formatter works fine.
Interestingly, and almost certainly related,
<<-TEXT
There are #{blah} thing
TEXT
gets formatted succesfully, but rufo wrongly removes whitespace inside the multiline string:
# space between #{blah} and thing reduced
<<~TEXT
There are #{blah} thing
TEXT
Lexer chokes on multi-line word array literal.
Here's the code that triggers the error.
header = %w(
organization
full_name
phone_number
email
tags
assignments
created
)
Here's the error.
/usr/local/var/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3429:in `bug': Expected token on_ident, not on_words_sep at [[27, 19], :on_words_sep, "\n ", #<Ripper::Lexer::
State: EXPR_BEG>] (Rufo::Bug)
One of my favorite features from rubocop --auto-correct
and prettier
is quote cleanup. They will happily turn all single quotes into double quotes (or vice versa depending on config). Is this something rufo can do? That would be a great feature.
This is a bit like the tabs vs. spaces debate, and having rufo enforce the rule would obviate the need for discussion.
While looking into #83 I tried rufo on a number of repositories for commonly-used gems and came across a few issues.
This one comes from the dry-types gem.
The file to_ast_spec.rb
link https://raw.githubusercontent.com/dry-rb/dry-types/761bc00b24dc4d4a66fd4ef5a514e72b1558d5f7/spec/dry/types/to_ast_spec.rb keeps getting switched back and forth between two formats by rufo:
$ wget "https://raw.githubusercontent.com/dry-rb/dry-types/761bc00b24dc4d4a66fd4ef5a514e72b1558d5f7/spec/dry/types/to_ast_spec.rb"
(...)
$ rufo to_ast_spec.rb
Format: to_ast_spec.rb
$ md5sum to_ast_spec.rb
e50ddccef298cb1d99ea53022219dc95 to_ast_spec.rb
$ rufo to_ast_spec.rb
Format: to_ast_spec.rb
$ md5sum to_ast_spec.rb
525b86cbabfe431098db93cb6331f9d4 to_ast_spec.rb
$ rufo to_ast_spec.rb
Format: to_ast_spec.rb
$ md5sum to_ast_spec.rb
e50ddccef298cb1d99ea53022219dc95 to_ast_spec.rb
$ rufo to_ast_spec.rb
Format: to_ast_spec.rb
$ md5sum to_ast_spec.rb
525b86cbabfe431098db93cb6331f9d4 to_ast_spec.rb
Input:
context 'no sidecar/archive' do
it 'uploads destination master to the specified destination' do
expect_any_instance_of(Uploader::Null) # rubocop:disable RSpec/AnyInstance
.to receive(:upload)
.with([file_path, 'HON_TEST001_010.mxf'])
.and_return(Uploader::Result.new(success: true))
end
end
Output:
context 'no sidecar/archive' do
it 'uploads destination master to the specified destination' do
expect_any_instance_of(Uploader::Null)# rubocop:disable RSpec/AnyInstance
.to receive(:upload)
)
)
end
end
You've found a bug!
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3429:in bug': Expected token on_period, not on_words_sep at [[74, 35], :on_words_sep, " ", #<Ripper::Lexer::State: EXPR_BEG>] (Rufo::Bug) from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3424:in
check'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:2990:in consume_token' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:962:in
consume_call_dot'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:942:in visit_call_with_receiver' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:353:in
visit'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1257:in visit_call_with_block' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:351:in
visit'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in block (2 levels) in visit_exps' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in
push_node'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in block in visit_exps' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in
each'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in each_with_index' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in
visit_exps'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:187:in visit' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:166:in
format'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:165:in format' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:48:in
format_stdin'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:38:in run' from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:12:in
run'
from C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/exe/rufo:4:in <top (required)>' from C:/tools/ruby25/bin/rufo:23:in
load'
from C:/tools/ruby25/bin/rufo:23:in `
I notice that when I chain method calls and I add a do block at the end, the formatting gets weird.
res = [1, 2, 3].
select { |a| a.odd? }.
inject({}) do |memo, a|
memo = memo + 1
memo
end
I think that the following would be easier to understand:
res = [1, 2, 3].
select { |a| a.odd? }.
inject({}) do |memo, a|
memo = memo + 1
memo
end
Everything in the 0.2.0 milestone is complete, any objections to cutting a new gem version? Did we want to resolve #32 first?
This is a great project, thanks. I like that it tries to respect some alignment choices agnostically, Unobtrusive by default.
Trying it out on my code, here is one choice where it doesn't:
something = if whatever
"foo"
else
"bar"
end
This seems reasonable to me, but rufo insists on:
something = if whatever
"foo"
else
"bar"
end
thoughts? Maybe I'm wrong that this is reasonable!
def a
test = DB.exec <<~SQL
UPDATE table set col = 1
SQL
end
Is aligned:
def a
test = DB.exec <<~SQL
UPDATE table set col = 1
SQL
end
Which is somewhat odd... it aligns as expected for DB.exec(<<~SQL)
Note, now the we adopted Prettier for Discourse js I am very very keen to move to rufo, from my tests on a few files this appears to be the biggest point of contention, there is some around params as well cause our rubocop rules currently are at odds with what rufo produces.
While looking into #83 I tried rufo on a number of repositories for commonly-used gems and came across a few issues.
This one comes from the arel gem.
Traceback:
Traceback (most recent call last):
72: from .rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'
71: from .rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
70: from .rvm/gems/ruby-2.5.0/bin/rufo:23:in `<main>'
69: from .rvm/gems/ruby-2.5.0/bin/rufo:23:in `load'
68: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/exe/rufo:4:in `<top (required)>'
67: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:12:in `run'
66: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:40:in `run'
65: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `format_args'
64: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `each'
63: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:82:in `block in format_args'
62: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:124:in `format_file'
61: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:165:in `format'
60: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:166:in `format'
59: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:187:in `visit'
58: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
57: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
56: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
55: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
54: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
53: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
52: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:383:in `visit'
51: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1885:in `visit_module'
50: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3578:in `push_type'
49: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1892:in `block in visit_module'
48: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:363:in `visit'
47: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
46: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
45: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
44: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
43: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
42: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
41: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
40: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
39: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
38: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
37: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:381:in `visit'
36: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1859:in `visit_class'
35: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3578:in `push_type'
34: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1875:in `block in visit_class'
33: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:363:in `visit'
32: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
31: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
30: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
29: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
28: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
27: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
26: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
25: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
24: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
23: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
22: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:393:in `visit'
21: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1906:in `visit_def'
20: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3571:in `push_hash'
19: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1907:in `block in visit_def'
18: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1985:in `visit_def_from_name'
17: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:363:in `visit'
16: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
15: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
14: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
13: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
12: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
11: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
10: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
9: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
8: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
7: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
6: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:309:in `visit'
5: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:738:in `visit_assign'
4: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:279:in `visit'
3: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:285:in `visit'
2: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:2990:in `consume_token'
1: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3424:in `check'
.rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3429:in `bug': Expected token on_ivar, not on_tstring_end at [[13, 52], :on_tstring_end, "}", #<Ripper::Lexer::State: EXPR_END|EXPR_ENDARG>] (Rufo::Bug)
File that triggers the issue: https://raw.githubusercontent.com/rails/arel/eb3f968b5ffdd3b343e7d190f1aa0b36864f56a2/test/support/fake_record.rb
While looking into #83 I tried rufo on a number of repositories for commonly-used gems and came across a few issues.
This one comes from the arel gem.
Traceback:
Traceback (most recent call last):
99: from .rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'
98: from .rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
97: from .rvm/gems/ruby-2.5.0/bin/rufo:23:in `<main>'
96: from .rvm/gems/ruby-2.5.0/bin/rufo:23:in `load'
95: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/exe/rufo:4:in `<top (required)>'
94: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:12:in `run'
93: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:40:in `run'
92: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `format_args'
91: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `each'
90: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:82:in `block in format_args'
89: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:124:in `format_file'
88: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:165:in `format'
87: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:166:in `format'
86: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:187:in `visit'
85: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
84: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
83: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
82: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
81: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
80: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
79: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:383:in `visit'
78: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1885:in `visit_module'
77: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3578:in `push_type'
76: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1892:in `block in visit_module'
75: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:363:in `visit'
74: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
73: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
72: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
71: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
70: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
69: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
68: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
67: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
66: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
65: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
64: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:351:in `visit'
63: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1268:in `visit_call_with_block'
62: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:357:in `visit'
61: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1337:in `visit_do_block'
60: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
59: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
58: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
57: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
56: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
55: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
54: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
53: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
52: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
51: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
50: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:351:in `visit'
49: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1268:in `visit_call_with_block'
48: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:357:in `visit'
47: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1337:in `visit_do_block'
46: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
45: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
44: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
43: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
42: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
41: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
40: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
39: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
38: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
37: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
36: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:351:in `visit'
35: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1268:in `visit_call_with_block'
34: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:357:in `visit'
33: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1337:in `visit_do_block'
32: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1480:in `visit_bodystmt'
31: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3321:in `indent_body'
30: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3246:in `indent'
29: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3322:in `block in indent_body'
28: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
27: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
26: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
25: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
24: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
23: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
22: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:309:in `visit'
21: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:743:in `visit_assign'
20: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:812:in `visit_assign_value'
19: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3413:in `indent_after_space'
18: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:336:in `visit'
17: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1162:in `visit_command_call'
16: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1217:in `visit_command_args'
15: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3242:in `indent'
14: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1218:in `block in visit_command_args'
13: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
12: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
11: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
10: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
9: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
8: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
7: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:338:in `visit'
6: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1417:in `visit_call_args'
5: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1685:in `visit_comma_separated_list'
4: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1685:in `each_with_index'
3: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1685:in `each'
2: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:1697:in `block in visit_comma_separated_list'
1: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3424:in `check'
.rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3429:in `bug': Expected token on_comma, not on_words_sep at [[15, 47], :on_words_sep, " ", #<Ripper::Lexer::State: EXPR_ARG>] (Rufo::Bug)
File that triggers the issue: https://raw.githubusercontent.com/rails/arel/eb3f968b5ffdd3b343e7d190f1aa0b36864f56a2/test/test_insert_manager.rb
Famous ruby configuration plugin, vim-ruby, has three styles to indent public
, private
, protected
directives. Currently, rufo
uses the normal
style (in terms of vim-ruby
), but maybe you would find the outdent
style more apparent and decide to use it instead.
Anyway, thanks for a great tool!
Last week I have created an issue about Ruby 2.1. I am wondering why it was deleted and not just closed. I think that the issue would have helped people to know on which version is supported by the gem.
I'd like to have tests in separate files, with an in-file delimiter to separate original and expected. Something like
def method arg
arg
end
#~#
def method(arg)
arg
end
Hi,
I've just released v0.1.0 which basically reflects rufo's new home in gemspec. โจ
This release is also the first release in the "post-@asterite era".
Speaking of the new era. I'd like to add a changelog which keeps track of notable changes in rufo.
Personally, I've used Keep a Changelog format in some projects.
I like it but it can be any other format. I don't care as long as it is consistent ๐ค
What are your thoughts on this topic?
Kind regards,
Peter
$ rufo --version
rufo 0.4.0
$ echo 'module Foo; def Foo::bar; end; end' | rufo
You've found a bug!
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
Traceback (most recent call last):
31: from /path/.rbenv/versions/2.5.1/bin/rufo:23:in `<main>'
30: from /path/.rbenv/versions/2.5.1/bin/rufo:23:in `load'
29: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/exe/rufo:4:in `<top (required)>'
28: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/command.rb:12:in `run'
27: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/command.rb:38:in `run'
26: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/command.rb:48:in `format_stdin'
25: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/command.rb:165:in `format'
24: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:176:in `format'
23: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:198:in `visit'
22: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:496:in `visit_exps'
21: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:496:in `each_with_index'
20: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:496:in `each'
19: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:515:in `block in visit_exps'
18: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:3678:in `push_node'
17: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:516:in `block (2 levels) in visit_exps'
16: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:394:in `visit'
15: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:1966:in `visit_module'
14: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:3693:in `push_type'
13: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:1973:in `block in visit_module'
12: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:374:in `visit'
11: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:1559:in `visit_bodystmt'
10: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:3406:in `indent_body'
9: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:496:in `visit_exps'
8: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:496:in `each_with_index'
7: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:496:in `each'
6: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:515:in `block in visit_exps'
5: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:3678:in `push_node'
4: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:516:in `block (2 levels) in visit_exps'
3: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:406:in `visit'
2: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:2006:in `visit_def_with_receiver'
1: from /path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:3539:in `check'
/path/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rufo-0.4.0/lib/rufo/formatter.rb:3544:in `bug': Expected token on_period, not on_op at [[1, 19], :on_op, "::", #<Ripper::Lexer::State: EXPR_DOT>] (Rufo::Bug)
While looking into #83 I tried rufo on a number of repositories for commonly-used gems and came across a few issues.
This one is a testcase extracted from the pry gem.
Example code:
puts (<<-HELLO
hello world
HELLO
)
which after running rufo turns into
puts (<<-HELLO
hello world
HELLO)
which is now invalid:
$ ruby heredoc.rb
heredoc.rb:3: can't find string "HELLO" anywhere before EOF
heredoc.rb:1: syntax error, unexpected end-of-input, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
puts (<<-HELLO
^
As raised by @bessey, see here, we should probably do something about invalid config that is defined in a .rufo
file.
This will help users know that their config is actually doing something.
Some of the options include:
--check-config
Thoughts?
If you format:
foo(<<-EOF
foo
bar
EOF
)
you get
foo(<<-EOF
foo
bar
EOF)
which is invalid, because EOF must be followed by no other characters. This doesn't happen if you start with
foo(
<<-EOF
foo
bar
EOF
)
I added a couple tests that show this failure on this branch
Hi,
New to rufo
, I can see that string surrounded by simple quotes are turned into double quotes surrounded ones ?
As I remembered, simple quotes string are less resource consuming if there is no interpolation in it, right ?
Regards,
Formatting the following file:
def putit!(**args)
puts(**args)
end
putit!(a:1,b:2)
Gives the following error:
You've found a bug!
It happened while trying to format the file foo.rb
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
bundler: failed to load command: rufo (/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/bin/rufo)
Rufo::Bug: Unhandled node: kwrest_param at [[1, 13], :on_ident, "args", #<Ripper::Lexer::State: EXPR_ARG>]
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:3507:in `bug'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:463:in `visit'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:2074:in `visit_params'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:390:in `visit'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:1959:in `block in visit_def_from_name'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:3312:in `indent'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:1958:in `visit_def_from_name'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:1899:in `block in visit_def'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:3707:in `push_hash'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:1898:in `visit_def'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:384:in `visit'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:492:in `block (2 levels) in visit_exps'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:3699:in `push_node'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:491:in `block in visit_exps'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:472:in `each'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:472:in `each_with_index'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:472:in `visit_exps'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:187:in `visit'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:163:in `format'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:127:in `format'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:85:in `format_file'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:68:in `block in format_args'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:67:in `each'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:67:in `format_args'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:25:in `run'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/lib/rufo/command.rb:12:in `run'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/gems/rufo-0.1.0/exe/rufo:4:in `<top (required)>'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/bin/rufo:23:in `load'
/data/projects/personal/chips/vendor/bundle/ruby/2.5.0/bin/rufo:23:in `<top (required)>'
I found indent problem while using tilde heredocs inside of hash.
Example:
{
content: <<~EOF,
heredoc
EOF
}
Result:
{
content: <<~EOF,
heredoc
EOF
}
I am using ruby 2.1.3 and rufo 0.3.1. when I try to format the following:
class FormatError
scope :my_scope, lambda { |tata|
where([%{coco} , tata])
.order("")
}
end
I get this broken ruby code
class FormatError
scope :my_scope, lambda { |tata|
where([%{coco}, tata])
rder("")
}
end
We found an interesting case while trying out the new-formatter
branch.
Formatting a file with:
p [
*[:shine],
*[:kerk]
]
Results in:
Rufo::Bug: Expected token on_op, not on_ignored_nl at [[2, 14], :on_ignored_nl, "\n"]
What's really interesting, if you have a file with:
p [*[:shine],*[:kerk]]
The result of the formatter will be:
p [
*{:type=>:align, :contents=>{:type=>:group, :contents=>{:type=>:concat, :parts=>["[", {:type=>:indent, :contents=>{:type=>:concat, :parts=>[{:type=>:concat, :parts=>[]}, {:type=>:line, :soft=>true}, {:type=>:concat, :parts=>[{:type=>:concat, :parts=>[":shine", {:type=>:if_break, :break_contents=>",", :flat_contents=>""}]}]}]}}, {:type=>:line, :soft=>true}, "]"]}, :break=>false, :expanded_states=>nil}, :n=>2},
*{:type=>:align, :contents=>{:type=>:group, :contents=>{:type=>:concat, :parts=>["[", {:type=>:indent, :contents=>{:type=>:concat, :parts=>[{:type=>:concat, :parts=>[]}, {:type=>:line, :soft=>true}, {:type=>:concat, :parts=>[{:type=>:concat, :parts=>[":kerk", {:type=>:if_break, :break_contents=>",", :flat_contents=>""}]}]}]}}, {:type=>:line, :soft=>true}, "]"]}, :break=>false, :expanded_states=>nil}, :n=>2},
]
I verified it is Ruby:
$ ruby the_file.rb
[:shine, :kerk]
I'm super happy with this work!
Fails to parse:
for i, in [[1,2]]
i.should == 1
end
Error is:
Rufo::Bug:
Expected token on_kw, not on_comma at [[2, 5], :on_comma, ","]
ref: #44
Hello,
I am trying to use rufo
tool at Arch Linux to format following file I get a bug
error from the script:
$ rufo ./generate_build.rb
You've found a bug!
It happened while trying to format the file ./generate_build.rb
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
Traceback (most recent call last):
24: from /usr/bin/rufo:23:in `<main>'
23: from /usr/bin/rufo:23:in `load'
22: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/exe/rufo:4:in `<top (required)>'
21: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:12:in `run'
20: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:40:in `run'
19: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `format_args'
18: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `each'
17: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:82:in `block in format_args'
16: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:124:in `format_file'
15: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:165:in `format'
14: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:166:in `format'
13: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:187:in `visit'
12: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
11: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
10: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
9: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
8: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
7: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
6: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:309:in `visit'
5: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:738:in `visit_assign'
4: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:279:in `visit'
3: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:273:in `visit'
2: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:2990:in `consume_token'
1: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3424:in `check'
/usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3429:in `bug': Expected token on_ident, not on_words_sep at [[86, 28], :on_words_sep, "\n", #<Ripper::Lexer::State: EXPR_BEG>] (Rufo::Bug)
I upgraded to 0.3.0
today and of cause noticed the formatting of quotes. We decided to stick with single quotes so I added a .rufo
file in the project root with the content
quote_style :single
Yet rufo
still formats with "
everywhere.
Anything I am missing?
Example code that produces the crash:
execute <<~SQL
SQL
You've found a bug!
It happened while trying to format the file db/migrate/20170209120024_split_destination_masters_and_files.rb
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
/home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:70:in `block in on_heredoc_dedent': undefined meth
od `event' for #<Array:0x000000021b77c0> (NoMethodError)
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:69:in `each'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:69:in `on_heredoc_dedent'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:61:in `parse'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:61:in `parse'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:55:in `lex'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/2.3.0/ripper/lexer.rb:44:in `lex'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/formatter.rb:14:in `ini
tialize'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:115:in `new'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:115:in `form
at'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:85:in `forma
t_file'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:68:in `block
in format_args'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:67:in `each'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:67:in `forma
t_args'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:25:in `run'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/lib/rufo/command.rb:12:in `run'
from /home/louis/.asdf/installs/ruby/2.3.0/lib/ruby/gems/2.3.0/gems/rufo-0.1.0/exe/rufo:4:in `<top (required)>'
from /home/louis/.asdf/installs/ruby/2.3.0/bin/rufo:23:in `load'
from /home/louis/.asdf/installs/ruby/2.3.0/bin/rufo:23:in `<main>'
I've taken a look at generating a html-rendered output of our specs.
The result output is here.
The script is in the spec_viewer branch here.
Each pair of actual / expected code segments are scanned with Rippers lexer.
The lexical tokens are then used to a) rebuild the code b) highlight and render the code.
Each token type is associated with a theme following the base16 format (MIT licence) which means there are dozens of themes readily available etc.
Each code rebuild is tested to ensure the lexer output reflects our specs and provides a form of Ripper regression testing.
The html output / page structure is a bare bones proof of principle but it would be easy to offer a couple of themes (light / dark), and spec catagories etc.
Currently the generator is run via ruby spec/viewer/generate.rb (ruby version 2.3.5, 2.4.2, 2.5.0dev).
Thoughts?
Tools like neoformat treats non-zero exit codes as errors and will discard the returned text from rufo. I'm not sure what the best practice is but I would expect a tool (like rufo) to return zero if there was no errors (ie, the tool ran successfully).
While looking into #83 I tried rufo on a number of repositories for commonly-used gems and came across a few issues.
This one comes from the i18n gem.
Traceback:
Traceback (most recent call last):
18: from .rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'
17: from .rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
16: from .rvm/gems/ruby-2.5.0/bin/rufo:23:in `<main>'
15: from .rvm/gems/ruby-2.5.0/bin/rufo:23:in `load'
14: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/exe/rufo:4:in `<top (required)>'
13: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:12:in `run'
12: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:40:in `run'
11: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `format_args'
10: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `each'
9: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:82:in `block in format_args'
8: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:124:in `format_file'
7: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:165:in `format'
6: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:171:in `format'
5: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3600:in `dedent_calls'
4: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3600:in `each'
3: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3612:in `block in dedent_calls'
2: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3696:in `adjust_other_alignments'
1: from .rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3696:in `each'
.rvm/gems/ruby-2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3700:in `block in adjust_other_alignments': undefined method `[]' for nil:NilClass (NoMethodError)
File that triggers the issue: https://raw.githubusercontent.com/svenfuchs/i18n/ed3623f1a9a8eedd968ac5fd7040faccbb171547/lib/i18n/exceptions.rb
Now that we have cleaned up the config significantly as part of #2 it might be a good time to start thinking about how we go about implementing line length based code formatting.
Both @danielma and I have had a go at implementing this. We both used the printing algorithm described by Philip Wadler in his paper "A prettier printer" which can be found here.
We have taken different approaches for the implementation. You can see the WIP code for @danielma's here and my WIP code here.
This is the same algorithm used by Prettier. They have some descriptions of the commands used to power the formatter here.
The way that Prettier has been implemented can best be described by this flow:
Source -> Doc -> Formatted Source
. Where Doc
is an intermediary representation of the source code. It is this intermediary representation that is then printed with the line length aware formatter.
This approach has the advantage of the Doc
construction phase being the only language aware component. This allows for the same document construction utilities and formatter to be used for different languages. For example:
Ruby Source -> Doc -> Formatted Source
CSS/SCSS Source -> Doc -> Formatted Source
HTML ERB Source -> Doc -> Formatted Source
The downside to this approach is likely performance. I don't have any numbers to back this up but if we are doing more work then we are currently I would hazard to guess that the performance will decrease to some degree.
So I think we have a few decisions to make:
Hiya! Came across this issue when testing rufo's changes to a codebase. Rufo adds a trailing comma to hash args, which can break heredocs, as follows:
{
content: <<-EOF
This is a heredoc
EOF
}
...gets transformed to
{
content: <<-EOF
This is a heredoc
EOF,
]
Which will yield the error:
test.rb:5: can't find string "EOF" anywhere before EOF
test.rb:2: syntax error, unexpected end-of-input, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
In cases of heredocs, commas simply can't be placed without breaking the terminator.
I've got rufo 0.3.0 with the following .rufo
file
align_chained_calls true
I ran it with this file as input:
foo.
bar
And to my surprise, this is preserved. I would have expected that the align_chained_calls
setting would replace the trailling dot notation for a leading dot notation.
Up until now I get it that that's not the case, and although it could be debatable, that may well be intentional so it's not a bug (perhaps a subject for another issue about that).
However, I ran it through this code:
expect(MixpanelTrackWorker).to receive(:perform_async).
with('[email protected]', 'Republish Job', an_instance_of(Hash))
And I got this:
expect(MixpanelTrackWorker).to receive(:perform_async).
with("[email protected]", "Republish Job", an_instance_of(Hash))
The change is subtle, but notice the 4-space indentation of the second line in the output.
This does not seem consistent when the above. Wasn't this code supposed to stay untouched, just as in the foo.bar example? What's this 4-space indentation about?
Hi,
I found strange behavior of indents for comments. Here is a spec to reproduce.
RSpec.describe 'wrong indents for bare_assoc_hash' do
assert_format "foo(\n# comment for foo\nfoo: 'foo',\n\n# comment for bar\nbar: 'bar',\n)", "foo(\n # comment for foo\n foo: 'foo',\n\n # comment for bar\n bar: 'bar',\n)"
end
And the result.
RuntimeError: Expected
~~~
foo(
# comment for foo
foo: 'foo',
# comment for bar
bar: 'bar',
)
~~~
to format to:
~~~
foo(
# comment for foo
foo: 'foo',
# comment for bar
bar: 'bar',
)
~~~
but got:
~~~
foo(
# comment for foo
foo: 'foo',
# comment for bar
bar: 'bar',
)
~~~
diff = "foo(\n # comment for foo\n foo: 'foo',\n\n # comment for bar\n bar: 'bar',\n)\n"
"foo(\n# comment for foo\n foo: 'foo',\n\n # comment for bar\n bar: 'bar',\n)\n"
When I put braces around the hash, rufo formatted as expected.
Hello there! First of all: thank you very much for Rufo! I hope it takes off like a Falcon rocket ๐
I was playing with it on one for my personal projects, and noticed that unlike the examples listed in the aligning call parameters section of the README, the alignment on method arguments is not preserved.
Input file:
def method_with_a_lot_of_args(
hello:,
world:,
foo:,
bar:,
baz:
)
puts "hello, world!"
end
method_with_a_lot_of_args(
hello: 1,
world: 2,
foo: 3,
bar: 4,
baz: 5
)
Rufo output:
def method_with_a_lot_of_args(
hello:,
world:,
foo:,
bar:,
baz:)
puts "hello, world!"
end
method_with_a_lot_of_args(
hello: 1,
world: 2,
foo: 3,
bar: 4,
baz: 5,
)
My expectation: I would like for Rufo to also keep the existing alignment, as it does on method calls.
What do you think? I know that Rufo is not about personal opinion, but this result was quite unexpected to me, as I wouldn't expect different rules for calling a method from declaring a method.
Thanks! ๐
I am keen to discuss where rufo is heading, so I thought i'd start an issue on the topic.
Personally I am very excited about this project, and am keen to see its continued development. I'm a little tired of spending time in code reviews paying attention to formatting concerns, to me, this is solely the job of a formatter, and the more opinionated the better. I'd like my formatter to enforce rules strictly, even if I don't necessarily agree with them. The value I get from there being a One True Format exceeds that of having code look just how I like it.
To that end, I'd like to see the default settings of rufo be more opinionated, and less permissive. Much like tools like prettier. But that's definitely my personal bias, and I'd love to know what others think on the matter.
echo "class A end; class B end;class C end # comment" | rufo
gives:
class A end;
class B end;
class C end # comment
Trying out rufo in my project, I like it with one dealbreaking exception: the apparent forced "aligning of arrays" (or other things). I imagine this is something that has been discussed before, but I couldn't find a specific issue.
Rufo changes this code:
class Email
class Schema
class RemoveRecipient < ApplicationSchema
define do |schema|
schema.required(:property).schema do
required(:recipient_type, Types::Coerce::String).filled(included_in?: [
"THIS IS A LONG STRING OF TEXT THAT REALLY SHOULDN'T BE PUSHED TO THE RIGHT",
"CC",
"BCC",
])
required(:email_address, Types::Email).filled
end
end
end
end
end
To this, which contains an unacceptable line length for me (it actually also removes the extra line breaks, but I've added them back in for readability):
class Email
class Schema
class RemoveRecipient < ApplicationSchema
define do |schema|
schema.required(:property).schema do
required(:recipient_type, Types::Coerce::String).filled(included_in?: [
"THIS IS A LONG STRING OF TEXT THAT REALLY SHOULDN'T BE PUSHED TO THE RIGHT",
"CC",
"BCC",
])
required(:email_address, Types::Email).filled
end
end
end
end
end
I see issue #54 is already dealing with line length based formatting, which maybe this would fall under, but I wanted to call out this case specifically because, so far as I can tell, there's currently no way to stop the above behavior.
Is the above considered a bug? Desired behavior?
I would argue that consistency in formatting is important, and because the above is unacceptable, the only solution that will work consistently is to never "align arrays". The same logic would apply to "aligning" other items like case statements:
I.e. this:
this_is_a_long_veriable_name = case some_variable
when :one
"THIS IS A REALLY LONG STRING THAT REALLY SHOULDN'T BE PUSHED TO THE RIGHT"
when :two
"one"
end
Is transformed to this:
this_is_a_long_veriable_name = case some_variable
when :one
"THIS IS A REALLY LONG STRING THAT REALLY SHOULDN'T BE PUSHED TO THE RIGHT"
when :two
"one"
end
Personally, in all these cases I could accept a minor level of consistent indentation, the exact amount of which could be decided in a separate issue:
I.e. something like
this_is_a_long_veriable_name = case some_variable
when :one
"THIS IS A REALLY LONG STRING THAT REALLY SHOULDN'T BE PUSHED TO THE RIGHT"
when :two
"one"
end
Anyway, obviously this is your project, and I definitely won't press the issue if you decide to keep things as is.
It's also possible I could accept inconsistant formatting, where rufo tried to "align things", but would fall back on other behavior if that produced a line length that is too long. I'd really question this, specific, choice though (i.e. why not just choose the consistent option?).
I have multiple situations where I need to check for exactly those two characters in order, or to consume those two characters because I need them. When I reformat something with Rufo, this:
record_separator = "\x0d\x0a"
becomes
record_separator = "
"
And that is bad because in this situation, for example, I'm checking for end of record in a line of data from an EBCDIC text file from a mainframe (yes, for some reason they almost always use ASCII crlf as record separators in my experience). If the separator character becomes a literal line break, it becomes just a \x0a and the carriage return character stays (because I'm using either Linux or a Mac), which means that it doesn't consume the entire EOR sequence and I get an error. Not to mention putting a literal line break in quotes like that just looks weird.
But basically, I've had two gems so far that this broke, and when I tracked down the reason, it was this behavior. Can you change it so that it leaves these sequences alone? This also happens if I'm matching inside a regular expression, so it seems like any quote-like construct that takes escaped hex characters will get them replaced by literals, but in these cases I want them to be the escaped characters and changing them breaks things.
I noticed that if a pass a hash to a function and I put every key-value pair on its own line, the last key-value pair gets a comma appended to it.
create(
name: "Joe",
email: "[email protected]",
customer_id: cust.id,
)
In this case a comma is added after the customer_id
value.
I think this is not the expected behaviour.
Before:
return if flash[:notice].is_a?(Array) || (
flash[:notice].present? && (
flash[:notice][/foo/] ||
flash[:notice][/bar/]
)
)
After:
return if flash[:notice].is_a?(Array) || (flash[:notice].present? && (flash[:notice][/foo/] ||
flash[:notice][/bar/]))
(I replaced the regular expressions with examples.)
But the reformatted code has a really long line, which I'm trying to avoid.
I am running rufo
at Arch Linux for following simple ruby script
srcs = %w(
myserver.c
)
emit_each(:cc, srcs)
and rufo is panicking:
You've found a bug!
It happened while trying to format the file ./example/shog.build
Please report it to https://github.com/ruby-formatter/rufo/issues with code that triggers it
Traceback (most recent call last):
24: from /usr/bin/rufo:23:in `<main>'
23: from /usr/bin/rufo:23:in `load'
22: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/exe/rufo:4:in `<top (required)>'
21: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:12:in `run'
20: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:40:in `run'
19: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `format_args'
18: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:81:in `each'
17: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:82:in `block in format_args'
16: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:124:in `format_file'
15: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/command.rb:165:in `format'
14: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:166:in `format'
13: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:187:in `visit'
12: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `visit_exps'
11: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each_with_index'
10: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:483:in `each'
9: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:502:in `block in visit_exps'
8: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3563:in `push_node'
7: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:503:in `block (2 levels) in visit_exps'
6: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:349:in `visit'
5: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:975:in `visit_call_without_receiver'
4: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:332:in `visit'
3: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:273:in `visit'
2: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:2990:in `consume_token'
1: from /usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3424:in `check'
/usr/lib/ruby/gems/2.5.0/gems/rufo-0.2.0/lib/rufo/formatter.rb:3429:in `bug': Expected token on_ident, not on_words_sep at [[2, 12], :on_words_sep, "\n", #<Ripper::Lexer::State: EXPR_BEG>] (Rufo::Bug)
When I try and use vscode with rufo, or use rufo from the command line I cannot get single quotes to get converted to double quotes.
Rufo will respect the .rufo config and turn double quotes into single quotes.
I'm pretty new to ruby and rufo in general. I have a very simplistic .rufo
file:
quote_style :single
trailing_commas true
When I use this and use vscode-rufo I get no error, but the single are not changed. I know it's recognizing the config because when I change to an invalid option:
quote_style single
I get an error. The trailing comma configuration works fine. I've looked into the recent pull request that intended on fixing this, but I don't know the correct way to make it work. This is most likely an error on my end. But I can't find what to do to fix it.
Windows 10
PS: I'm using our issue template: https://github.com/OperationCode/operationcode_backend/blob/master/.github/ISSUE_TEMPLATE.md would recommend one for your amazing project. It really helps filter out low effort submissions.
When a string in a Ruby file contains "รฉ" or any other non-Latin a-zA-Z character (foreign languages), the file fails syntax checking.
Error: the given text is not a valid ruby program (it has syntax errors)
.rufo
filerufo -v #=> rufo 0.1.0
Given this code:
class Foo
def self.bar(_)
end
bar \
def baz
end
end
The formatter will change it to:
class Foo
def self.bar(_)
end
bar \
def baz
end
end
Is there any settings to avoid this behavior?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.