Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
485f84fc
Commit
485f84fc
authored
May 10, 2020
by
Arun Kumar Mohan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Rubocop cop to flag keyword arguments usage in Sidekiq workers
parent
3cb7eebb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
0 deletions
+80
-0
.rubocop.yml
.rubocop.yml
+6
-0
changelogs/unreleased/rubocop-flag-kwargs-in-sidekiq-workers-cop.yml
...unreleased/rubocop-flag-kwargs-in-sidekiq-workers-cop.yml
+5
-0
rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb
rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb
+20
-0
spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb
...op/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb
+49
-0
No files found.
.rubocop.yml
View file @
485f84fc
...
...
@@ -28,6 +28,12 @@ AllCops:
-
'
file_hooks/**/*'
CacheRootDirectory
:
tmp
Cop/AvoidKeywordArgumentsInSidekiqWorkers
:
Enabled
:
true
Include
:
-
'
app/workers/**/*'
-
'
ee/app/workers/**/*'
Cop/StaticTranslationDefinition
:
Enabled
:
true
Exclude
:
...
...
changelogs/unreleased/rubocop-flag-kwargs-in-sidekiq-workers-cop.yml
0 → 100644
View file @
485f84fc
---
title
:
Add Rubocop cop to flag keyword arguments usage in Sidekiq workers
merge_request
:
31551
author
:
Arun Kumar Mohan
type
:
added
rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers.rb
0 → 100644
View file @
485f84fc
module
RuboCop
module
Cop
# Cop that blacklists keyword arguments usage in Sidekiq workers
class
AvoidKeywordArgumentsInSidekiqWorkers
<
RuboCop
::
Cop
::
Cop
MSG
=
"Do not use keyword arguments in Sidekiq workers. "
\
"For details, check https://github.com/mperham/sidekiq/issues/2372"
.
freeze
OBSERVED_METHOD
=
:perform
def
on_def
(
node
)
return
if
node
.
method_name
!=
OBSERVED_METHOD
node
.
arguments
.
each
do
|
argument
|
if
argument
.
type
==
:kwarg
||
argument
.
type
==
:kwoptarg
add_offense
(
node
,
location: :expression
)
end
end
end
end
end
end
spec/rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers_spec.rb
0 → 100644
View file @
485f84fc
# frozen_string_literal: true
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../rubocop/cop/avoid_keyword_arguments_in_sidekiq_workers'
describe
RuboCop
::
Cop
::
AvoidKeywordArgumentsInSidekiqWorkers
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
it
'flags violation for keyword arguments usage in perform method signature'
do
expect_offense
(
<<~
RUBY
)
def perform(id:)
^^^^^^^^^^^^^^^^ Do not use keyword arguments in Sidekiq workers. For details, check https://github.com/mperham/sidekiq/issues/2372
end
RUBY
end
it
'flags violation for optional keyword arguments usage in perform method signature'
do
expect_offense
(
<<~
RUBY
)
def perform(id: nil)
^^^^^^^^^^^^^^^^^^^^ Do not use keyword arguments in Sidekiq workers. For details, check https://github.com/mperham/sidekiq/issues/2372
end
RUBY
end
it
'does not flag a violation for standard optional arguments usage in perform method signature'
do
expect_no_offenses
(
<<~
RUBY
)
def perform(id = nil)
end
RUBY
end
it
'does not flag a violation for keyword arguments usage in non-perform method signatures'
do
expect_no_offenses
(
<<~
RUBY
)
def helper(id:)
end
RUBY
end
it
'does not flag a violation for optional keyword arguments usage in non-perform method signatures'
do
expect_no_offenses
(
<<~
RUBY
)
def helper(id: nil)
end
RUBY
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment