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
Redesign of the configuration system #1151
Comments
@yujinakayama I'm more or less 100% with you. Making the config as complex as it's now was definitely a mistake in hindsight. Personally, I've almost never used the ability to have multiple config files in a project and I want us to kill this for the sake of simplicity of the code (and its workings). I've also regretted for a while the choice of yml for configuration and I'll enjoy immensely getting rid of it (especially now when we introduced namespaces). With a Ruby config sky will be the limit and it's pretty obvious all of RuboCop's users know Ruby anyways. Looking at the suggested config format I don't like only one thing: Style::LineLength.tap do |cop|
cop.enabled = true
cop.max = 100
end
# this would be better
Style::LineLength.configure do
enabled = true
max = 100
end In the block On the subject of the config file - I'm not a huge fan of the |
I thought this syntax once, but gave up since setters in Ruby cannot be invoked without explicit receiver (in this case Style::LineLength.configure do |cop|
enabled true # or `set_enabled true`
max 100
end
Seems reasonable. |
Oh, yes, you're totally right. Without the self those will be considered local variables. Silly me... |
By the way, I'm also planning to build YAML-to-Ruby config converter for smooth migration. I guess it's not so difficult task. |
@yujinakayama That'd be great as I don't want us to have to keep the two config systems side by side. |
@yujinakayama Looks great! I really like the idea of writing configuration in a programming language (Ruby) rather than a data format (YAML, INI, JSON). Choosing the simple (and very limiting) format at an early stage is a mistake that's been made over and over again in a variety of projects, including ours. Are you pretty close to a complete solution yourself or is there any way we can help? |
I have not yet started the implementation. I have a rough plan and there will be some side tasks such as documentation, migration support, detailed design decision, etc., but it's still a bit unclear to ask you to start them now. I will ask for your help when it's ready. :) |
I would like to raise a concern I have here, please feel free to tell me to put this in a new issue or somewhere else :) My concern is ease of upgrading my configuration from one rubocop version to the next. I just started using rubocop and I just upgraded from 0.24.1 to 0.25.0, and I just experienced a nontrivial amount of pain trying to upgrade our configuration in such a way that we could easily see what has changed and be confident that it's what we wanted. We originally used Anyway, it would be incredible to be able to upgrade rubocop, and run some command that would:
I'm not sure if or how any of these considerations fit into the plans to move the configuration to ruby... I could see some of these concerns falling away, and some becoming harder perhaps. |
@carols10cents Personally, I think those are great ideas for the Yaml-to-Ruby configuration migration that @yujinakayama mentioned and @bbatsov commented on earlier. I think your first bullet is an absolute and obvious requirement. I don't know that deprecated cops have ever happened (have they, guys?); if there's a rule that's influential enough to have a cop to enforce it, the only way I can see that going away is in light of Ruby language changes, like the move away from hashrocket syntax in hashes post-Ruby 1.9. @yujinakayama and @bbatsov, let me just put my two cents in on naming: Please make the file |
Two more cents here (perhaps less): I also vote for no leading dot on the new config file name. My vim fuzzy finder (CtrlP w/ silver searcher) excludes hidden files by default. I always forget and try to find .rubocop.yml with it then fall back to |
Personally I would go +1 for the leading dot. This is fairly standard convention for configuration files. It's also nice to have the option for less cluttered |
My
|
Is there any update on this topic? Or anybody really working on it? The result of this can be found in this gist: https://gist.github.com/sch1zo/cd06dd8b0bd641cdfe31 Some points to note:
Let me know what you think about my PoC. I'll probably play around with it some more anyway and look into how much stuff in rubocop would need to change to introduce something like this. |
I'd like to add another problem with this proposal: A simple configuration file in YAML or some other generally parsable format allows external tools to read the file without having to worry about security problems. For example, there is at least one code reviewing service (pullreview.com) that uses RuboCop to analyse pull requests. They are currently not using the project's RuboCop configuration but instead have their own. With configuration in YAML format, they would at some point be able to safely merge the project's configuration with their own. Configuration as Ruby would make this, or even running RuboCop with the project's configuration much more dangerous. If people want to make programmatic rules for their RuboCop configuration, I think they should create a separate rake task to generate the .rubocop.yml file. |
HoundCI uses RuboCop as well. I see CodeClimate are planning to add style check to their platform and I'd be surprised if they don't use RuboCop as well (as most of their checks are done with other open-source tools). Having two config systems would introduce significant overhead IMO. To be honest I haven't thought about this issue in a while (super busy at work, etc), but we'll definitely keep in mind the external services relying on the existing format. |
Without @yujinakayama it seems this is going nowhere and I'll just close it. |
As we know the current configuration system is flawed, I'm planning a redesign of the system. Currently this is a draft and feedbacks are welcomed.
Problems in the current configuration system
Not project-aware
The current system allows you to customize configuration in a generic directory-based way. Practically
.rubocop.yml
is put in a project root directory, but technically it doesn't indicate where the project root is. Since generally configuration is a project-specific thing and should not be overridden by another configuration outside of the project, the current system's versatility unnecessarily makes things complex:Exclude
.rubocop.yml
at the project root, and need to check outside of the project for this.vendor
)RunRailsCops
).rubocop.yml
in a subdirectory?Complex inheritance system
The inheritance provides a sort of abstraction, but it seems to be overkill for a project-specific thing.
.rubocop.yml
in thespec
directory!”Include/Exclude
paths and the config file pathsNot programmable
Since it's YAML:
Include/Exclude
) in the default configuration are reset by user's data.!ruby/regexp /^some_pattern$/
New design
The new design needs to solve all the problems above.
Rubocopfile
(though this may spread the misspelledRubocop
:P) or.rubocop.rb
?Though there's a tradeoff between readability and magical syntax (and it's the most difficult decision in this design) and currently I'm not sure about it, here's an example:
What do you think? @bbatsov @jonas054
The text was updated successfully, but these errors were encountered: