Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard does not forward --server to rubocop #462

Open
multiplegeorges opened this issue Sep 22, 2022 · 2 comments
Open

Standard does not forward --server to rubocop #462

multiplegeorges opened this issue Sep 22, 2022 · 2 comments

Comments

@multiplegeorges
Copy link

Issue

When running standardrb on the CLI, I expect that any args not recognized by standard will be forwarded to the rubocop invocation. This does not seem to happen with --server.

Expectation

Subsequent invocations of standardrb should run much faster when the rubocop server has been launched after the first invocation.

Example

❯ time bundle exec standardrb --fix --server '/Users/georges/development/.../config/initializers/http_defaults.rb'
Inspecting 1 file
.

1 file inspected, no offenses detected
bundle exec standardrb --fix --server   2.02s user 0.81s system 91% cpu 3.086 total

❯ time bundle exec standardrb --fix --server '/Users/georges/development/.../config/initializers/http_defaults.rb'
Inspecting 1 file
.

1 file inspected, no offenses detected
bundle exec standardrb --fix --server   1.85s user 0.75s system 95% cpu 2.714 total

Full file path intentionally omitted above.
As you can see, there is no appreciable speedup seen when passing the --server option.

In addition, the rubocop server has not been launched.

❯ rubocop -v
1.36.0

❯ standardrb -v
1.16.1

❯ ps | grep rubocop
90401 ttys004    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox rubocop

❯ time standardrb --server config/initializers/http_defaults.rb
Inspecting 1 file
.

1 file inspected, no offenses detected
standardrb --server config/initializers/http_defaults.rb  1.18s user 0.50s system 95% cpu 1.771 total

❯ ps | grep rubocop
90627 ttys004    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox rubocop

❯
@searls
Copy link
Contributor

searls commented Sep 26, 2022

Howdy. I spent ten minutes looking into this (I'd never heard of the --server feature in Rubocop before.

This should be achievable, but I don't think I'm going to make the time to do this myself.

Some breadcrumbs if you or someone else wants to take a stab at a PR:

  1. Some nomenclature: RuboCop's CLI has "options" (command-line args / env vars), including --server, --server-status, --start-server, --stop-server as well as "configuration" (the config file of cops and settings). These are both handed to a Runner, which in RuboCop are factored as "Commands". You can see the server commands here

  2. Standard imitates the shape of this runner style by invoking RuboCop's primary Runner (in most cases) and implementing our own (when someone adds --version etc). These live in lib/runners

  3. This is where Standard determines which Runner Command to invoke if we were to add server ones.

I believe a PR could implement this behavior of either forking or forwarding to RuboCop's server commands from a new Standard set of commands. Because the server is doing stuff, there's a chance we'd need to fork or patch whatever the RuboCop server is invoking, in turn, though, so it's not really clear it'd work.

@multiplegeorges
Copy link
Author

Thanks for that background @searls, very appreciated.
I'll leave this issue here for anyone else wondering. It seems like a good implementation requires someone to get into the internals of both projects.

In the meantime, an interim way to go would be using Rubocop directly with Standard's set of cops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants