Draft: Add cop Gitlab/RoutingUrlHelpers
Description of the proposal
This MR adds a new Gitlab/RoutingUrlHelpers
to enforce use of Gitlab::Routing.url_helpers
instead of Rails.application.routes.url_helpers
.
This MR also generates TODOs for Gitlab/RoutingUrlHelpers and enable "grace period" and adds a new section URL helpers
to development guidelines in https://docs.gitlab.com/ee/development/routing.html.
Why?
Gitlab::Routing
implements more convenient path helpers which are not available via Rails.application.routes.url_helpers
.
Code
# bad
Rails.application.routes.url_helpers.root_path(foo: :bar)
# good
Gitlab::Routing.url_helpers.root_path
Example offense
ee/app/helpers/projects/security/api_fuzzing_configuration_helper.rb:8:33: C: [Correctable] Gitlab/RoutingUrlHelpers: Prefer Gitlab::Routing over Rails.application.routes. See https://docs.gitlab.com/ee/development/routing.html
gitlab_ci_yaml_edit_path: Rails.application.routes.url_helpers.project_ci_pipeline_editor_path(project),
^^^^^^^^^^^^^^^^^^^^^^^^
Check-list
-
Make sure this MR enables a static analysis check rule for new usage but ignores current offenses. -
Mention this proposal in the relevant Slack channels (e.g. #development
,#backend
,#frontend
).- Vote for both choices, so they are visible to others.
-
The MR doesn't have significant objections, and is getting a majority of 👍 vs👎 (remember that we don't need to reach a consensus). -
Create a follow-up issue to fix the current offenses as a separate iteration: #390359 (closed) -
Follow the review process as usual. -
Once approved and merged by a maintainer, mention it again: -
In the relevant Slack channels (e.g. #development
,#backend
,#frontend
). -
(Optional depending on the impact of the change) In the Engineering Week in Review.
-
Edited by Peter Leitzen