-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Inherit config from gems #290
Comments
I can't comment if a Rake task is the way the project team wants to go, but I can help with one thing. This is my Rake task for RuboCop: desc 'Run style checks'
task :rubocop do
sh 'rubocop'
end The |
That indeed is a lot easier. |
I'm not sure what benefits you'd get from a |
rubocop is project-aware, but that doesnt mean configurations should not be able to be shared. Use case: I've disabled some cops (because I do not agree with the style-guide on all points) and do not want to copy paste (and maintain) between this .yml in all projects. Therefore would like to put this configuration in one file, put it in a gem and load it in all my projects. The place for me to load the configuration from a gem would be in a rake task, but I just realize, that is just in my setting, so it can be whatever other ruby file that works. |
Today we have the One soluton could be to add ERB pre-processing of the config files so you could do things like # .rubocop.yml
<% require 'rubocop_config' %>
inherit_from <%= path_to_rubocop_config + '/config/rubocop_checks.yml' %> but it means we have to mix languages in the config files (someting Robert C. Martin warns about in Clean Code), and it seems pretty complicated. How about you do this in the inherit_from common_config/rubocop_checks.yml and then keep the |
Currently I think it's rather a role of external tools than RuboCop itself. If you really want to use just one configuration file in all your projects, put the If you prefer more flexible way, I think you can use $ cd some-project
$ git submodule add https://github.com/foo/common-config.git
$ vi .rubocop.yml
inherit_from: common-config/default.yml
# project specific configuration
# ... When you've updated the $ git submodule foreach git pull |
@jonas054 and @yujinakayama |
Let's identify the scenarios we want to enable. We currently have:
Now ... the typical way to enable configuration sharing would be to have a per-user and per-machine configuration. Anything else is typically up to the user. We do enable either of these scenarios with the I just had an idea ... You could create a gem with your configuration file and use But after going through the options of how to implement this and thinking of ways that other Ruby utilities work, I think I'm with @yujinakayama, that this level of configuration sharing is orthogonal to RuboCop. |
Thanks for all the help. I'll close this for now, non-file based configuration doesn't seem to be on rubocops roadmap. I think I'll eventually write a ruby wrapper_method that is put in a gem that generates a .rubocop.yml. (combining a general project_rubocop.yml and the common_rubocop.yml loaded from the gem) or something. |
I made a construction like this, and it works ok for me:
|
I've also recently run into a situation where it would be helpful to inherit a rubocop config from a gem's library path. I'm not saying it's up to Rubocop to install the gem, or determine the most up to date version, or anything like that; but if the project is using a gem, then presumably that gem has already been installed, and presumably executing rubocop would be done from a context in which the gem is already accessible. To simplify the implementation, it could be a new yml key (something like inherit_from: .rubocop_todo.yml
inherit_from_gem:
cucumber: 'config/rubocop.yml'
my_shared_gem: 'path/to/my/rubocop.yml'
AllCops:
# ... And the config loader would essentially perform something like: def resolve_inheritance_from_gem(gem_name, relative_config_path)
spec = Gem::Specification.find_by_name(gem_name)
f = File.join(spec.gem_dir, relative_config_path)
load_file(f)
end If the gem isn't available, it could either be silently ignored, or a proper error could be emitted suggesting that the required gem needs to be installed (or suggesting I understand the argument that this may be orthogonal to Rubocop, but it's not like this is anything that requires particularly obscure Ruby -- most projects successfully make use of shared gems, and if a project wants to use a shared rubocop configuration (without the need to maintain any symlinks, submodules, or resolve_inheritance_from_gem('rubocop', 'config/default.yml') I don't mean to resurrect a 2-year-old issue that was closed, but really all the alternatives given do not lend themselves to a "works-out-of-the-box" project -- i.e., where a Jenkins CI job can easily invoke rubocop for the project with: bundle install
bundle exec rubocop In fact, I would consider all of the suggested alternatives above specifically discouraged, because they each require external tools (symlinks, which are not supported on all platforms; |
The config directive should be in Hash format, with the `gem_name` as the key, and the `relative_path_to_config` as the value. Ex: inherit_from: .rubocop_todo.yml inherit_gem: cucumber: config/rubocop.yml mygem: path/to/my/shared/rubocop.yml
Resolve #290 to inherit rubocop config from a gem
[Feature request]
Hi,
Rake tasks are pretty much the way to go in ruby. its great for having things run in a build.
Also, rake tasks can be distrubuted by gems/rails engines etc, to reduce code duplication per project.
E.g. it is now hard to share the config like that. I was thinking of something like:
(since you cant do this in .yml)
It would be great if there's an API to support this.
My current rake task that is used by my build task:
The text was updated successfully, but these errors were encountered: