vscode-rubocopThis is the official VS Code extension for RuboCop. You can install this VS Code extension from the Visual Studio Marketplace. For VS Code-based IDEs like VSCodium or Eclipse Theia, the extension can be installed from the Open VSX Registry. Language Server CapabilitiesThese are the capabilities of this extension, each enabled by RuboCop's built-in LSP server. It supports the following capabilities:
:star2: Pro tip: Enabling Format On Save is recommended. By activating just this one setting, code gets autocorrected every time a file is saved. Don't miss out on this game-changing boost to your development experience! RequirementsConfigurationThe extension only offers a few of its own configuration options, but because it conforms to the VS Code Formatting API, several general editor settings can impact the extension's behavior as well. Configuring the VS Code editor to use RuboCopThere are two general editor settings that you'll want to verify are set in order to use RuboCop as your formatter. editor.formatOnSaveTo automatically format your Ruby with RuboCop, check Format on Save in the Formatting settings under Text Editor: Or, in
editor.defaultFormatterNext, if you have installed multiple extensions that provide formatting for Ruby
files (it's okay if you're not sure—it can be hard to tell), you can specify
RuboCop as your formatter of choice by setting
Configuring RuboCop extension optionsTo edit RuboCop's own options, first expand Extensions and select RuboCop from the sidebar of the Settings editor. rubocop.modeThe Mode setting determines how (and whether) RuboCop runs in a given
workspace. Generally, it will try to execute
Or, in
rubocop.autocorrectThe autocorrect option does what it says on the tin. if you don't want RuboCop to automatically edit your documents on save, you can disable it here: You might want to disable this if you're using RuboCop to highlight problems
but don't want it to edit your files automatically. You could also accomplish
this by disabling Or, in
rubocop.safeAutocorrectThis feature requires RuboCop 1.54+ to be enabled. When autocorrect is enabled, Or, in
rubocop.lintModeThis feature requires RuboCop 1.55+ to be enabled. Run lint only cops ( Or, in
rubocop.layoutModeThis feature requires RuboCop 1.55+ to be enabled. Run layout only cops. If you only want to enable the feature as a formatter, you can conveniently set it here: Or, in
Furthermore, enabling autocorrect with the rubocop.commandPathAs described above, the extension contains logic to determine which version of
This will override whatever search strategy is set in Or, in
rubocop.yjitEnabledThis extension supports YJIT, which can speed up the built-in language server in RuboCop.
The You can disable YJIT by unchecking. Or, in
Changing settings only for a specific projectYou may want to apply certain settings to a specific project, which you can do by configuring them in the Workspace scope as opposed to the global User scope. Clicking "Workspace" before changing a setting will save it to
Manually triggering a format with autocorrectsIn addition to the built-in VS Code Formatting API, you can trigger the
extension to format and autocorrect the current file listing by running
the command "RuboCop: Format with Autocorrects". This is equivalent to This is handy if you don't want to enable format-on-save, already have another formatter associated with Ruby files, want to format your code before saving, or just want to bind a shortcut to RuboCop's formatting action. To map a keybind to the command, search for it by name in the Keyboard Shortcuts editor: Or, in
You can also trigger the extension to format and autocorrect all the current file listing by running
the command "RuboCop: Format All with Autocorrects". This is equivalent to This command "RuboCop: Format All with Autocorrects" requires RuboCop 1.56+ to be enabled. You can use two autocorrect commands depending on the purpose. Decoding the Status Bar itemThe extension also includes a status bar item to convey the status of the current file listing at a glance. When the file conforms to RuboCop without issue: When the file contains a low-severity formatting issue: When the file contains a normal linter error: When the file fails to parse at all: Clicking the status bar item will open the problems tab: LimitationsThere's some room for improvement yet, but it isn't yet clear whether these limitations will be a big deal in practice:
AcknowledgementsThis extension's codebase was initially based on Standard Ruby's vscode-standard-ruby and Kevin Newton's vscode-syntax-tree extension, which has a similar architecture (VS Code language client communicating with a long-running Ruby process via STDIO). Thank you! Code of ConductThis project follows The RuboCop Community Code of Conduct. |