rubocop-thread_safety 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +9 -0
- data/lib/rubocop-thread_safety.rb +6 -0
- data/lib/rubocop/cop/thread_safety/class_and_module_attributes.rb +23 -0
- data/lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb +44 -0
- data/lib/rubocop/thread_safety/version.rb +5 -0
- data/rubocop-thread_safety.gemspec +30 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b4eed435834382bb3694ea772ecd66ea9eaebbb
|
4
|
+
data.tar.gz: 430cc7dd678b3a0305d8cab1f8b2fd6ac910f286
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 630c1225098911d9e2f210ad95065d13f68430cd3957a1bcb58f37dd4bd7392574f2e63957af6b7861e0d217e95414775a2ef0ccb99c8b0e05896a65fbd50f08
|
7
|
+
data.tar.gz: 38c09a805700ae2fb7fdb21fa496149704905259200b10c35df8e1c724a3a15097c0a28df15951cacf7a5efbc71075f70ba17207fa27fed76c7799ee0c00e702
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# RuboCop::ThreadSafety
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/thread_safety`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rubocop-thread_safety'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rubocop-thread_safety
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/covermymeds/rubocop-thread_safety.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rubocop-thread_safety"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module ThreadSafety
|
7
|
+
class ClassAndModuleAttributes < Cop
|
8
|
+
MSG = 'Avoid class and module attributes.'.freeze
|
9
|
+
|
10
|
+
def_node_matcher :mattr?, <<-END
|
11
|
+
(send nil
|
12
|
+
{:mattr_writer :mattr_accessor :cattr_writer :cattr_accessor}
|
13
|
+
...)
|
14
|
+
END
|
15
|
+
|
16
|
+
def on_send(node)
|
17
|
+
return unless mattr?(node)
|
18
|
+
add_offense(node, :expression, format(MSG, node.source))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RuboCop
|
5
|
+
module Cop
|
6
|
+
module ThreadSafety
|
7
|
+
class InstanceVariableInClassMethod < Cop
|
8
|
+
MSG = 'Avoid instance variables in class methods.'.freeze
|
9
|
+
|
10
|
+
def on_ivar(node)
|
11
|
+
return unless in_defs?(node) || in_def_sclass?(node) || singleton_method_definition?(node)
|
12
|
+
|
13
|
+
add_offense(node, :name, MSG)
|
14
|
+
end
|
15
|
+
alias_method :on_ivasgn, :on_ivar
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def in_defs?(node)
|
20
|
+
node.ancestors.any? do |ancestor|
|
21
|
+
ancestor.type == :defs
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def in_def_sclass?(node)
|
26
|
+
defn = node.ancestors.find do |ancestor|
|
27
|
+
ancestor.type == :def
|
28
|
+
end
|
29
|
+
|
30
|
+
defn && defn.ancestors.any? do |ancestor|
|
31
|
+
ancestor.type == :sclass
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def singleton_method_definition?(node)
|
36
|
+
node.ancestors.any? do |ancestor|
|
37
|
+
next unless ancestor.children.first.is_a? Node
|
38
|
+
ancestor.children.first.command? :define_singleton_method
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubocop/thread_safety/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubocop-thread_safety"
|
8
|
+
spec.version = RuboCop::ThreadSafety::VERSION
|
9
|
+
spec.authors = ["Michael Gee"]
|
10
|
+
spec.email = ["michaelpgee@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Thread-safety checks via static analysis'
|
13
|
+
spec.description = <<-end_description
|
14
|
+
Thread-safety checks via static analysis.
|
15
|
+
A plugin for the RuboCop code style enforcing & linting tool.
|
16
|
+
end_description
|
17
|
+
spec.homepage = 'https://github.com/covermymeds/rubocop-thread_safety'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'rubocop'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-thread_safety
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Gee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: |2
|
84
|
+
Thread-safety checks via static analysis.
|
85
|
+
A plugin for the RuboCop code style enforcing & linting tool.
|
86
|
+
email:
|
87
|
+
- michaelpgee@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".gitmodules"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/rubocop-thread_safety.rb
|
102
|
+
- lib/rubocop/cop/thread_safety/class_and_module_attributes.rb
|
103
|
+
- lib/rubocop/cop/thread_safety/instance_variable_in_class_method.rb
|
104
|
+
- lib/rubocop/thread_safety/version.rb
|
105
|
+
- rubocop-thread_safety.gemspec
|
106
|
+
homepage: https://github.com/covermymeds/rubocop-thread_safety
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.8
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Thread-safety checks via static analysis
|
129
|
+
test_files: []
|
130
|
+
has_rdoc:
|