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
d702a2e3
Commit
d702a2e3
authored
Apr 01, 2020
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add rubocop rule for preventing change timezone
This commit adds rubocop rule for preventing change timezone
parent
3ded5e45
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
1 deletion
+50
-1
.rubocop.yml
.rubocop.yml
+5
-0
rubocop/cop/gitlab/change_timzone.rb
rubocop/cop/gitlab/change_timzone.rb
+20
-0
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+4
-1
spec/rubocop/cop/gitlab/change_timezone_spec.rb
spec/rubocop/cop/gitlab/change_timezone_spec.rb
+21
-0
No files found.
.rubocop.yml
View file @
d702a2e3
...
...
@@ -200,6 +200,11 @@ Gitlab/ConstGetInheritFalse:
Exclude
:
-
'
qa/bin/*'
Gitlab/ChangeTimezone
:
Enabled
:
true
Exclude
:
-
config/initializers/time_zone.rb
Gitlab/HTTParty
:
Enabled
:
true
Exclude
:
...
...
rubocop/cop/gitlab/change_timzone.rb
0 → 100644
View file @
d702a2e3
# frozen_string_literal: true
module
RuboCop
module
Cop
module
Gitlab
class
ChangeTimezone
<
RuboCop
::
Cop
::
Cop
MSG
=
"Do not change timezone in the runtime (application or rspec), "
\
"it could result in silently modifying other behavior."
.
freeze
def_node_matcher
:changing_timezone?
,
<<~
PATTERN
(send (const nil? :Time) :zone= ...)
PATTERN
def
on_send
(
node
)
changing_timezone?
(
node
)
{
add_offense
(
node
)
}
end
end
end
end
end
spec/helpers/application_helper_spec.rb
View file @
d702a2e3
...
...
@@ -90,8 +90,11 @@ describe ApplicationHelper do
end
describe
'time_ago_with_tooltip'
do
around
do
|
example
|
Time
.
use_zone
(
'UTC'
)
{
example
.
run
}
end
def
element
(
*
arguments
)
Time
.
zone
=
'UTC'
@time
=
Time
.
zone
.
parse
(
'2015-07-02 08:23'
)
element
=
helper
.
time_ago_with_tooltip
(
@time
,
*
arguments
)
...
...
spec/rubocop/cop/gitlab/change_timezone_spec.rb
0 → 100644
View file @
d702a2e3
# frozen_string_literal: true
require
'spec_helper'
require
'rubocop'
require
'rubocop/rspec/support'
require_relative
'../../../../rubocop/cop/gitlab/change_timzone'
describe
RuboCop
::
Cop
::
Gitlab
::
ChangeTimezone
do
include
CopHelper
subject
(
:cop
)
{
described_class
.
new
}
context
'Time.zone='
do
it
'registers an offense with no 2nd argument'
do
expect_offense
(
<<~
PATTERN
.
strip_indent
)
Time.zone = 'Awkland'
^^^^^^^^^^^^^^^^^^^^^ Do not change timezone in the runtime (application or rspec), it could result in silently modifying other behavior.
PATTERN
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