diff --git a/.rubocop.yml b/.rubocop.yml index 15096124c0e..dc0fd5cceb2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/Gemfile b/Gemfile index 6d4182e56cc..c4ce6cb4795 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 6abc17fb503..43eac52d794 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/lib/rubocop/cop/discourse_cops.rb b/lib/rubocop/cop/discourse_cops.rb deleted file mode 100644 index 3acc3d71276..00000000000 --- a/lib/rubocop/cop/discourse_cops.rb +++ /dev/null @@ -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