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
Add option OnlyFor
to the Bundler/GemComment
cop.
#7978
Add option OnlyFor
to the Bundler/GemComment
cop.
#7978
Conversation
By the way, I'm also planning on doing a similar PR for parameters that change the source of a gem, such as I was thinking it could be a bit more general and work by receiving a list of parameter names that should activate the cop, something like: Does that make sense to you? |
OnlyIfVersionRestricted
to the Bumdler/GemComment
cop.OnlyIfVersionRestricted
to the Bundler/GemComment
cop.
@@ -5,7 +5,7 @@ module Cop | |||
module Bundler | |||
# Add a comment describing each gem in your Gemfile. | |||
# | |||
# @example | |||
# @example OnlyIfVersionRestricted: false (default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also expand the cop summary.
You should also mention this in the default config. I'm not sure I like the idea of a boolean option, though - might be a better idea to have some styles like "always", "only gems with some extra params". I like your idea overall, but we have to be careful to make the config both easy to understand and extendable. |
Yeah, making it extensible is a great point. What do you think of a configuration with three parameters:
Where As an example:
Would only trigger for a gem that has version restrictions OR uses at least one of |
The problem with the boolean flags approach is that some of them are not compatible with one another and this makes the configuration harder. A different approach might be to just have a list of things to check - e.g.:
And I guess when empty this can mean "all". Or there can be an enforced style "All" and "Subset" and the second one would consult this extra configuration option. Not sure what's the best approach, but I really don't like the boolean flags, so I'd rather us avoid it. |
My last suggestion would make the options compatible with each other, it's just that But I like your suggestion, it makes the configuration more straightforward, just need to treat version specifiers as a special case 👍 |
Fine by me. |
@bbatsov The new version has a single new configuration: If it's empty the cop behaves the same as before, checking all gems, otherwise it only registers offenses on gems with one or more of the configured options.
Happy to change the names to whatever you prefer, if you don't think they're clear enough or consistent with rubocop conventions. |
Co-authored-by: mwolman <33032571+mwolman@users.noreply.github.com>
Co-authored-by: mwolman <33032571+mwolman@users.noreply.github.com>
Co-authored-by: mwolman <33032571+mwolman@users.noreply.github.com>
Co-authored-by: mwolman <33032571+mwolman@users.noreply.github.com>
OnlyIfVersionRestricted
to the Bundler/GemComment
cop.OnlyWhenUsingAnyOf
to the Bundler/GemComment
cop.
All the tests pass on my machine, the failing test seems completely unrelated to this PR, not sure what to do. |
I think it's a good idea to summarize in docs somewhere all the common params (https://bundler.io/man/gemfile.5.html) for its easier for people to figure out what's available to them. |
You should also update |
Thanks! |
OnlyWhenUsingAnyOf
to the Bundler/GemComment
cop.OnlyFor
to the Bundler/GemComment
cop.
This PR adds a boolean option
OnlyFor
to theBundler/GemComment
cop.The goal of this option is to require gem comments only if the gem version has an explicit version specifier or other options like
required/github/etc
, so that the reason for the specifier/options is documented.I tested it on a project I work on and it worked as expected.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.