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

Explore plugin configs #498

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/labeler.yml
@@ -1 +1,8 @@
"config change": rubocop.yml
"config change": rubocop*.yml
"hq": rubocop.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure of a good label name, so I went with the "cop" analogy of headquarters. 🤷

"graphql": rubocop.graphql.yml
"minitest": rubocop.minitest.yml
"performance": rubocop.performance.yml
"rails": rubocop.rails.yml
"rake": rubocop.rake.yml
"rspec": rubocop.rspec.yml
9 changes: 9 additions & 0 deletions Gemfile
Expand Up @@ -8,3 +8,12 @@ gem "diffy"
gem "minitest"
gem "pry-byebug"
gem "rake"

group :plugins do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could use this to skip installing these in one of our CI runs, so we can ensure everything still works for consumers only using RuboCop.

gem "rubocop-graphql"
gem "rubocop-minitest"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rake"
gem "rubocop-rspec"
end
35 changes: 35 additions & 0 deletions Gemfile.lock
Expand Up @@ -7,10 +7,18 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.4.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.2)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.2.0)
diffy (3.4.2)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.3)
method_source (1.0.0)
minitest (5.17.0)
Expand All @@ -23,6 +31,7 @@ GEM
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
rack (3.0.4.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.6.2)
Expand All @@ -39,7 +48,27 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-capybara (2.17.0)
rubocop (~> 1.41)
rubocop-graphql (0.19.0)
rubocop (>= 0.87, < 2)
rubocop-minitest (0.27.0)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.16.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.17.4)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.18.1)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-progressbar (1.11.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)

PLATFORMS
Expand All @@ -50,6 +79,12 @@ DEPENDENCIES
minitest
pry-byebug
rake
rubocop-graphql
rubocop-minitest
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec
rubocop-shopify!

BUNDLED WITH
Expand Down
Empty file added rubocop.graphql.yml
Empty file.
16 changes: 16 additions & 0 deletions rubocop.infer.yml
@@ -0,0 +1,16 @@
<%
# Identify installed RuboCop plugins to configure
plugin_configs = {
"rubocop" => "rubocop.yml",
"rubocop-graphql" => "rubocop.graphql.yml",
"rubocop-minitest" => "rubocop.minitest.yml",
"rubocop-performance" => "rubocop.performance.yml",
"rubocop-rails" => "rubocop.rails.yml",
"rubocop-rake" => "rubocop.graphql.yml",
"rubocop-rspec" => "rubocop.rspec.yml",
}.select { |plugin_name, _| Gem.loaded_specs.include?(plugin_name) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tricky part is that this checks if the gem is installed in the computer, not in the bundler right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The way it would work is that if a consumer has

# .rubocop.yml
inherit_gem:
  rubocop-shopify: rubocop.infer.yml

then when they run rubocop it will look at their installed gems, and inherit from the applicable configs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if the app doesn't have rubocop-minitest for example but the person has it installed globally we should not use it.

We should be using what is on the Gemfile.lock of the application, not what is on the gem paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I should have said "in their Gemfile" not "installed". I just confirmed Gem.loaded_specs handles this the way we want:

% cat Gemfile
source 'https://rubygems.org'
% bundle exec ruby -e 'puts Gem.loaded_specs.key?("rubocop-minitest")'
false
% gem install rubocop-minitest
Successfully installed rubocop-minitest-0.32.2
Parsing documentation for rubocop-minitest-0.32.2
Installing ri documentation for rubocop-minitest-0.32.2
Done installing documentation for rubocop-minitest after 0 seconds
1 gem installed
% bundle exec ruby -e 'puts Gem.loaded_specs.key?("rubocop-minitest")'
false
% bundle add rubocop-minitest > /dev/null && cat Gemfile
source 'https://rubygems.org'

gem "rubocop-minitest", "~> 0.32.2"
% bundle exec ruby -e 'puts Gem.loaded_specs.key?("rubocop-minitest")'
true
% bundle exec ruby -e 'puts Gem.loaded_specs.key?("rubocop")'
true

%>

require: <%= plugin_configs.keys.to_json %>

inherit_from: <%= plugin_configs.values.to_json %>
2 changes: 2 additions & 0 deletions rubocop.minitest.yml
@@ -0,0 +1,2 @@
Minitest:
Enabled: true
Comment on lines +1 to +2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't bothered filling out most of these files, but presumably they'd look like:

PluginName:
  Enabled: true

# ...config for cops where we want to diverge from the default...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could alternatively call these after the gem names (e.g. rubocop-minitest.yml).

I just went with what we use in Core. 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to not use defaults. Let's always curate cops.

Empty file added rubocop.performance.yml
Empty file.
Empty file added rubocop.rails.yml
Empty file.
Empty file added rubocop.rake.yml
Empty file.
Empty file added rubocop.rspec.yml
Empty file.