forked from covermymeds/rubocop-thread_safety
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d55c1b
commit da79885
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module ThreadSafety | ||
# Avoid using `Dir.chdir` due to its process-wide effect. | ||
# | ||
# @example | ||
# # bad | ||
# Dir.chdir("/var/run") | ||
class DirChdir < Base | ||
MSG = 'Avoid using `Dir.chdir` due to its process-wide effect.' | ||
RESTRICT_ON_SEND = %i[chdir].freeze | ||
|
||
def on_send(node) | ||
return unless node.receiver&.source == 'Dir' | ||
|
||
add_offense(node) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::ThreadSafety::DirChdir, :config do | ||
let(:msg) { 'Avoid using `Dir.chdir` due to its process-wide effect.' } | ||
|
||
context 'with `Dir.chdir` method' do | ||
it 'registers an offense' do | ||
expect_offense(<<~RUBY) | ||
Dir.chdir("/var/run") | ||
^^^^^^^^^^^^^^^^^^^^^ #{msg} | ||
RUBY | ||
end | ||
|
||
it 'registers an offsence when called without arguments' do | ||
expect_offense(<<~RUBY) | ||
Dir.chdir | ||
^^^^^^^^^ #{msg} | ||
RUBY | ||
end | ||
end | ||
|
||
context 'with another `Dir` module method' do | ||
it 'does not register an offense' do | ||
expect_no_offenses 'Dir.pwd' | ||
end | ||
end | ||
|
||
context 'when received is not `Dir`' do | ||
it 'does not register an offense' do | ||
expect_no_offenses 'chdir("/tmp")' | ||
end | ||
end | ||
end |