A platform for community discussion. Free, open, simple.
DEV: Use rubocop-discourse gem to add custom chdir cop
David Tayloreaf609689012
diff --git a/.rubocop.yml b/.rubocop.ymlindex 15096124c0e..dc0fd5cceb2 100644--- a/.rubocop.yml+++ b/.rubocop.yml@@ -1,3 +1,6 @@+require:+ - rubocop-discourse+AllCops:TargetRubyVersion: 2.4DisabledByDefault: 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 useddiff --git a/Gemfile b/Gemfileindex 6d4182e56cc..c4ce6cb4795 100644--- a/Gemfile+++ b/Gemfile@@ -143,6 +143,7 @@ group :test, :development dogem 'pry-nav'gem 'byebug', require: ENV['RM_INFO'].nil?gem 'rubocop', require: false+ gem "rubocop-discourse", require: falsegem 'parallel_tests'enddiff --git a/Gemfile.lock b/Gemfile.lockindex 6abc17fb503..43eac52d794 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -348,6 +348,8 @@ GEMrainbow (>= 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 @@ DEPENDENCIESrspec-rails (= 4.0.0.beta2)rtlitrubocop+ rubocop-discourseruby-profruby-readabilityrubyzipdiff --git a/lib/rubocop/cop/discourse_cops.rb b/lib/rubocop/cop/discourse_cops.rbdeleted file mode 100644index 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