rubocop-thread_safety 0.4.4 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +30 -0
- data/LICENSE.txt +2 -1
- data/README.md +15 -8
- data/config/default.yml +19 -2
- data/config/obsoletion.yml +2 -0
- data/lib/rubocop/cop/mixin/operation_with_threadsafe_result.rb +44 -0
- data/lib/rubocop/cop/thread_safety/class_and_module_attributes.rb +18 -5
- data/lib/rubocop/cop/thread_safety/class_instance_variable.rb +259 -0
- data/lib/rubocop/cop/thread_safety/dir_chdir.rb +65 -0
- data/lib/rubocop/cop/thread_safety/mutable_class_instance_variable.rb +41 -60
- data/lib/rubocop/cop/thread_safety/new_thread.rb +6 -5
- data/lib/rubocop/cop/thread_safety/rack_middleware_instance_variable.rb +121 -0
- data/lib/rubocop/thread_safety/plugin.rb +38 -0
- data/lib/rubocop/thread_safety/version.rb +3 -1
- data/lib/rubocop/thread_safety.rb +0 -5
- data/lib/rubocop-thread_safety.rb +5 -3
- metadata +31 -94
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.rubocop.yml +0 -70
- data/.travis.yml +0 -64
- data/Appraisals +0 -23
- data/Gemfile +0 -6
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -6
- data/gemfiles/rubocop_0.53.gemfile +0 -7
- data/gemfiles/rubocop_0.81.gemfile +0 -7
- data/gemfiles/rubocop_0.86.gemfile +0 -7
- data/gemfiles/rubocop_1.20.gemfile +0 -7
- data/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb +0 -131
- data/lib/rubocop/thread_safety/inject.rb +0 -20
- data/rubocop-thread_safety.gemspec +0 -38
data/.rubocop.yml
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
DisplayCopNames: true
|
3
|
-
TargetRubyVersion: 2.3
|
4
|
-
|
5
|
-
Lint/RaiseException:
|
6
|
-
Enabled: true
|
7
|
-
|
8
|
-
Lint/StructNewOverride:
|
9
|
-
Enabled: true
|
10
|
-
|
11
|
-
Metrics/BlockLength:
|
12
|
-
Exclude:
|
13
|
-
- "spec/**/*"
|
14
|
-
|
15
|
-
Metrics/ClassLength:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
Metrics/MethodLength:
|
19
|
-
Max: 14
|
20
|
-
|
21
|
-
Naming/FileName:
|
22
|
-
Exclude:
|
23
|
-
- lib/rubocop-thread_safety.rb
|
24
|
-
- rubocop-thread_safety.gemspec
|
25
|
-
|
26
|
-
# Enable more cops that are disabled by default:
|
27
|
-
|
28
|
-
Style/AutoResourceCleanup:
|
29
|
-
Enabled: true
|
30
|
-
|
31
|
-
Style/CollectionMethods:
|
32
|
-
Enabled: true
|
33
|
-
|
34
|
-
Style/FrozenStringLiteralComment:
|
35
|
-
Exclude:
|
36
|
-
- "gemfiles/*.gemfile"
|
37
|
-
|
38
|
-
Style/HashEachMethods:
|
39
|
-
Enabled: true
|
40
|
-
|
41
|
-
Style/HashTransformKeys:
|
42
|
-
Enabled: false
|
43
|
-
|
44
|
-
Style/HashTransformValues:
|
45
|
-
Enabled: false
|
46
|
-
|
47
|
-
Style/MethodCalledOnDoEndBlock:
|
48
|
-
Enabled: true
|
49
|
-
Exclude:
|
50
|
-
- spec/**/*
|
51
|
-
|
52
|
-
Style/MissingElse:
|
53
|
-
Enabled: true
|
54
|
-
EnforcedStyle: case
|
55
|
-
|
56
|
-
Style/OptionHash:
|
57
|
-
Enabled: true
|
58
|
-
|
59
|
-
Style/Send:
|
60
|
-
Enabled: true
|
61
|
-
|
62
|
-
Style/StringLiterals:
|
63
|
-
Exclude:
|
64
|
-
- "gemfiles/*.gemfile"
|
65
|
-
|
66
|
-
Style/StringMethods:
|
67
|
-
Enabled: true
|
68
|
-
|
69
|
-
Style/SymbolArray:
|
70
|
-
Enabled: true
|
data/.travis.yml
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
cache: bundler
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- jruby-9.2.9.0
|
5
|
-
- 2.3.0
|
6
|
-
- 2.4
|
7
|
-
- 2.5
|
8
|
-
- 2.6
|
9
|
-
- 2.7
|
10
|
-
- 3.0
|
11
|
-
|
12
|
-
gemfile:
|
13
|
-
- gemfiles/rubocop_0.53.gemfile
|
14
|
-
- gemfiles/rubocop_0.81.gemfile
|
15
|
-
- gemfiles/rubocop_0.86.gemfile
|
16
|
-
- gemfiles/rubocop_1.20.gemfile
|
17
|
-
|
18
|
-
script_rubocop: &script_rubocop
|
19
|
-
- bundle exec rspec
|
20
|
-
- bundle exec rubocop
|
21
|
-
|
22
|
-
jobs:
|
23
|
-
fast_finish: true
|
24
|
-
exclude:
|
25
|
-
- rvm: 2.3.0
|
26
|
-
gemfile: gemfiles/rubocop_0.86.gemfile
|
27
|
-
- rvm: 2.3.0
|
28
|
-
gemfile: gemfiles/rubocop_1.20.gemfile
|
29
|
-
- rvm: 2.5
|
30
|
-
gemfile: gemfiles/rubocop_0.53.gemfile
|
31
|
-
- rvm: 2.6
|
32
|
-
gemfile: gemfiles/rubocop_0.53.gemfile
|
33
|
-
- rvm: 2.7
|
34
|
-
gemfile: gemfiles/rubocop_0.53.gemfile
|
35
|
-
- rvm: 3.0
|
36
|
-
gemfile: gemfiles/rubocop_0.53.gemfile
|
37
|
-
include:
|
38
|
-
- rvm: jruby-9.2.9.0
|
39
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
40
|
-
script: *script_rubocop
|
41
|
-
- rvm: 2.3.0
|
42
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
43
|
-
script: *script_rubocop
|
44
|
-
- rvm: 2.4
|
45
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
46
|
-
script: *script_rubocop
|
47
|
-
- rvm: 2.5
|
48
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
49
|
-
script: *script_rubocop
|
50
|
-
- rvm: 2.6
|
51
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
52
|
-
script: *script_rubocop
|
53
|
-
- rvm: 2.7
|
54
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
55
|
-
script: *script_rubocop
|
56
|
-
- rvm: 3.0
|
57
|
-
gemfile: gemfiles/rubocop_0.81.gemfile
|
58
|
-
script: *script_rubocop
|
59
|
-
|
60
|
-
before_install: gem install --remote bundler
|
61
|
-
install:
|
62
|
-
- bundle install --retry=3
|
63
|
-
script:
|
64
|
-
- bundle exec rspec
|
data/Appraisals
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
appraise 'rubocop-0.53' do
|
4
|
-
gem 'rubocop', '~> 0.53.0'
|
5
|
-
end
|
6
|
-
|
7
|
-
appraise 'rubocop-0.81' do
|
8
|
-
gem 'rubocop', '~> 0.81.0'
|
9
|
-
end
|
10
|
-
|
11
|
-
if Gem::Requirement.new('>= 2.4.0')
|
12
|
-
.satisfied_by?(Gem::Version.new(RUBY_VERSION))
|
13
|
-
appraise 'rubocop-0.86' do
|
14
|
-
gem 'rubocop', '~> 0.86.0'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
if Gem::Requirement.new('>= 2.5.0')
|
19
|
-
.satisfied_by?(Gem::Version.new(RUBY_VERSION))
|
20
|
-
appraise 'rubocop-1.20' do
|
21
|
-
gem 'rubocop', '~> 1.20.0'
|
22
|
-
end
|
23
|
-
end
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
|
-
require 'bundler/setup'
|
6
|
-
require 'rubocop-thread_safety'
|
7
|
-
|
8
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
-
# with your gem easier. You can also use a different console, if you like.
|
10
|
-
|
11
|
-
require 'pry'
|
12
|
-
Pry.start
|
13
|
-
|
14
|
-
# require "irb"
|
15
|
-
# IRB.start
|
data/bin/setup
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module ThreadSafety
|
6
|
-
# Avoid instance variables in class methods.
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# # bad
|
10
|
-
# class User
|
11
|
-
# def self.notify(info)
|
12
|
-
# @info = validate(info)
|
13
|
-
# Notifier.new(@info).deliver
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# class Model
|
18
|
-
# class << self
|
19
|
-
# def table_name(name)
|
20
|
-
# @table_name = name
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# class Host
|
26
|
-
# %i[uri port].each do |key|
|
27
|
-
# define_singleton_method("#{key}=") do |value|
|
28
|
-
# instance_variable_set("@#{key}", value)
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# module Example
|
34
|
-
# module ClassMethods
|
35
|
-
# def test(params)
|
36
|
-
# @params = params
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
class InstanceVariableInClassMethod < Cop
|
41
|
-
MSG = 'Avoid instance variables in class methods.'
|
42
|
-
|
43
|
-
def_node_matcher :instance_variable_set_call?, <<~MATCHER
|
44
|
-
(send nil? :instance_variable_set (...) (...))
|
45
|
-
MATCHER
|
46
|
-
|
47
|
-
def_node_matcher :instance_variable_get_call?, <<~MATCHER
|
48
|
-
(send nil? :instance_variable_get (...))
|
49
|
-
MATCHER
|
50
|
-
|
51
|
-
def on_ivar(node)
|
52
|
-
return unless class_method_definition?(node)
|
53
|
-
return if synchronized?(node)
|
54
|
-
|
55
|
-
add_offense(node, location: :name, message: MSG)
|
56
|
-
end
|
57
|
-
alias on_ivasgn on_ivar
|
58
|
-
|
59
|
-
def on_send(node)
|
60
|
-
return unless instance_variable_call?(node)
|
61
|
-
return unless class_method_definition?(node)
|
62
|
-
return if synchronized?(node)
|
63
|
-
|
64
|
-
add_offense(node, message: MSG)
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def class_method_definition?(node)
|
70
|
-
in_defs?(node) ||
|
71
|
-
in_def_sclass?(node) ||
|
72
|
-
in_def_class_methods?(node) ||
|
73
|
-
singleton_method_definition?(node)
|
74
|
-
end
|
75
|
-
|
76
|
-
def in_defs?(node)
|
77
|
-
node.ancestors.any? do |ancestor|
|
78
|
-
ancestor.type == :defs
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def in_def_sclass?(node)
|
83
|
-
defn = node.ancestors.find do |ancestor|
|
84
|
-
ancestor.type == :def
|
85
|
-
end
|
86
|
-
|
87
|
-
defn&.ancestors&.any? do |ancestor|
|
88
|
-
ancestor.type == :sclass
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def in_def_class_methods?(node)
|
93
|
-
defn = node.ancestors.find(&:def_type?)
|
94
|
-
return unless defn
|
95
|
-
|
96
|
-
mod = defn.ancestors.find do |ancestor|
|
97
|
-
%i[class module].include?(ancestor.type)
|
98
|
-
end
|
99
|
-
return unless mod
|
100
|
-
|
101
|
-
class_methods_module?(mod)
|
102
|
-
end
|
103
|
-
|
104
|
-
def singleton_method_definition?(node)
|
105
|
-
node.ancestors.any? do |ancestor|
|
106
|
-
next unless ancestor.children.first.is_a? AST::SendNode
|
107
|
-
|
108
|
-
ancestor.children.first.command? :define_singleton_method
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def synchronized?(node)
|
113
|
-
node.ancestors.find do |ancestor|
|
114
|
-
next unless ancestor.block_type?
|
115
|
-
|
116
|
-
s = ancestor.children.first
|
117
|
-
s.send_type? && s.children.last == :synchronize
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def instance_variable_call?(node)
|
122
|
-
instance_variable_set_call?(node) || instance_variable_get_call?(node)
|
123
|
-
end
|
124
|
-
|
125
|
-
def_node_matcher :class_methods_module?, <<~PATTERN
|
126
|
-
(module (const _ :ClassMethods) ...)
|
127
|
-
PATTERN
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
-
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT_LICENSE.md
|
5
|
-
module RuboCop
|
6
|
-
module ThreadSafety
|
7
|
-
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
-
# bit of our configuration.
|
9
|
-
module Inject
|
10
|
-
def self.defaults!
|
11
|
-
path = CONFIG_DEFAULT.to_s
|
12
|
-
hash = ConfigLoader.__send__(:load_yaml_configuration, path)
|
13
|
-
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
-
puts "configuration from \#{path}" if ConfigLoader.debug?
|
15
|
-
config = ConfigLoader.merge_with_default(config, path)
|
16
|
-
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'rubocop/thread_safety/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'rubocop-thread_safety'
|
9
|
-
spec.version = RuboCop::ThreadSafety::VERSION
|
10
|
-
spec.authors = ['Michael Gee']
|
11
|
-
spec.email = ['michaelpgee@gmail.com']
|
12
|
-
|
13
|
-
spec.summary = 'Thread-safety checks via static analysis'
|
14
|
-
spec.description = <<-DESCRIPTION
|
15
|
-
Thread-safety checks via static analysis.
|
16
|
-
A plugin for the RuboCop code style enforcing & linting tool.
|
17
|
-
DESCRIPTION
|
18
|
-
spec.homepage = 'https://github.com/covermymeds/rubocop-thread_safety'
|
19
|
-
spec.licenses = ['MIT']
|
20
|
-
|
21
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
-
f.match(%r{^(test|spec|features)/})
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.bindir = 'exe'
|
26
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
-
spec.require_paths = ['lib']
|
28
|
-
|
29
|
-
spec.required_ruby_version = '>= 2.3.0'
|
30
|
-
|
31
|
-
spec.add_runtime_dependency 'rubocop', '>= 0.53.0'
|
32
|
-
|
33
|
-
spec.add_development_dependency 'appraisal'
|
34
|
-
spec.add_development_dependency 'bundler', '>= 1.10', '< 3'
|
35
|
-
spec.add_development_dependency 'pry' unless ENV['CI']
|
36
|
-
spec.add_development_dependency 'rake', '>= 10.0'
|
37
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
-
end
|