Skip to content

Commit

Permalink
Merge pull request rubocop#7 from rubocop/restrict-on-send
Browse files Browse the repository at this point in the history
Improve performance with RESTRICT_ON_SEND
  • Loading branch information
mikegee committed May 18, 2022
2 parents 0a25f3c + aede46c commit 79d2dcf
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1", ruby-head, jruby-9.2, jruby-9.3]
rubocop_version: ["0.86", "1.20"]
rubocop_version: ["0.90", "1.20"]
env:
BUNDLE_GEMFILE: "gemfiles/rubocop_${{ matrix.rubocop_version }}.gemfile"
steps:
Expand Down
4 changes: 2 additions & 2 deletions Appraisals
@@ -1,7 +1,7 @@
# frozen_string_literal: true

appraise 'rubocop-0.86' do
gem 'rubocop', '~> 0.86.0'
appraise 'rubocop-0.90' do
gem 'rubocop', '~> 0.90.0'
end

appraise 'rubocop-1.20' do
Expand Down
Expand Up @@ -2,6 +2,6 @@

source "https://rubygems.org"

gem "rubocop", "~> 0.86.0"
gem "rubocop", "~> 0.90.0"

gemspec path: "../"
6 changes: 6 additions & 0 deletions lib/rubocop/cop/thread_safety/class_and_module_attributes.rb
Expand Up @@ -14,6 +14,12 @@ module ThreadSafety
# end
class ClassAndModuleAttributes < Cop
MSG = 'Avoid mutating class and module attributes.'
RESTRICT_ON_SEND = %i[
mattr_writer mattr_accessor cattr_writer cattr_accessor
class_attribute
attr attr_accessor attr_writer
attr_internal attr_internal_accessor attr_internal_writer
].freeze

def_node_matcher :mattr?, <<~MATCHER
(send nil?
Expand Down
Expand Up @@ -55,6 +55,10 @@ module ThreadSafety
# end
class InstanceVariableInClassMethod < Cop
MSG = 'Avoid instance variables in class methods.'
RESTRICT_ON_SEND = %i[
instance_variable_set
instance_variable_get
].freeze

def_node_matcher :instance_variable_set_call?, <<~MATCHER
(send nil? :instance_variable_set (...) (...))
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/thread_safety/new_thread.rb
Expand Up @@ -12,6 +12,7 @@ module ThreadSafety
# Thread.new { do_work }
class NewThread < Cop
MSG = 'Avoid starting new threads.'
RESTRICT_ON_SEND = %i[new].freeze

def_node_matcher :new_thread?, <<~MATCHER
(send (const {nil? cbase} :Thread) :new)
Expand Down
2 changes: 1 addition & 1 deletion rubocop-thread_safety.gemspec
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.5.0'

spec.add_runtime_dependency 'rubocop', '>= 0.53.0'
spec.add_runtime_dependency 'rubocop', '>= 0.90.0'

spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'bundler', '>= 1.10', '< 3'
Expand Down
Expand Up @@ -4,11 +4,6 @@
:config do
subject(:cop) { described_class.new(config) }
let(:msg) { 'Freeze mutable objects assigned to class instance variables.' }
if Gem::Requirement.new('< 0.69')
.satisfied_by?(Gem::Version.new(RuboCop::Version::STRING))
let(:ruby_version) { 2.3 }
end

let(:prefix) { nil }
let(:suffix) { nil }
let(:indent) { '' }
Expand Down

0 comments on commit 79d2dcf

Please sign in to comment.