mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 06:53:45 +08:00
DEV: Use rubocop-discourse gem to add custom chdir cop
Followup to b27e009655
This commit is contained in:
parent
6f9afde9a8
commit
eaf6096890
|
@ -1,3 +1,6 @@
|
|||
require:
|
||||
- rubocop-discourse
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.4
|
||||
DisabledByDefault: true
|
||||
|
@ -128,3 +131,8 @@ Style/Semicolon:
|
|||
|
||||
Style/RedundantReturn:
|
||||
Enabled: true
|
||||
|
||||
DiscourseCops/NoChdir:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
- 'spec/**/*' # Specs are run sequentially, so chdir can be used
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -143,6 +143,7 @@ group :test, :development do
|
|||
gem 'pry-nav'
|
||||
gem 'byebug', require: ENV['RM_INFO'].nil?
|
||||
gem 'rubocop', require: false
|
||||
gem "rubocop-discourse", require: false
|
||||
gem 'parallel_tests'
|
||||
end
|
||||
|
||||
|
|
|
@ -348,6 +348,8 @@ GEM
|
|||
rainbow (>= 2.2.2, < 4.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 1.4.0, < 1.7)
|
||||
rubocop-discourse (1.0.1)
|
||||
rubocop (>= 0.69.0)
|
||||
ruby-openid (2.7.0)
|
||||
ruby-prof (0.17.0)
|
||||
ruby-progressbar (1.10.0)
|
||||
|
@ -524,6 +526,7 @@ DEPENDENCIES
|
|||
rspec-rails (= 4.0.0.beta2)
|
||||
rtlit
|
||||
rubocop
|
||||
rubocop-discourse
|
||||
ruby-prof
|
||||
ruby-readability
|
||||
rubyzip
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module DiscourseCops
|
||||
# Avoid using chdir - it is not thread safe.
|
||||
#
|
||||
# Instead, you may be able to use:
|
||||
# Discourse::Utils.execute_command(chdir: 'test') do |runner|
|
||||
# runner.exec('pwd')
|
||||
# end
|
||||
#
|
||||
# @example
|
||||
# # bad
|
||||
# Dir.chdir('test')
|
||||
class NoChdir < Cop
|
||||
MSG = 'Chdir is not thread safe.'
|
||||
|
||||
def_node_matcher :using_dir_chdir?, <<-MATCHER
|
||||
(send (const nil? :Dir) :chdir ...)
|
||||
MATCHER
|
||||
|
||||
def_node_matcher :using_fileutils_cd?, <<-MATCHER
|
||||
(send (const nil? :FileUtils) :cd ...)
|
||||
MATCHER
|
||||
|
||||
def on_send(node)
|
||||
return if !(using_dir_chdir?(node) || using_fileutils_cd?(node))
|
||||
add_offense(node, message: MSG)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user