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

Better separation of concerns between Team and Commissioner #8030

Merged
merged 5 commits into from May 26, 2020

Conversation

marcandre
Copy link
Contributor

Excluding non-relevant cops is a duty of Team, not Commissioner.

Before this PR:

  • a second call to Commissioner#investigate could be missing a cop that was excluded previously
  • a force might be added by Team for a single cop that is later judged to be non relevant by a Commissioner but the later can't exclude the force now
  • cops judged not relevant by the Commissioner were still looped through (e.g. in autocorrect_all_cops)

PR also includes some code cleanup. This is a prelude to #7968

@marcandre marcandre self-assigned this May 25, 2020
@marcandre marcandre marked this pull request as draft May 25, 2020 06:05
@marcandre
Copy link
Contributor Author

Argh, this is all good but the spec_helper needs to be fixed. It also shows it was duplicating the finding the forces. It should create a Team, not a Commissionner, but then this shows that Team doesn't have the right interface: it should accept cops, not cop classes. On hold.

Congrats to Metrics/AbcSize thinking this code is more complicated than before
Before this commit:
* a second call to `Commissioner#investigate` could be missing a cop that was excluded previously
* a force might be added by Team for a single cop that is later judged to be non relevant by Commissioner
  but the later can't exclude the force now
* cops judged not relevant by the Commissioner were still processed (e.g. in autocorrect_all_cops)
@marcandre marcandre marked this pull request as ready for review May 26, 2020 05:13
@marcandre
Copy link
Contributor Author

I refactored Team.new to accept an array of cops instead of an array of cop classes. Team doesn't actually need to create the cops itself and is more useful to accept cops. Previous functionality was moved to Team.mobilize.

I feel that's the cleanest API, but it would be easy for Team.new to accept an array of cops or an array of cop classes, thus maintaining compatibility. Is there any code out there that might call Team.new and should we care, especially for a v1? /cc @bbatsov

@bbatsov
Copy link
Collaborator

bbatsov commented May 26, 2020

I feel that's the cleanest API, but it would be easy for Team.new to accept an array of cops or an array of cop classes, thus maintaining compatibility.

Compatibility with what? :-) I think this class is not used outside the main gem. I did a quick grep in some extensions and I don't see any usages.

@bbatsov
Copy link
Collaborator

bbatsov commented May 26, 2020

Btw, this might also be a good opportunity to actually document the responsibilities of the class - I see currently they are "FIXME". :D

@marcandre marcandre merged commit aa930ec into rubocop:master May 26, 2020
@marcandre
Copy link
Contributor Author

Cool. I'll add a short doc and a Changelog entry

@marcandre
Copy link
Contributor Author

marcandre commented Jun 2, 2020

Compatibility with what? :-)

Now we know that the answer is, at least, pronto-rubocop and erb_lint 😅.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 3, 2020

So we do. :-)

yujideveloper added a commit to yujideveloper/pronto-rubocop that referenced this pull request Jun 4, 2020
Use `Rubocop::Cop::Team#mobilize` instead of `Rubocop::Cop::Team.new`
if RuboCop version is 0.85.0 and later because RuboCop changed `Team` API
at v0.85.0.
ref. rubocop/rubocop#8030
yujideveloper added a commit to yujideveloper/pronto-rubocop that referenced this pull request Jun 4, 2020
Use `Rubocop::Cop::Team#mobilize` instead of `Rubocop::Cop::Team.new`
if RuboCop version is 0.85.0 and later because RuboCop changed `Team` API
at v0.85.0.
ref. rubocop/rubocop#8030
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.

None yet

2 participants