Skip to content

Add RuboCop cops to enforce code reusing rules

Yorick Peterse requested to merge rubocop-code-reuse into master

What does this MR do?

This adds various RuboCop cops that enforce the rules outlined in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21254.

These cops reuse rules such as not being able to use a Finder in another Finder, or using a Finder in a model class method. Existing offences have been disabled, allowing us to solve them over time.

This MR is quite large due to there being many existing offences, which had to be whitelisted. This is done in separate commits, and so I recommend reviewing the following commits individually:

  1. https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21391/diffs?commit_id=91c40973dc620430b173ea2df968587d2a708dff

EE MR: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/7229

What are the relevant issue numbers?

TODO

  • Service classes
    • Disallow in Finders
    • Disallow in Presenters
    • Disallow in Serializers
    • Disallow in model class methods
  • Finders
    • Disallow in Finders
    • Disallow in model class methods
  • Presenters
    • Disallow in Service classes
    • Disallow in Finders
    • Disallow in Presenters
    • Disallow in Serializers
    • Disallow in Model class methods
    • Disallow in Model instance methods
    • Disallow in Workers
  • Serializers
    • Disallow in Service classes
    • Disallow in Finders
    • Disallow in Presenters
    • Disallow in Serializers
    • Disallow in Model class methods
    • Disallow in Model instance methods
    • Disallow in Workers
  • Active Record
    • Disallow everywhere, except in models
  • Worker
    • Disallow in Controller
    • Disallow in Grape API
    • Disallow in Finder
    • Disallow in Presenter
    • Disallow in Serializer
    • Disallow in Model class method
  • Set up EE MR
  • Whitelist EE specific offenses

Does this MR meet the acceptance criteria?

Edited by Yorick Peterse

Merge request reports