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

Ignore irrelevant cops when investigating a file #2175

Merged
merged 2 commits into from
Aug 24, 2015

Conversation

bquorning
Copy link
Contributor

Fixes #2142.

Instead of checking a cop's relevance for the current file multiple times in the investigation process, we can filter the cops one time, at the very beginning of the investigation.

The specs are were failing because of Rails/ActionFilters default configuration:

Rails/ActionFilter:
  Include:
    - app/controllers/**/*.rb

The temporary file being tested of course doesn’t match the configured Include pattern, and is therefore ignored. But I believe this is a problem with the spec, not with the implementation. Please help me: how can the specs be fixed?

@cops.select! { |cop| cop.relevant_file?(filename) }
end

# TODO: Bad design.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broken windows …

Copy link
Collaborator

Choose a reason for hiding this comment

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

:-) That's one pretty generic remark.

@bquorning bquorning closed this Aug 23, 2015
@bquorning bquorning reopened this Aug 23, 2015
@bquorning
Copy link
Contributor Author

0.00004% decreased code coverage is causing a red build?

On the plus side, the coverage of lib/rubocop/cop/commissioner.rb increased to 102.04%!

@@ -64,6 +63,11 @@ def reset_errors
end

# TODO: Bad design.
def remove_irrelevant_cops(filename)
@cops.select! { |cop| cop.relevant_file?(filename) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method name and the implementation kinda points in opposite directions. I thought of either naming the method #select_relevant_cops or changing the implementation to @cops.reject! { |cop| !cop.relevant_file?(filename) }. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can also add Cop#irrelevant_file?. :-) (or excluded_file?, which is more in line with our terminology so far).

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 23, 2015

Overall the changes look good to me. @jonas054 Any comments?

@@ -46,14 +46,13 @@ def #{callback}(node)

def investigate(processed_source)
reset_errors
remove_irrelevant_cops(processed_source.buffer.name)
prepare(processed_source)
invoke_custom_processing(@cops, processed_source)
invoke_custom_processing(@forces, processed_source)
process(processed_source.ast) if processed_source.ast
@cops.each_with_object([]) do |cop, offenses|
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 guess this could be changed to a simple map now?

@bquorning bquorning force-pushed the dont-process-irrelevant-cops branch from 02fd49d to dc45832 Compare August 23, 2015 19:22
# ignore files that are of no interest to the cop in question
offenses.concat(cop.offenses) if cop.relevant_file?(filename)
end
@cops.flat_map(&:offenses)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#flat_map and symbol-to-proc, how about that?

@bquorning bquorning force-pushed the dont-process-irrelevant-cops branch from 1e2f7ca to 1ddef56 Compare August 23, 2015 19:47
Instead of checking a cop's relevance for the current file multiple
times in the investigation process, we can filter the cops one time,
at the very beginning of the investigation.
The default config for the Rails/ActionFilter cop tells it to operate
only on controllers (`{ 'Include' => ['app/controllers/**/*.rb'] }`),
causing it to *not* operate on the temporary files generated by the
spec. Nullifying the `Include` configuration option in the spec makes
the spec pass.
@bquorning bquorning force-pushed the dont-process-irrelevant-cops branch from 1ddef56 to 4646794 Compare August 23, 2015 19:48
@rrosenblum
Copy link
Contributor

Looks good. I thought that this was going to be much more difficult to implement.

bbatsov added a commit that referenced this pull request Aug 24, 2015
Ignore irrelevant cops when investigating a file
@bbatsov bbatsov merged commit 920fdcb into rubocop:master Aug 24, 2015
@bquorning bquorning deleted the dont-process-irrelevant-cops branch August 24, 2015 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuboCop processes files that are excluded from individual cops
3 participants