-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic line length based formatting support #66
Add basic line length based formatting support #66
Conversation
Why:
Why: So that other usages don't need to be fixed yet.
Why: So that I can workout what the formatter needs to construct.
@gingermusketeer This is looking great! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! I have a few small things I'd tweak, but no major hangups. This is a great step forward!
lib/rufo/formatter.rb
Outdated
# arg1, ..., *star | ||
doc = visit args | ||
else | ||
pre_doc, *_ = with_doc_mode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a multiline block, can we use do...end
?
lib/rufo/formatter.rb
Outdated
doc << B.concat([last, B.if_break(",", "")]) | ||
end | ||
|
||
B.group( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expression is really nice to read 👏.
In the end, I think this points to a more readable future for rufo. Instead of needing to keep the entire stack in your head to understand a point in code, we can capture output and express the ultimate shape of an expression at the end
lib/rufo/formatter.rb
Outdated
|
||
elements.each_with_index do |elem, i| | ||
doc_el = visit(elem) | ||
if doc_el.is_a?(Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: what do you think about coalescing every doc_el
into an array? This can replace this entire if
expression
doc.concat Array(doc_el)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried this and it causes the tests to break. Perhaps we can revisit this once we are further down the implementation of prettier printer.
lib/rufo/settings.rb
Outdated
value = options.fetch(name, default) | ||
unless valid_options.include?(value) | ||
$stderr.puts "Invalid value for #{name}: #{value.inspect}. Valid " \ | ||
"values are: #{valid_options.map(&:inspect).join(', ')}" | ||
"values are: #{valid_options.map(&:inspect).join(', ')}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did a space get added here? Was it added manually, or did rufo do that in the formatting pass?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um not sure to be honest. I will run the formatter over it once the tests are passing. Hopefully that will remove it.
@danielma Thanks for the feedback :) |
@gingermusketeer just a heads-up whilst checking out your printer: [([1,2]), ([3,4]), ([5,6])] formats to: [), ), )] |
Why: So that syntax highlighting will work in some editors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me.
Why: content was being removed due to the regex being used.
Why: So that each type does not need to be wrapped in a capture_output block.
Why: Until this is used by other parts of the formatter we cannot handle anything before the array other than indentation.
Why: So that tests work on ruby 2.3.
f6ab762
to
ba42b5c
Compare
Why: to reduce code duplication.
@bessey Apologies for the slow response. Yes your understanding is correct :) I have all the tests passing now that heredocs are finally working. Only concern is this pending test: https://github.com/ruby-formatter/rufo/pull/66/files#diff-1be4af1647655801c693a52968d5d64dR754 The changes causes any multiline method calls inside an array to have incorrect indentation. I am hesitant to try and tackle that in this PR due to how big this getting. I can see a couple options for how we proceed:
Thoughts? |
✋ vote for
|
FYI, I'm working on a branch right now that would fix that indent error. Trying to get familiar with using this doc building code |
I've been talking to @gingermusketeer on Gitter this afternoon and we feel it would probably be better in the long run to develop a new formatter along side the old one, in a branch called new-formatter - complete with its own specs. Once complete the new formatter can be switched into prime time. This allows the current formatter to be maintained and receive bug fixes as reported in isolation to the new formatter work. The idea is to strip the new formatter of much of the old `wiring mechanism' and build up the doc-based formatter piece by piece, working back up from the simpler sexp structures to the more complex structures containing the simpler structures. |
Works for me!
Ps I'm pretty busy over the Xmas period so haven't been very active here,
but I'll be back in January.
…On Mon, 11 Dec 2017, 21:09 Martyn Jago, ***@***.***> wrote:
I've been talking to @gingermusketeer <https://github.com/gingermusketeer>
on Gitter this afternoon and we feel it would probably be better in the
long run to develop a new formatter along side the old one, in a branch
called new-formatter - complete with its own specs. Once complete the new
formatter can be switched into prime time. This allows the current
formatter to be maintained and receive bug fixes as reported in isolation
to the new formatter work. The idea is to strip the new formatter of much
of the old `wiring mechanism' and build up the doc-based formatter piece by
piece, working back up from the simpler sexp structures to the more complex
structures containing the simpler structures.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#66 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AArOaJjAC4xTx5DmY4aN2J3ltyoBcfoOks5s_ZoBgaJpZM4QjHW4>
.
|
Any news here? I notice the |
@bessey I will merge this branch into there now :) |
First step as part of #54.
Adds:
print_width
Remaining: