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
fad99d93
Commit
fad99d93
authored
Apr 27, 2019
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Rubocop rule to ban include ActionView::Context
parent
b02458ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
0 deletions
+77
-0
rubocop/cop/include_action_view_context.rb
rubocop/cop/include_action_view_context.rb
+31
-0
rubocop/rubocop.rb
rubocop/rubocop.rb
+1
-0
spec/rubocop/cop/include_action_view_context_spec.rb
spec/rubocop/cop/include_action_view_context_spec.rb
+45
-0
No files found.
rubocop/cop/include_action_view_context.rb
0 → 100644
View file @
fad99d93
# 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
(send nil? :include (const (const nil? :ActionView) :Context))
PATTERN
def
on_send
(
node
)
return
if
in_spec?
(
node
)
return
unless
includes_action_view_context?
(
node
)
add_offense
(
node
.
arguments
.
first
,
location: :expression
)
end
def
autocorrect
(
node
)
lambda
do
|
corrector
|
corrector
.
replace
(
node
.
source_range
,
'::Gitlab::ActionViewOutput::Context'
)
end
end
end
end
end
rubocop/rubocop.rb
View file @
fad99d93
...
...
@@ -4,6 +4,7 @@ require_relative 'cop/gitlab/predicate_memoization'
require_relative
'cop/gitlab/httparty'
require_relative
'cop/gitlab/finder_with_find_by'
require_relative
'cop/gitlab/union'
require_relative
'cop/include_action_view_context'
require_relative
'cop/include_sidekiq_worker'
require_relative
'cop/safe_params'
require_relative
'cop/active_record_association_reload'
...
...
spec/rubocop/cop/include_action_view_context_spec.rb
0 → 100644
View file @
fad99d93
# frozen_string_literal: true
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../rubocop/cop/include_action_view_context'
describe
RuboCop
::
Cop
::
IncludeActionViewContext
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
context
'when `ActionView::Context` is included'
do
let
(
:source
)
{
'include ActionView::Context'
}
let
(
:correct_source
)
{
'include ::Gitlab::ActionViewOutput::Context'
}
it
'registers an offense'
do
inspect_source
(
source
)
aggregate_failures
do
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
expect
(
cop
.
offenses
.
map
(
&
:line
)).
to
eq
([
1
])
expect
(
cop
.
highlights
).
to
eq
([
'ActionView::Context'
])
end
end
it
'autocorrects to the right version'
do
autocorrected
=
autocorrect_source
(
source
)
expect
(
autocorrected
).
to
eq
(
correct_source
)
end
end
context
'when `ActionView::Context` is not included'
do
it
'registers no offense'
do
inspect_source
(
'include Context'
)
aggregate_failures
do
expect
(
cop
.
offenses
.
size
).
to
eq
(
0
)
end
end
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