vscode( vscode-ruby + rubocop ) how to auto correct on save?

Per this comment on the vscode-ruby-rubocop GitHub, you can use the following settings:

{
    "editor.formatOnSave": true,
    "editor.formatOnSaveTimeout": 5000,
    "ruby.rubocop.executePath": "path/where/rubocop/is/located",
    "ruby.format": "rubocop",
}

Just applied them to my user settings on my local box and it appears to work. VS Code was throwing an error for my ruby.rubocop.executePath setting saying it wasn't executable, and removing the line appears to not cause that error to show, and still formats my code accordingly. Setting a lower timeout (I tried 2500) also seems to break auto format on saving, so I'd suggest leaving it at 5000.


Now, it's enough just adding these lines:

{
  "ruby.rubocop.onSave": true,
  "editor.formatOnSave": true,
}

I've tried all the options other people shared and it fixed linking for me (so I would get warnings when my code wasn't formatted correctly) but it didn't fix indentation or other formatting on save.

What seemed to work for me is adding a default formatter option. If you look at the bottom right corner in vscode you should see a notification icon which might throw in a few warnings that can help with your config. For me it was adding:

"[ruby]": {
  "editor.defaultFormatter": "misogi.ruby-rubocop"
}