Closed npupko closed 1 year ago
This is not a bug. When you call treesj on brackets - it'll format node block
to do_block
(or reverse). But if you call treesj inside - it'll format another configured node body_statement
. body_statement
uses not only inside block
/do_block
(see tests/sample/index.rb
for more info).
You can use follow preset in your plugin settings for ruby to avoid this situation:
-- other nodes
body_statement = lang_utils.set_preset_for_non_bracket({
both = {
enable = function(tsn)
local t = tsn:parent():type()
return not (t == 'block' or t == 'do_block')
end,
},
-- other node settings
}),
-- other nodes
Personally, I am not using ruby and if these settings are suitable for all cases for block
, do_block
and body_statement
- please, let me know. I'll add it to the default ruby preset.
https://github.com/Wansmer/treesj/assets/46977173/98e0a2a2-e402-44cc-b0b1-d87b7d76c260
@Wansmer Thank you for the quick answer. Yes, this behavior is definitely what I used to see usually. Added to my config. I should've investigate it deeper before creating this "bug":) This issue may be closed.
As for the default settings, I would say in Ruby it's considered a good practice to always use {
and }
for one-liners: styleguide so I guess this could be added to the default configuration.
Example:
https://github.com/Wansmer/treesj/assets/5938539/de32db11-74f8-4379-8635-bbd386ac8bc6
For construction
While calling
require('treesj').join()
inside block it will not convertdo
/end
to{
and}
. Everything works ok if the cursor outside, or directly ondo
orend