Skip to content

Draft: Enable rake related cop rules via rubocop-rake

Peter Leitzen requested to merge pl-rubocop-rake into master

What does this MR do and why?

This MR enables a set of 👮 cop rule related to rake.

Contributes to #391438 (comment 1276168070).

Refs gitlab-org/ruby/gems/gitlab-styles!161 (merged).

How to set up and validate locally

unset REVEAL_RUBOCOP_TODO
bundle exec rubocop --parallel --only Rake/ClassDefinitionInTask,Rake/DuplicateNamespace,Rake/DuplicateTask,Rake/MethodDefinitionInTask,Rake/Require

# No offenses/errors

bundle exec rake 'rubocop:todo:generate[Rake/ClassDefinitionInTask,Rake/DuplicateNamespace,Rake/DuplicateTask,Rake/MethodDefinitionInTask,Rake/Require]'
git status
# No changes

RuboCop configuration diff

Via rubocop --show-cops on master and this MR:

--- before.txt	2023-02-13 13:14:43.825105730 +0100
+++ after.txt	2023-02-13 13:13:46.297421290 +0100
@@ -1,4 +1,4 @@
-# Available cops (999) + config for /home/peter/devel/gitlab/gdk/gitlab: 
+# Available cops (1004) + config for /home/peter/devel/gitlab/gdk/gitlab: 
 # Department 'API' (3):
 # Supports --autocorrect
 API/Base:
@@ -6264,10 +6264,38 @@
   Enabled: pending
   VersionAdded: '2.17'
 
-# Department 'Rake' (1):
+# Department 'Rake' (6):
+Rake/ClassDefinitionInTask:
+  Description: Do not define a class or module in rake task, because it will be defined
+    to the top level.
+  Enabled: true
+  VersionAdded: 0.3.0
+
+# Supports --autocorrect
+Rake/Desc:
+  Description: Describe the task with `desc` method.
+  Enabled: false
+  VersionAdded: 0.1.0
+
+Rake/DuplicateNamespace:
+  Description: Do not define namespace with the same name
+  Enabled: true
+  VersionAdded: 0.5.0
+
+Rake/DuplicateTask:
+  Description: Do not define tasks with the same name
+  Enabled: true
+  VersionAdded: 0.4.0
+
+Rake/MethodDefinitionInTask:
+  Description: Do not define a method in rake task, because it will be defined to the
+    top level.
+  Enabled: true
+  VersionAdded: 0.2.0
+
 Rake/Require:
   Include:
-  - "{,ee/,jh/}lib/**/*.rake"
+  - "{,ee/,jh/}lib/tasks/**/*.rake"
   - qa/tasks/**/*.rake
   Enabled: true
 

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports