spoom 1.5.4 → 1.6.0
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/lib/spoom/backtrace_filter/minitest.rb +2 -3
- data/lib/spoom/cli/deadcode.rb +1 -2
- data/lib/spoom/cli/helper.rb +36 -28
- data/lib/spoom/cli/srb/assertions.rb +48 -0
- data/lib/spoom/cli/srb/bump.rb +1 -2
- data/lib/spoom/cli/srb/sigs.rb +133 -18
- data/lib/spoom/cli/srb.rb +8 -4
- data/lib/spoom/cli.rb +1 -2
- data/lib/spoom/colors.rb +2 -6
- data/lib/spoom/context/bundle.rb +8 -9
- data/lib/spoom/context/exec.rb +2 -5
- data/lib/spoom/context/file_system.rb +12 -19
- data/lib/spoom/context/git.rb +14 -19
- data/lib/spoom/context/sorbet.rb +13 -26
- data/lib/spoom/context.rb +3 -7
- data/lib/spoom/coverage/d3/base.rb +6 -8
- data/lib/spoom/coverage/d3/circle_map.rb +6 -16
- data/lib/spoom/coverage/d3/pie.rb +14 -19
- data/lib/spoom/coverage/d3/timeline.rb +46 -47
- data/lib/spoom/coverage/d3.rb +2 -4
- data/lib/spoom/coverage/report.rb +38 -76
- data/lib/spoom/coverage/snapshot.rb +7 -13
- data/lib/spoom/coverage.rb +3 -5
- data/lib/spoom/deadcode/definition.rb +12 -14
- data/lib/spoom/deadcode/erb.rb +10 -8
- data/lib/spoom/deadcode/index.rb +19 -23
- data/lib/spoom/deadcode/indexer.rb +5 -6
- data/lib/spoom/deadcode/plugins/action_mailer.rb +2 -3
- data/lib/spoom/deadcode/plugins/action_mailer_preview.rb +2 -3
- data/lib/spoom/deadcode/plugins/actionpack.rb +4 -4
- data/lib/spoom/deadcode/plugins/active_model.rb +2 -3
- data/lib/spoom/deadcode/plugins/active_record.rb +2 -3
- data/lib/spoom/deadcode/plugins/active_support.rb +2 -1
- data/lib/spoom/deadcode/plugins/base.rb +29 -32
- data/lib/spoom/deadcode/plugins/graphql.rb +2 -3
- data/lib/spoom/deadcode/plugins/minitest.rb +4 -4
- data/lib/spoom/deadcode/plugins/namespaces.rb +5 -5
- data/lib/spoom/deadcode/plugins/rails.rb +5 -5
- data/lib/spoom/deadcode/plugins/rubocop.rb +4 -4
- data/lib/spoom/deadcode/plugins/ruby.rb +3 -4
- data/lib/spoom/deadcode/plugins/sorbet.rb +12 -6
- data/lib/spoom/deadcode/plugins/thor.rb +2 -3
- data/lib/spoom/deadcode/plugins.rb +2 -4
- data/lib/spoom/deadcode/remover.rb +37 -59
- data/lib/spoom/deadcode/send.rb +2 -8
- data/lib/spoom/file_collector.rb +10 -18
- data/lib/spoom/file_tree.rb +31 -46
- data/lib/spoom/location.rb +9 -20
- data/lib/spoom/model/builder.rb +60 -15
- data/lib/spoom/model/model.rb +65 -68
- data/lib/spoom/model/namespace_visitor.rb +3 -2
- data/lib/spoom/model/reference.rb +4 -8
- data/lib/spoom/model/references_visitor.rb +49 -29
- data/lib/spoom/parse.rb +17 -3
- data/lib/spoom/poset.rb +17 -19
- data/lib/spoom/printer.rb +10 -13
- data/lib/spoom/sorbet/assertions.rb +278 -0
- data/lib/spoom/sorbet/config.rb +8 -12
- data/lib/spoom/sorbet/errors.rb +16 -31
- data/lib/spoom/sorbet/lsp/base.rb +9 -15
- data/lib/spoom/sorbet/lsp/errors.rb +8 -16
- data/lib/spoom/sorbet/lsp/structures.rb +36 -59
- data/lib/spoom/sorbet/lsp.rb +15 -17
- data/lib/spoom/sorbet/metrics.rb +3 -5
- data/lib/spoom/sorbet/sigils.rb +7 -11
- data/lib/spoom/sorbet/sigs.rb +118 -25
- data/lib/spoom/sorbet.rb +3 -9
- data/lib/spoom/timeline.rb +4 -6
- data/lib/spoom/version.rb +1 -1
- data/lib/spoom/visitor.rb +298 -151
- data/lib/spoom.rb +0 -2
- data/rbi/spoom.rbi +3963 -0
- metadata +6 -3
data/lib/spoom/coverage.rb
CHANGED
@@ -10,9 +10,7 @@ require "date"
|
|
10
10
|
module Spoom
|
11
11
|
module Coverage
|
12
12
|
class << self
|
13
|
-
|
14
|
-
|
15
|
-
sig { params(context: Context, rbi: T::Boolean, sorbet_bin: T.nilable(String)).returns(Snapshot) }
|
13
|
+
#: (Context context, ?rbi: bool, ?sorbet_bin: String?) -> Snapshot
|
16
14
|
def snapshot(context, rbi: true, sorbet_bin: nil)
|
17
15
|
config = context.sorbet_config
|
18
16
|
config.allowed_extensions.push(".rb", ".rbi") if config.allowed_extensions.empty?
|
@@ -79,7 +77,7 @@ module Spoom
|
|
79
77
|
snapshot
|
80
78
|
end
|
81
79
|
|
82
|
-
|
80
|
+
#: (Context context, Array[Snapshot] snapshots, palette: D3::ColorPalette) -> Report
|
83
81
|
def report(context, snapshots, palette:)
|
84
82
|
intro_commit = context.sorbet_intro_commit
|
85
83
|
|
@@ -99,7 +97,7 @@ module Spoom
|
|
99
97
|
)
|
100
98
|
end
|
101
99
|
|
102
|
-
|
100
|
+
#: (Context context) -> FileTree
|
103
101
|
def file_tree(context)
|
104
102
|
config = context.sorbet_config
|
105
103
|
config.ignore += ["test"]
|
@@ -5,8 +5,6 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
# A definition is a class, module, method, constant, etc. being defined in the code
|
7
7
|
class Definition < T::Struct
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
class Kind < T::Enum
|
11
9
|
enums do
|
12
10
|
AttrReader = new("attr_reader")
|
@@ -37,66 +35,66 @@ module Spoom
|
|
37
35
|
|
38
36
|
# Kind
|
39
37
|
|
40
|
-
|
38
|
+
#: -> bool
|
41
39
|
def attr_reader?
|
42
40
|
kind == Kind::AttrReader
|
43
41
|
end
|
44
42
|
|
45
|
-
|
43
|
+
#: -> bool
|
46
44
|
def attr_writer?
|
47
45
|
kind == Kind::AttrWriter
|
48
46
|
end
|
49
47
|
|
50
|
-
|
48
|
+
#: -> bool
|
51
49
|
def class?
|
52
50
|
kind == Kind::Class
|
53
51
|
end
|
54
52
|
|
55
|
-
|
53
|
+
#: -> bool
|
56
54
|
def constant?
|
57
55
|
kind == Kind::Constant
|
58
56
|
end
|
59
57
|
|
60
|
-
|
58
|
+
#: -> bool
|
61
59
|
def method?
|
62
60
|
kind == Kind::Method
|
63
61
|
end
|
64
62
|
|
65
|
-
|
63
|
+
#: -> bool
|
66
64
|
def module?
|
67
65
|
kind == Kind::Module
|
68
66
|
end
|
69
67
|
|
70
68
|
# Status
|
71
69
|
|
72
|
-
|
70
|
+
#: -> bool
|
73
71
|
def alive?
|
74
72
|
status == Status::ALIVE
|
75
73
|
end
|
76
74
|
|
77
|
-
|
75
|
+
#: -> void
|
78
76
|
def alive!
|
79
77
|
@status = Status::ALIVE
|
80
78
|
end
|
81
79
|
|
82
|
-
|
80
|
+
#: -> bool
|
83
81
|
def dead?
|
84
82
|
status == Status::DEAD
|
85
83
|
end
|
86
84
|
|
87
|
-
|
85
|
+
#: -> bool
|
88
86
|
def ignored?
|
89
87
|
status == Status::IGNORED
|
90
88
|
end
|
91
89
|
|
92
|
-
|
90
|
+
#: -> void
|
93
91
|
def ignored!
|
94
92
|
@status = Status::IGNORED
|
95
93
|
end
|
96
94
|
|
97
95
|
# Utils
|
98
96
|
|
99
|
-
|
97
|
+
#: (*untyped args) -> String
|
100
98
|
def to_json(*args)
|
101
99
|
{
|
102
100
|
kind: kind,
|
data/lib/spoom/deadcode/erb.rb
CHANGED
@@ -27,9 +27,7 @@ module Spoom
|
|
27
27
|
module Deadcode
|
28
28
|
# Custom engine to handle ERB templates as used by Rails
|
29
29
|
class ERB < ::Erubi::Engine
|
30
|
-
|
31
|
-
|
32
|
-
sig { params(input: T.untyped, properties: T.untyped).void }
|
30
|
+
#: (untyped input, ?untyped properties) -> void
|
33
31
|
def initialize(input, properties = {})
|
34
32
|
@newline_pending = 0
|
35
33
|
|
@@ -44,7 +42,8 @@ module Spoom
|
|
44
42
|
|
45
43
|
private
|
46
44
|
|
47
|
-
|
45
|
+
# @override
|
46
|
+
#: (untyped text) -> void
|
48
47
|
def add_text(text)
|
49
48
|
return if text.empty?
|
50
49
|
|
@@ -62,7 +61,8 @@ module Spoom
|
|
62
61
|
|
63
62
|
BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
|
64
63
|
|
65
|
-
|
64
|
+
# @override
|
65
|
+
#: (untyped indicator, untyped code) -> void
|
66
66
|
def add_expression(indicator, code)
|
67
67
|
flush_newline_if_pending(src)
|
68
68
|
|
@@ -79,19 +79,21 @@ module Spoom
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
# @override
|
83
|
+
#: (untyped code) -> void
|
83
84
|
def add_code(code)
|
84
85
|
flush_newline_if_pending(src)
|
85
86
|
super
|
86
87
|
end
|
87
88
|
|
88
|
-
|
89
|
+
# @override
|
90
|
+
#: (untyped _) -> void
|
89
91
|
def add_postamble(_)
|
90
92
|
flush_newline_if_pending(src)
|
91
93
|
super
|
92
94
|
end
|
93
95
|
|
94
|
-
|
96
|
+
#: (untyped src) -> void
|
95
97
|
def flush_newline_if_pending(src)
|
96
98
|
if @newline_pending > 0
|
97
99
|
src << bufvar << ".safe_append='#{"\n" * @newline_pending}'.freeze;"
|
data/lib/spoom/deadcode/index.rb
CHANGED
@@ -4,28 +4,24 @@
|
|
4
4
|
module Spoom
|
5
5
|
module Deadcode
|
6
6
|
class Index
|
7
|
-
extend T::Sig
|
8
|
-
|
9
7
|
class Error < Spoom::Error
|
10
|
-
|
11
|
-
|
12
|
-
sig { params(message: String, parent: Exception).void }
|
8
|
+
#: (String message, parent: Exception) -> void
|
13
9
|
def initialize(message, parent:)
|
14
10
|
super(message)
|
15
11
|
set_backtrace(parent.backtrace)
|
16
12
|
end
|
17
13
|
end
|
18
14
|
|
19
|
-
|
15
|
+
#: Model
|
20
16
|
attr_reader :model
|
21
17
|
|
22
|
-
|
18
|
+
#: Hash[String, Array[Definition]]
|
23
19
|
attr_reader :definitions
|
24
20
|
|
25
|
-
|
21
|
+
#: Hash[String, Array[Model::Reference]]
|
26
22
|
attr_reader :references
|
27
23
|
|
28
|
-
|
24
|
+
#: (Model model) -> void
|
29
25
|
def initialize(model)
|
30
26
|
@model = model
|
31
27
|
@definitions = T.let({}, T::Hash[String, T::Array[Definition]])
|
@@ -35,7 +31,7 @@ module Spoom
|
|
35
31
|
|
36
32
|
# Indexing
|
37
33
|
|
38
|
-
|
34
|
+
#: (String file, ?plugins: Array[Plugins::Base]) -> void
|
39
35
|
def index_file(file, plugins: [])
|
40
36
|
if file.end_with?(".erb")
|
41
37
|
erb = File.read(file)
|
@@ -46,17 +42,17 @@ module Spoom
|
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
49
|
-
|
45
|
+
#: (String erb, file: String, ?plugins: Array[Plugins::Base]) -> void
|
50
46
|
def index_erb(erb, file:, plugins: [])
|
51
47
|
index_ruby(Deadcode::ERB.new(erb).src, file: file, plugins: plugins)
|
52
48
|
end
|
53
49
|
|
54
|
-
|
50
|
+
#: (String rb, file: String, ?plugins: Array[Plugins::Base]) -> void
|
55
51
|
def index_ruby(rb, file:, plugins: [])
|
56
|
-
node = Spoom.
|
52
|
+
node, comments = Spoom.parse_ruby_with_comments(rb, file: file)
|
57
53
|
|
58
54
|
# Index definitions
|
59
|
-
model_builder = Model::Builder.new(@model, file)
|
55
|
+
model_builder = Model::Builder.new(@model, file, comments: comments)
|
60
56
|
model_builder.visit(node)
|
61
57
|
|
62
58
|
# Index references
|
@@ -75,27 +71,27 @@ module Spoom
|
|
75
71
|
raise Error.new("Error while indexing #{file} (#{e.message})", parent: e)
|
76
72
|
end
|
77
73
|
|
78
|
-
|
74
|
+
#: (Definition definition) -> void
|
79
75
|
def define(definition)
|
80
76
|
(@definitions[definition.name] ||= []) << definition
|
81
77
|
end
|
82
78
|
|
83
|
-
|
79
|
+
#: (String name, Location location) -> void
|
84
80
|
def reference_constant(name, location)
|
85
81
|
(@references[name] ||= []) << Model::Reference.constant(name, location)
|
86
82
|
end
|
87
83
|
|
88
|
-
|
84
|
+
#: (String name, Location location) -> void
|
89
85
|
def reference_method(name, location)
|
90
86
|
(@references[name] ||= []) << Model::Reference.method(name, location)
|
91
87
|
end
|
92
88
|
|
93
|
-
|
89
|
+
#: (Model::SymbolDef symbol_def) -> void
|
94
90
|
def ignore(symbol_def)
|
95
91
|
@ignored << symbol_def
|
96
92
|
end
|
97
93
|
|
98
|
-
|
94
|
+
#: (Array[Plugins::Base] plugins) -> void
|
99
95
|
def apply_plugins!(plugins)
|
100
96
|
@model.symbols.each do |_full_name, symbol|
|
101
97
|
symbol.definitions.each do |symbol_def|
|
@@ -118,7 +114,7 @@ module Spoom
|
|
118
114
|
# Mark all definitions having a reference of the same name as `alive`
|
119
115
|
#
|
120
116
|
# To be called once all the files have been indexed and all the definitions and references discovered.
|
121
|
-
|
117
|
+
#: -> void
|
122
118
|
def finalize!
|
123
119
|
@model.symbols.each do |_full_name, symbol|
|
124
120
|
symbol.definitions.each do |symbol_def|
|
@@ -210,17 +206,17 @@ module Spoom
|
|
210
206
|
|
211
207
|
# Utils
|
212
208
|
|
213
|
-
|
209
|
+
#: (String name) -> Array[Definition]
|
214
210
|
def definitions_for_name(name)
|
215
211
|
@definitions[name] || []
|
216
212
|
end
|
217
213
|
|
218
|
-
|
214
|
+
#: -> Array[Definition]
|
219
215
|
def all_definitions
|
220
216
|
@definitions.values.flatten
|
221
217
|
end
|
222
218
|
|
223
|
-
|
219
|
+
#: -> Array[Model::Reference]
|
224
220
|
def all_references
|
225
221
|
@references.values.flatten
|
226
222
|
end
|
@@ -4,15 +4,13 @@
|
|
4
4
|
module Spoom
|
5
5
|
module Deadcode
|
6
6
|
class Indexer < Visitor
|
7
|
-
|
8
|
-
|
9
|
-
sig { returns(String) }
|
7
|
+
#: String
|
10
8
|
attr_reader :path
|
11
9
|
|
12
|
-
|
10
|
+
#: Index
|
13
11
|
attr_reader :index
|
14
12
|
|
15
|
-
|
13
|
+
#: (String path, Index index, ?plugins: Array[Plugins::Base]) -> void
|
16
14
|
def initialize(path, index, plugins: [])
|
17
15
|
super()
|
18
16
|
|
@@ -23,7 +21,8 @@ module Spoom
|
|
23
21
|
|
24
22
|
# Visit
|
25
23
|
|
26
|
-
|
24
|
+
# @override
|
25
|
+
#: (Prism::CallNode node) -> void
|
27
26
|
def visit_call_node(node)
|
28
27
|
visit(node.receiver)
|
29
28
|
|
@@ -5,9 +5,8 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class ActionMailer < Base
|
8
|
-
|
9
|
-
|
10
|
-
sig { override.params(send: Send).void }
|
8
|
+
# @override
|
9
|
+
#: (Send send) -> void
|
11
10
|
def on_send(send)
|
12
11
|
return unless send.recv.nil? && ActionPack::CALLBACKS.include?(send.name)
|
13
12
|
|
@@ -5,11 +5,10 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class ActionMailerPreview < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_classes_inheriting_from("ActionMailer::Preview")
|
11
9
|
|
12
|
-
|
10
|
+
# @override
|
11
|
+
#: (Model::Method definition) -> void
|
13
12
|
def on_define_method(definition)
|
14
13
|
owner = definition.owner
|
15
14
|
return unless owner.is_a?(Model::Class)
|
@@ -5,8 +5,6 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class ActionPack < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_classes_inheriting_from("ApplicationController")
|
11
9
|
|
12
10
|
CALLBACKS = T.let(
|
@@ -27,7 +25,8 @@ module Spoom
|
|
27
25
|
T::Array[String],
|
28
26
|
)
|
29
27
|
|
30
|
-
|
28
|
+
# @override
|
29
|
+
#: (Model::Method definition) -> void
|
31
30
|
def on_define_method(definition)
|
32
31
|
owner = definition.owner
|
33
32
|
return unless owner.is_a?(Model::Class)
|
@@ -35,7 +34,8 @@ module Spoom
|
|
35
34
|
@index.ignore(definition) if ignored_subclass?(owner)
|
36
35
|
end
|
37
36
|
|
38
|
-
|
37
|
+
# @override
|
38
|
+
#: (Send send) -> void
|
39
39
|
def on_send(send)
|
40
40
|
return unless send.recv.nil? && CALLBACKS.include?(send.name)
|
41
41
|
|
@@ -5,12 +5,11 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class ActiveModel < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_classes_inheriting_from("ActiveModel::EachValidator")
|
11
9
|
ignore_methods_named("validate_each", "persisted?")
|
12
10
|
|
13
|
-
|
11
|
+
# @override
|
12
|
+
#: (Send send) -> void
|
14
13
|
def on_send(send)
|
15
14
|
return if send.recv
|
16
15
|
|
@@ -5,8 +5,6 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class ActiveRecord < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_classes_inheriting_from(/^(::)?ActiveRecord::Migration/)
|
11
9
|
|
12
10
|
ignore_methods_named(
|
@@ -70,7 +68,8 @@ module Spoom
|
|
70
68
|
T::Array[String],
|
71
69
|
)
|
72
70
|
|
73
|
-
|
71
|
+
# @override
|
72
|
+
#: (Send send) -> void
|
74
73
|
def on_send(send)
|
75
74
|
if send.recv.nil? && CALLBACKS.include?(send.name)
|
76
75
|
send.each_arg(Prism::SymbolNode) do |arg|
|
@@ -18,7 +18,8 @@ module Spoom
|
|
18
18
|
|
19
19
|
SETUP_AND_TEARDOWN_METHODS = T.let(["setup", "teardown"], T::Array[String])
|
20
20
|
|
21
|
-
|
21
|
+
# @override
|
22
|
+
#: (Send send) -> void
|
22
23
|
def on_send(send)
|
23
24
|
return unless send.recv.nil? && SETUP_AND_TEARDOWN_METHODS.include?(send.name)
|
24
25
|
|
@@ -7,14 +7,11 @@ module Spoom
|
|
7
7
|
module Deadcode
|
8
8
|
module Plugins
|
9
9
|
class Base
|
10
|
-
extend T::Sig
|
11
10
|
extend T::Helpers
|
12
11
|
|
13
12
|
abstract!
|
14
13
|
|
15
14
|
class << self
|
16
|
-
extend T::Sig
|
17
|
-
|
18
15
|
# Plugins DSL
|
19
16
|
|
20
17
|
# Mark classes matching `names` as ignored.
|
@@ -30,7 +27,7 @@ module Spoom
|
|
30
27
|
# )
|
31
28
|
# end
|
32
29
|
# ~~~
|
33
|
-
|
30
|
+
#: (*(String | Regexp) names) -> void
|
34
31
|
def ignore_classes_named(*names)
|
35
32
|
save_names_and_patterns(names, :@ignored_class_names, :@ignored_class_patterns)
|
36
33
|
end
|
@@ -48,7 +45,7 @@ module Spoom
|
|
48
45
|
# )
|
49
46
|
# end
|
50
47
|
# ~~~
|
51
|
-
|
48
|
+
#: (*(String | Regexp) names) -> void
|
52
49
|
def ignore_classes_inheriting_from(*names)
|
53
50
|
save_names_and_patterns(names, :@ignored_subclasses_of_names, :@ignored_subclasses_of_patterns)
|
54
51
|
end
|
@@ -66,7 +63,7 @@ module Spoom
|
|
66
63
|
# )
|
67
64
|
# end
|
68
65
|
# ~~~
|
69
|
-
|
66
|
+
#: (*(String | Regexp) names) -> void
|
70
67
|
def ignore_constants_named(*names)
|
71
68
|
save_names_and_patterns(names, :@ignored_constant_names, :@ignored_constant_patterns)
|
72
69
|
end
|
@@ -84,7 +81,7 @@ module Spoom
|
|
84
81
|
# )
|
85
82
|
# end
|
86
83
|
# ~~~
|
87
|
-
|
84
|
+
#: (*(String | Regexp) names) -> void
|
88
85
|
def ignore_methods_named(*names)
|
89
86
|
save_names_and_patterns(names, :@ignored_method_names, :@ignored_method_patterns)
|
90
87
|
end
|
@@ -102,14 +99,14 @@ module Spoom
|
|
102
99
|
# )
|
103
100
|
# end
|
104
101
|
# ~~~
|
105
|
-
|
102
|
+
#: (*(String | Regexp) names) -> void
|
106
103
|
def ignore_modules_named(*names)
|
107
104
|
save_names_and_patterns(names, :@ignored_module_names, :@ignored_module_patterns)
|
108
105
|
end
|
109
106
|
|
110
107
|
private
|
111
108
|
|
112
|
-
|
109
|
+
#: (Array[(String | Regexp)] names, Symbol names_variable, Symbol patterns_variable) -> void
|
113
110
|
def save_names_and_patterns(names, names_variable, patterns_variable)
|
114
111
|
ignored_names = instance_variable_set(names_variable, Set.new)
|
115
112
|
ignored_patterns = instance_variable_set(patterns_variable, [])
|
@@ -125,10 +122,10 @@ module Spoom
|
|
125
122
|
end
|
126
123
|
end
|
127
124
|
|
128
|
-
|
125
|
+
#: Index
|
129
126
|
attr_reader :index
|
130
127
|
|
131
|
-
|
128
|
+
#: (Index index) -> void
|
132
129
|
def initialize(index)
|
133
130
|
@index = index
|
134
131
|
end
|
@@ -148,13 +145,13 @@ module Spoom
|
|
148
145
|
# end
|
149
146
|
# end
|
150
147
|
# ~~~
|
151
|
-
|
148
|
+
#: (Model::Attr definition) -> void
|
152
149
|
def on_define_accessor(definition)
|
153
150
|
# no-op
|
154
151
|
end
|
155
152
|
|
156
153
|
# Do not override this method, use `on_define_accessor` instead.
|
157
|
-
|
154
|
+
#: (Model::Attr definition) -> void
|
158
155
|
def internal_on_define_accessor(definition)
|
159
156
|
on_define_accessor(definition)
|
160
157
|
end
|
@@ -172,13 +169,13 @@ module Spoom
|
|
172
169
|
# end
|
173
170
|
# end
|
174
171
|
# ~~~
|
175
|
-
|
172
|
+
#: (Model::Class definition) -> void
|
176
173
|
def on_define_class(definition)
|
177
174
|
# no-op
|
178
175
|
end
|
179
176
|
|
180
177
|
# Do not override this method, use `on_define_class` instead.
|
181
|
-
|
178
|
+
#: (Model::Class definition) -> void
|
182
179
|
def internal_on_define_class(definition)
|
183
180
|
if ignored_class_name?(definition.name)
|
184
181
|
@index.ignore(definition)
|
@@ -202,13 +199,13 @@ module Spoom
|
|
202
199
|
# end
|
203
200
|
# end
|
204
201
|
# ~~~
|
205
|
-
|
202
|
+
#: (Model::Constant definition) -> void
|
206
203
|
def on_define_constant(definition)
|
207
204
|
# no-op
|
208
205
|
end
|
209
206
|
|
210
207
|
# Do not override this method, use `on_define_constant` instead.
|
211
|
-
|
208
|
+
#: (Model::Constant definition) -> void
|
212
209
|
def internal_on_define_constant(definition)
|
213
210
|
@index.ignore(definition) if ignored_constant_name?(definition.name)
|
214
211
|
|
@@ -228,13 +225,13 @@ module Spoom
|
|
228
225
|
# end
|
229
226
|
# end
|
230
227
|
# ~~~
|
231
|
-
|
228
|
+
#: (Model::Method definition) -> void
|
232
229
|
def on_define_method(definition)
|
233
230
|
# no-op
|
234
231
|
end
|
235
232
|
|
236
233
|
# Do not override this method, use `on_define_method` instead.
|
237
|
-
|
234
|
+
#: (Model::Method definition) -> void
|
238
235
|
def internal_on_define_method(definition)
|
239
236
|
@index.ignore(definition) if ignored_method_name?(definition.name)
|
240
237
|
|
@@ -254,13 +251,13 @@ module Spoom
|
|
254
251
|
# end
|
255
252
|
# end
|
256
253
|
# ~~~
|
257
|
-
|
254
|
+
#: (Model::Module definition) -> void
|
258
255
|
def on_define_module(definition)
|
259
256
|
# no-op
|
260
257
|
end
|
261
258
|
|
262
259
|
# Do not override this method, use `on_define_module` instead.
|
263
|
-
|
260
|
+
#: (Model::Module definition) -> void
|
264
261
|
def internal_on_define_module(definition)
|
265
262
|
@index.ignore(definition) if ignored_module_name?(definition.name)
|
266
263
|
|
@@ -280,7 +277,7 @@ module Spoom
|
|
280
277
|
# end
|
281
278
|
# end
|
282
279
|
# ~~~
|
283
|
-
|
280
|
+
#: (Send send) -> void
|
284
281
|
def on_send(send)
|
285
282
|
# no-op
|
286
283
|
end
|
@@ -289,7 +286,7 @@ module Spoom
|
|
289
286
|
|
290
287
|
# DSL support
|
291
288
|
|
292
|
-
|
289
|
+
#: (Model::Namespace definition, String superclass_name) -> bool
|
293
290
|
def subclass_of?(definition, superclass_name)
|
294
291
|
superclass_symbol = @index.model.symbols[superclass_name]
|
295
292
|
return false unless superclass_symbol
|
@@ -297,14 +294,14 @@ module Spoom
|
|
297
294
|
@index.model.symbols_hierarchy.edge?(definition.symbol, superclass_symbol)
|
298
295
|
end
|
299
296
|
|
300
|
-
|
297
|
+
#: (String? name) -> bool
|
301
298
|
def ignored_class_name?(name)
|
302
299
|
return false unless name
|
303
300
|
|
304
301
|
ignored_name?(name, :@ignored_class_names, :@ignored_class_patterns)
|
305
302
|
end
|
306
303
|
|
307
|
-
|
304
|
+
#: (Model::Class definition) -> bool
|
308
305
|
def ignored_subclass?(definition)
|
309
306
|
superclass_name = definition.superclass_name
|
310
307
|
return true if superclass_name && ignored_name?(
|
@@ -316,39 +313,39 @@ module Spoom
|
|
316
313
|
names(:@ignored_subclasses_of_names).any? { |superclass_name| subclass_of?(definition, superclass_name) }
|
317
314
|
end
|
318
315
|
|
319
|
-
|
316
|
+
#: (String name) -> bool
|
320
317
|
def ignored_constant_name?(name)
|
321
318
|
ignored_name?(name, :@ignored_constant_names, :@ignored_constant_patterns)
|
322
319
|
end
|
323
320
|
|
324
|
-
|
321
|
+
#: (String name) -> bool
|
325
322
|
def ignored_method_name?(name)
|
326
323
|
ignored_name?(name, :@ignored_method_names, :@ignored_method_patterns)
|
327
324
|
end
|
328
325
|
|
329
|
-
|
326
|
+
#: (String name) -> bool
|
330
327
|
def ignored_module_name?(name)
|
331
328
|
ignored_name?(name, :@ignored_module_names, :@ignored_module_patterns)
|
332
329
|
end
|
333
330
|
|
334
|
-
|
331
|
+
#: (String name, Symbol names_variable, Symbol patterns_variable) -> bool
|
335
332
|
def ignored_name?(name, names_variable, patterns_variable)
|
336
333
|
names(names_variable).include?(name) || patterns(patterns_variable).any? { |pattern| pattern.match?(name) }
|
337
334
|
end
|
338
335
|
|
339
|
-
|
336
|
+
#: (Symbol const) -> Set[String]
|
340
337
|
def names(const)
|
341
338
|
self.class.instance_variable_get(const) || Set.new
|
342
339
|
end
|
343
340
|
|
344
|
-
|
341
|
+
#: (Symbol const) -> Array[Regexp]
|
345
342
|
def patterns(const)
|
346
343
|
self.class.instance_variable_get(const) || []
|
347
344
|
end
|
348
345
|
|
349
346
|
# Plugin utils
|
350
347
|
|
351
|
-
|
348
|
+
#: (String name) -> String
|
352
349
|
def camelize(name)
|
353
350
|
name = T.must(name.split("::").last)
|
354
351
|
name = T.must(name.split("/").last)
|