|The server mode was introduced in RuboCop 1.31. If you’re using an older RuboCop version you can check out the rubocop-daemon project that served as the inspiration for RuboCop’s built-in functionality.|
You can reduce the RuboCop boot time significantly (something like 850x faster) by using the
--server command-line option.
--server option speeds up the launch of the
rubocop command by utilizing
a standalone server process that loads the RuboCop runtime production files (i.e.
Normally RuboCop starts somewhat slowly because it needs to
require a ton of files and that’s fairly
slow. With the RuboCop server we sidestep this nasty issue and make it much more pleasant to
interact with RuboCop from text editors and IDEs.
The feature cannot be used on JRuby and Windows, as they do not support the
Run with Server
There are two ways to enable server:
rubocop --server: If server process has not started yet, start server process and execute inspection with server.
rubocop --start-server: Just start server process.
When the server is started, it outputs the host and port.
$ rubocop --start-server RuboCop server starting on 127.0.0.1:55772.
If a server is already running, the command only displays the server’s PID. A new server will not be started.
$ rubocop --start-server RuboCop server (16060) is already running.
The server process name is basically
rubocop --server and the project directory path:
$ ps aux | grep 'rubocop --server' user 16060 0.0 0.0 5078568 2264 ?? S 7:54AM 0:00.00 rubocop --server /Users/user/src/github.com/rubocop/rubocop user 16337 0.0 0.0 5331560 2396 ?? S 23:51PM 0:00.00 rubocop --server /Users/user/src/github.com/rubocop/rubocop-rails
When you update and run
rubocop, the server process will restart automatically.
% rubocop --server RuboCop version incompatibility found, RuboCop server restarting... RuboCop server starting on 127.0.0.1:60665.
The started server does not reload the configuration file. You will need to restart the server when you upgrade RuboCop or change the RuboCop configuration.
% rubocop --restart-server RuboCop server starting on 127.0.0.1:55822.
Command Line Options
These are the command-line options for server operations:
If a server process has not been started yet, start the server process and execute inspection with server.
If a server process has been started, stop the server process and execute inspection without the server.
Restart server process.
Start server process.
Stop server process.
Show server status.
|You can specify the server host and port with the $RUBOCOP_SERVER_HOST and the $RUBOCOP_SERVER_PORT environment variables.|
RUBOCOP_OPTS environment variable or
.rubocop file contains
rubocop command defaults to server mode.
Other server options such as
restart-server specified on the command line will take precedence over them.