6

is there any chance to format code to satisfy rubocop?

By default my neovim is indenting code like that:

class Test
  attr_accessor :a, :b, :c,
    :d, :e, :f
end

However, it would be nicer to have it like that

class Test
  attr_accessor :a, :b, :c,
                :d, :e, :f
end
2

Maybe the tabular plugin suits your needs?

E.g:

class Test
  attr_accessor :a, :b, :c,
    :d, :e, :f
end

typing :Tabularize /:\a\S\s/l0 will result in

class Test
  attr_accessor:a, :b, :c,
               :d, :e, :f
end

:Tabularize /: aligns all colons. The colon must be followed by a letter (\a), a non whitespace character (\S) and a whitespace (\s). That complete match is then left-adjusted (/l0). The zero afterwards prevents Tabular to add whitespace after each alignment.

note that this is not permanent. I.e. when you reformat your code, the aligning is destroyed and it will look like the first example again. To make this aligning persistent, you could maybe define a custom formatting function which runs the above tabular command after the vim formatting. But I don't know much about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.