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
b4f0e809
Commit
b4f0e809
authored
Aug 26, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
d9d1bcdb
519a130c
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
67 additions
and
112 deletions
+67
-112
.rubocop.yml
.rubocop.yml
+54
-0
rubocop/cop/gitlab/httparty.rb
rubocop/cop/gitlab/httparty.rb
+1
-5
rubocop/cop/gitlab/union.rb
rubocop/cop/gitlab/union.rb
+0
-4
rubocop/cop/graphql/authorize_types.rb
rubocop/cop/graphql/authorize_types.rb
+0
-6
rubocop/cop/include_action_view_context.rb
rubocop/cop/include_action_view_context.rb
+0
-5
rubocop/cop/include_sidekiq_worker.rb
rubocop/cop/include_sidekiq_worker.rb
+1
-4
rubocop/cop/rspec/env_assignment.rb
rubocop/cop/rspec/env_assignment.rb
+1
-4
rubocop/cop/rspec/factories_in_migration_specs.rb
rubocop/cop/rspec/factories_in_migration_specs.rb
+1
-4
rubocop/cop/sidekiq_options_queue.rb
rubocop/cop/sidekiq_options_queue.rb
+1
-4
rubocop/spec_helpers.rb
rubocop/spec_helpers.rb
+0
-30
spec/rubocop/cop/gitlab/union_spec.rb
spec/rubocop/cop/gitlab/union_spec.rb
+0
-6
spec/rubocop/cop/rspec/env_assignment_spec.rb
spec/rubocop/cop/rspec/env_assignment_spec.rb
+6
-20
spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
+2
-20
No files found.
.rubocop.yml
View file @
b4f0e809
...
...
@@ -181,6 +181,9 @@ Gitlab/ModuleWithInstanceVariables:
Gitlab/HTTParty
:
Enabled
:
true
Exclude
:
-
'
spec/**/*'
-
'
ee/spec/**/*'
GitlabSecurity/PublicSend
:
Enabled
:
true
...
...
@@ -214,3 +217,54 @@ ActiveRecordAssociationReload:
Exclude
:
-
'
spec/**/*'
-
'
ee/spec/**/*'
RSpec/FactoriesInMigrationSpecs
:
Enabled
:
true
Include
:
-
'
spec/migrations/**/*.rb'
-
'
ee/spec/migrations/**/*.rb'
-
'
spec/lib/gitlab/background_migration/**/*.rb'
-
'
ee/spec/lib/gitlab/background_migration/**/*.rb'
Cop/IncludeActionViewContext
:
Enabled
:
true
Exclude
:
-
'
spec/**/*'
-
'
ee/spec/**/*'
Cop/IncludeSidekiqWorker
:
Enabled
:
true
Exclude
:
-
'
spec/**/*'
-
'
ee/spec/**/*'
Gitlab/Union
:
Enabled
:
true
Exclude
:
-
'
spec/**/*'
-
'
ee/spec/**/*'
Cop/SidekiqOptionsQueue
:
Enabled
:
true
Exclude
:
-
'
spec/**/*.rb'
-
'
ee/spec/**/*.rb'
Graphql/AuthorizeTypes
:
Enabled
:
true
Exclude
:
-
'
spec/**/*.rb'
-
'
ee/spec/**/*.rb'
RSpec/EnvAssignment
:
Enable
:
true
Include
:
-
'
spec/**/*.rb'
-
'
ee/spec/**/*.rb'
Exclude
:
-
'
spec/**/fast_spec_helper.rb'
-
'
ee/spec/**/fast_spec_helper.rb'
-
'
spec/**/rails_helper.rb'
-
'
ee/spec/**/rails_helper.rb'
-
'
spec/**/spec_helper.rb'
-
'
ee/spec/**/spec_helper.rb'
rubocop/cop/gitlab/httparty.rb
View file @
b4f0e809
require_relative
'../../spec_helpers'
# frozen_string_literal: true
module
RuboCop
module
Cop
module
Gitlab
class
HTTParty
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MSG_SEND
=
<<~
EOL
.
freeze
Avoid calling `HTTParty` directly. Instead, use the Gitlab::HTTP
wrapper. To allow request to localhost or the private network set
...
...
@@ -27,8 +25,6 @@ module RuboCop
PATTERN
def
on_send
(
node
)
return
if
in_spec?
(
node
)
add_offense
(
node
,
location: :expression
,
message:
MSG_SEND
)
if
httparty_node?
(
node
)
add_offense
(
node
,
location: :expression
,
message:
MSG_INCLUDE
)
if
includes_httparty?
(
node
)
end
...
...
rubocop/cop/gitlab/union.rb
View file @
b4f0e809
# frozen_string_literal: true
require_relative
'../../spec_helpers'
module
RuboCop
module
Cop
...
...
@@ -7,8 +6,6 @@ module RuboCop
# Cop that disallows the use of `Gitlab::SQL::Union`, in favour of using
# the `FromUnion` module.
class
Union
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MSG
=
'Use the `FromUnion` concern, instead of using `Gitlab::SQL::Union` directly'
def_node_matcher
:raw_union?
,
<<~
PATTERN
...
...
@@ -17,7 +14,6 @@ module RuboCop
def
on_send
(
node
)
return
unless
raw_union?
(
node
)
return
if
in_spec?
(
node
)
add_offense
(
node
,
location: :expression
)
end
...
...
rubocop/cop/graphql/authorize_types.rb
View file @
b4f0e809
# frozen_string_literal: true
require_relative
'../../spec_helpers'
module
RuboCop
module
Cop
module
Graphql
class
AuthorizeTypes
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MSG
=
'Add an `authorize :ability` call to the type: '
\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
...
...
@@ -32,8 +28,6 @@ module RuboCop
private
def
in_type?
(
node
)
return
if
in_spec?
(
node
)
path
=
node
.
location
.
expression
.
source_buffer
.
name
path
.
include?
(
TYPES_DIR
)
...
...
rubocop/cop/include_action_view_context.rb
View file @
b4f0e809
# frozen_string_literal: true
require_relative
'../spec_helpers'
module
RuboCop
module
Cop
# Cop that makes sure workers include `::Gitlab::ActionViewOutput::Context`, not `ActionView::Context`.
class
IncludeActionViewContext
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MSG
=
'Include `::Gitlab::ActionViewOutput::Context`, not `ActionView::Context`, for Rails 5.'
.
freeze
def_node_matcher
:includes_action_view_context?
,
<<~
PATTERN
...
...
@@ -15,7 +11,6 @@ module RuboCop
PATTERN
def
on_send
(
node
)
return
if
in_spec?
(
node
)
return
unless
includes_action_view_context?
(
node
)
add_offense
(
node
.
arguments
.
first
,
location: :expression
)
...
...
rubocop/cop/include_sidekiq_worker.rb
View file @
b4f0e809
require_relative
'../spec_helpers'
# frozen_string_literal: true
module
RuboCop
module
Cop
# Cop that makes sure workers include `ApplicationWorker`, not `Sidekiq::Worker`.
class
IncludeSidekiqWorker
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MSG
=
'Include `ApplicationWorker`, not `Sidekiq::Worker`.'
.
freeze
def_node_matcher
:includes_sidekiq_worker?
,
<<~
PATTERN
...
...
@@ -13,7 +11,6 @@ module RuboCop
PATTERN
def
on_send
(
node
)
return
if
in_spec?
(
node
)
return
unless
includes_sidekiq_worker?
(
node
)
add_offense
(
node
.
arguments
.
first
,
location: :expression
)
...
...
rubocop/cop/rspec/env_assignment.rb
View file @
b4f0e809
require_relative
'../../spec_helpers'
# frozen_string_literal: true
module
RuboCop
module
Cop
...
...
@@ -17,8 +17,6 @@ module RuboCop
# stub_env('FOO', 'bar')
# end
class
EnvAssignment
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MESSAGE
=
"Don't assign to ENV, use `stub_env` instead."
.
freeze
def_node_search
:env_assignment?
,
<<~
PATTERN
...
...
@@ -28,7 +26,6 @@ module RuboCop
# Following is what node.children looks like on a match
# [s(:const, nil, :ENV), :[]=, s(:str, "key"), s(:str, "value")]
def
on_send
(
node
)
return
unless
in_spec?
(
node
)
return
unless
env_assignment?
(
node
)
add_offense
(
node
,
location: :expression
,
message:
MESSAGE
)
...
...
rubocop/cop/rspec/factories_in_migration_specs.rb
View file @
b4f0e809
require_relative
'../../spec_helpers'
# frozen_string_literal: true
module
RuboCop
module
Cop
...
...
@@ -14,8 +14,6 @@ module RuboCop
# let(:users) { table(:users) }
# let(:user) { users.create!(name: 'User 1', username: 'user1') }
class
FactoriesInMigrationSpecs
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MESSAGE
=
"Don't use FactoryBot.%s in migration specs, use `table` instead."
.
freeze
FORBIDDEN_METHODS
=
%i[build build_list create create_list]
.
freeze
...
...
@@ -27,7 +25,6 @@ module RuboCop
# - Without FactoryBot namespace: [nil, :build, s(:sym, :user)]
# - With FactoryBot namespace: [s(:const, nil, :FactoryBot), :build, s(:sym, :user)]
def
on_send
(
node
)
return
unless
in_migration_spec?
(
node
)
return
unless
forbidden_factory_usage?
(
node
)
method
=
node
.
children
[
1
]
...
...
rubocop/cop/sidekiq_options_queue.rb
View file @
b4f0e809
require_relative
'../spec_helpers'
# frozen_string_literal: true
module
RuboCop
module
Cop
# Cop that prevents manually setting a queue in Sidekiq workers.
class
SidekiqOptionsQueue
<
RuboCop
::
Cop
::
Cop
include
SpecHelpers
MSG
=
'Do not manually set a queue; `ApplicationWorker` sets one automatically.'
.
freeze
def_node_matcher
:sidekiq_options?
,
<<~
PATTERN
...
...
@@ -13,7 +11,6 @@ module RuboCop
PATTERN
def
on_send
(
node
)
return
if
in_spec?
(
node
)
return
unless
sidekiq_options?
(
node
)
node
.
arguments
.
first
.
each_node
(
:pair
)
do
|
pair
|
...
...
rubocop/spec_helpers.rb
deleted
100644 → 0
View file @
d9d1bcdb
module
RuboCop
module
SpecHelpers
SPEC_HELPERS
=
%w[fast_spec_helper.rb rails_helper.rb spec_helper.rb]
.
freeze
MIGRATION_SPEC_DIRECTORIES
=
[
'spec/migrations'
,
'spec/lib/gitlab/background_migration'
].
freeze
# Returns true if the given node originated from the spec directory.
def
in_spec?
(
node
)
path
=
node
.
location
.
expression
.
source_buffer
.
name
pwd
=
RuboCop
::
PathUtil
.
pwd
!
SPEC_HELPERS
.
include?
(
File
.
basename
(
path
))
&&
path
.
start_with?
(
File
.
join
(
pwd
,
'spec'
),
File
.
join
(
pwd
,
'ee'
,
'spec'
))
end
def
migration_directories
@migration_directories
||=
MIGRATION_SPEC_DIRECTORIES
.
map
do
|
dir
|
pwd
=
RuboCop
::
PathUtil
.
pwd
[
File
.
join
(
pwd
,
dir
),
File
.
join
(
pwd
,
'ee'
,
dir
)]
end
.
flatten
end
# Returns true if the given node originated from a migration spec.
def
in_migration_spec?
(
node
)
path
=
node
.
location
.
expression
.
source_buffer
.
name
in_spec?
(
node
)
&&
path
.
start_with?
(
*
migration_directories
)
end
end
end
spec/rubocop/cop/gitlab/union_spec.rb
View file @
b4f0e809
...
...
@@ -16,10 +16,4 @@ describe RuboCop::Cop::Gitlab::Union do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the `FromUnion` concern, instead of using `Gitlab::SQL::Union` directly
SOURCE
end
it
'does not flag the use of Gitlab::SQL::Union in a spec'
do
allow
(
cop
).
to
receive
(
:in_spec?
).
and_return
(
true
)
expect_no_offenses
(
'Gitlab::SQL::Union.new([foo])'
)
end
end
spec/rubocop/cop/rspec/env_assignment_spec.rb
View file @
b4f0e809
...
...
@@ -33,27 +33,13 @@ describe RuboCop::Cop::RSpec::EnvAssignment do
end
end
context
'in a spec file'
do
before
do
allow
(
cop
).
to
receive
(
:in_spec?
).
and_return
(
true
)
end
context
'with a key using single quotes'
do
it_behaves_like
'an offensive ENV#[]= call'
,
OFFENSE_CALL_SINGLE_QUOTES_KEY
it_behaves_like
'an autocorrected ENV#[]= call'
,
OFFENSE_CALL_SINGLE_QUOTES_KEY
,
%(stub_env('FOO', 'bar'))
end
context
'with a key using double quotes'
do
it_behaves_like
'an offensive ENV#[]= call'
,
OFFENSE_CALL_DOUBLE_QUOTES_KEY
it_behaves_like
'an autocorrected ENV#[]= call'
,
OFFENSE_CALL_DOUBLE_QUOTES_KEY
,
%(stub_env("FOO", 'bar'))
end
context
'with a key using single quotes'
do
it_behaves_like
'an offensive ENV#[]= call'
,
OFFENSE_CALL_SINGLE_QUOTES_KEY
it_behaves_like
'an autocorrected ENV#[]= call'
,
OFFENSE_CALL_SINGLE_QUOTES_KEY
,
%(stub_env('FOO', 'bar'))
end
context
'outside of a spec file'
do
it
"does not register an offense for `
#{
OFFENSE_CALL_SINGLE_QUOTES_KEY
}
` in a non-spec file"
do
inspect_source
(
OFFENSE_CALL_SINGLE_QUOTES_KEY
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
0
)
end
context
'with a key using double quotes'
do
it_behaves_like
'an offensive ENV#[]= call'
,
OFFENSE_CALL_DOUBLE_QUOTES_KEY
it_behaves_like
'an autocorrected ENV#[]= call'
,
OFFENSE_CALL_DOUBLE_QUOTES_KEY
,
%(stub_env("FOO", 'bar'))
end
end
spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
View file @
b4f0e809
...
...
@@ -8,8 +8,6 @@ require_relative '../../../../rubocop/cop/rspec/factories_in_migration_specs'
describe
RuboCop
::
Cop
::
RSpec
::
FactoriesInMigrationSpecs
do
include
CopHelper
let
(
:source_file
)
{
'spec/migrations/foo_spec.rb'
}
subject
(
:cop
)
{
described_class
.
new
}
shared_examples
'an offensive factory call'
do
|
namespace
|
...
...
@@ -27,22 +25,6 @@ describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do
end
end
context
'in a migration spec file'
do
before
do
allow
(
cop
).
to
receive
(
:in_migration_spec?
).
and_return
(
true
)
end
it_behaves_like
'an offensive factory call'
,
''
it_behaves_like
'an offensive factory call'
,
'FactoryBot.'
end
context
'outside of a migration spec file'
do
it
"does not register an offense"
do
expect_no_offenses
(
<<-
RUBY
)
describe 'foo' do
let(:user) { create(:user) }
end
RUBY
end
end
it_behaves_like
'an offensive factory call'
,
''
it_behaves_like
'an offensive factory call'
,
'FactoryBot.'
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