Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance with RESTRICT_ON_SEND #7

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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