Prevent Rubymine from auto-correcting hash and array alignment
RubyMine aggressively enforces the following style for arrays and hashes:
expect(something).to eq({
name: 'John Doe',
email: 'johndoe@example.com'
})
expect(something).to eq([
{
name: 'John Doe'
},
{
name: 'Jacob Lockard'
}
])
I find this to be extremely ugly and hard-to-follow. I much prefer something more like this:
expect(something).to eq({
name: 'John Doe',
email: 'johndoe@example.com'
})
expect(something).to eq([
{
name: 'John Doe'
},
{
name: 'Jacob Lockard'
}
])
However, it is nearly impossible to get RubyMine to allow this. Whenever I hit <enter> it indents the cursor, and whenever I hit <backspace>, it returns all the way to the previous line.
I have set the following in my `.rubocop.yml` to get RuboCop to respect this:
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent
Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent
RubyMine apparently does not pick up on this, however.
Any suggestions? It seems like there should be a setting under `Editor -> Code Style -> Ruby`, but nothing there seemed to help...
Please sign in to leave a comment.
Hello Jacob,
we have a request for adding more formatting options for hashes, could you please take a look:
https://youtrack.jetbrains.com/issue/RUBY-26542
Olga Kuvardina Ah, I see. Is there any way to disable that autocorrect feature altogether then?
You can try using 'Detect and use existing file indents for editing'
https://www.jetbrains.com/help/ruby/2021.3/settings-code-style.html#indents-detection
or markers for disabling formatter
https://www.jetbrains.com/help/ruby/2021.3/settings-code-style.html#formatter-control