-
-
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
Make cops with Rails compatibility issue dependant on Rails cops being disabled #2862
Make cops with Rails compatibility issue dependant on Rails cops being disabled #2862
Conversation
436bf95
to
fbdae39
Compare
@@ -61,6 +78,14 @@ def autocorrect(node) | |||
|
|||
private | |||
|
|||
def should_run? | |||
if config[RAILS] && config[RAILS][ENABLED] |
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.
What about the -R
/--rails
command line option?
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 had initially forgotten about the command line flags. It turns out that I will not have to do anything special to handle the command line flags. Runner#inspect_file
calls enable_rails_cops
if one of the command line flags is passed in and sets the config['Rails']['Enabled']
flag.
def inspect_file(processed_source)
config = @config_store.for(processed_source.path)
enable_rails_cops(config) if @options[:rails]
team = Cop::Team.new(mobilized_cop_classes(config), config, @options)
offenses = team.inspect_file(processed_source)
@errors.concat(team.errors)
@warnings.concat(team.warnings)
[offenses, team.updated_source_file?]
end
def enable_rails_cops(config)
config['Rails'] ||= {}
config['Rails']['Enabled'] = true
end
It's been stated many times that we want to remove the Rails cops from RC and make them a separate gem. What will happen to this code when that is done? |
fbdae39
to
f85baea
Compare
@alexdowad, I think that this will work just fine when the Rails cops are moved out to a different gem. Both gems would make use of the |
bf4d9c0
to
648d0e5
Compare
648d0e5
to
22b3701
Compare
Btw, you can be using ActiveSupport or similar gems even without Rails, so while this might solve some cases of the problem, it definitely won't solve all of them. |
But my real concern is having something Rails-specific in the code, when long-term I want to move the Rails functionality out of it. |
I am aware that this wouldn't solve all cases, but the hope was that it would at least help some. I can understand not wanting to add Rails specific code to base project. Once the Rails cops are refactored out, we should be able to disable the cops or the auto-correct from inside that project. |
OK, I guess it's ok to add something like this for the time being. Still, I'd like for the comments and descriptions to be more specific, as ActiveSupport/Record are just two pieces of Rails. |
@@ -1173,6 +1173,11 @@ Performance/Count: | |||
Use `count` instead of `select...size`, `reject...size`, | |||
`select...count`, `reject...count`, `select...length`, | |||
and `reject...length`. | |||
# This cop has known compatibility issues with Rails. Rails' `count` ignores |
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.
Here there should be a reference to ActiveRecord.
Will do. I left it generically to Rails initially because the same distinction isn't make for |
There's definitely room for improvement regarding their names. :-) |
69fd6a5
to
6578e62
Compare
@@ -75,6 +75,10 @@ | |||
* [#2923](https://github.com/bbatsov/rubocop/issues/2923): `Style/FileName` considers file names which contain a ? or ! character to still be "snake case". ([@alexdowad][]) | |||
* [#2879](https://github.com/bbatsov/rubocop/issues/2879): When autocorrecting, `Lint/UnusedMethodArgument` removes unused block arguments rather than simply prefixing them with an underscore. ([@alexdowad][]) | |||
|
|||
### Changes |
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.
This section isn't at the right location.
6578e62
to
934df83
Compare
Updated and rebased. |
Make cops with Rails compatibility issue dependant on Rails cops being disabled
For what it’s worth, I’ve submitted a patch to Rails that would make auto-correcting the |
@sferik thanks for putting in a PR to Rails. That has been on my radar for a while. It has been a little while since I worked with |
@rrosenblum By my reading of the code, |
I remembered the issue. ActiveRecord partially supports
|
It has been a while since this has come up, but it is still a known issue. Since we cannot determine if the method comes from Ruby or Rails, the next best thing is to determine if Rails is going to be in used and not run these cops if it is. Short of scanning the Gemfile for a rails entry, this seemed like the easiest and most self contained approach. If anyone has an alternative idea, I am open to suggestions.