spoom 1.5.0 → 1.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/README.md +14 -0
- data/lib/spoom/backtrace_filter/minitest.rb +3 -4
- data/lib/spoom/cli/deadcode.rb +1 -2
- data/lib/spoom/cli/helper.rb +41 -31
- data/lib/spoom/cli/srb/assertions.rb +48 -0
- data/lib/spoom/cli/srb/bump.rb +1 -2
- data/lib/spoom/cli/srb/coverage.rb +1 -1
- data/lib/spoom/cli/srb/metrics.rb +68 -0
- data/lib/spoom/cli/srb/sigs.rb +209 -0
- data/lib/spoom/cli/srb/tc.rb +16 -1
- data/lib/spoom/cli/srb.rb +16 -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 +3 -6
- data/lib/spoom/context/file_system.rb +12 -19
- data/lib/spoom/context/git.rb +14 -19
- data/lib/spoom/context/sorbet.rb +14 -27
- data/lib/spoom/context.rb +4 -8
- data/lib/spoom/counters.rb +22 -0
- 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 +41 -79
- data/lib/spoom/coverage/snapshot.rb +8 -14
- 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 +21 -25
- 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 +19 -22
- data/lib/spoom/deadcode/plugins/active_model.rb +2 -3
- data/lib/spoom/deadcode/plugins/active_record.rb +62 -53
- data/lib/spoom/deadcode/plugins/active_support.rb +3 -2
- 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 +5 -5
- 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 +23 -31
- data/lib/spoom/deadcode/remover.rb +58 -79
- data/lib/spoom/deadcode/send.rb +2 -8
- data/lib/spoom/file_collector.rb +11 -19
- data/lib/spoom/file_tree.rb +36 -51
- data/lib/spoom/location.rb +9 -20
- data/lib/spoom/model/builder.rb +54 -17
- data/lib/spoom/model/model.rb +71 -74
- data/lib/spoom/model/namespace_visitor.rb +4 -3
- data/lib/spoom/model/reference.rb +4 -8
- data/lib/spoom/model/references_visitor.rb +50 -30
- data/lib/spoom/parse.rb +4 -4
- data/lib/spoom/poset.rb +22 -24
- data/lib/spoom/printer.rb +10 -13
- data/lib/spoom/rbs.rb +77 -0
- data/lib/spoom/sorbet/config.rb +17 -24
- data/lib/spoom/sorbet/errors.rb +87 -45
- data/lib/spoom/sorbet/lsp/base.rb +10 -16
- data/lib/spoom/sorbet/lsp/errors.rb +8 -16
- data/lib/spoom/sorbet/lsp/structures.rb +65 -91
- data/lib/spoom/sorbet/lsp.rb +20 -22
- data/lib/spoom/sorbet/metrics/code_metrics_visitor.rb +236 -0
- data/lib/spoom/sorbet/metrics/metrics_file_parser.rb +34 -0
- data/lib/spoom/sorbet/metrics.rb +2 -32
- data/lib/spoom/sorbet/sigils.rb +16 -23
- data/lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb +242 -0
- data/lib/spoom/sorbet/translate/sorbet_assertions_to_rbs_comments.rb +123 -0
- data/lib/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments.rb +293 -0
- data/lib/spoom/sorbet/translate/strip_sorbet_sigs.rb +23 -0
- data/lib/spoom/sorbet/translate/translator.rb +71 -0
- data/lib/spoom/sorbet/translate.rb +49 -0
- data/lib/spoom/sorbet.rb +6 -12
- data/lib/spoom/source/rewriter.rb +167 -0
- data/lib/spoom/source.rb +4 -0
- 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 +4 -3
- data/rbi/spoom.rbi +3567 -0
- metadata +62 -8
@@ -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,29 +5,25 @@ 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
|
-
CALLBACKS =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
)
|
29
|
-
|
30
|
-
sig { override.params(definition: Model::Method).void }
|
10
|
+
CALLBACKS = [
|
11
|
+
"after_action",
|
12
|
+
"append_after_action",
|
13
|
+
"append_around_action",
|
14
|
+
"append_before_action",
|
15
|
+
"around_action",
|
16
|
+
"before_action",
|
17
|
+
"prepend_after_action",
|
18
|
+
"prepend_around_action",
|
19
|
+
"prepend_before_action",
|
20
|
+
"skip_after_action",
|
21
|
+
"skip_around_action",
|
22
|
+
"skip_before_action",
|
23
|
+
].freeze #: Array[String]
|
24
|
+
|
25
|
+
# @override
|
26
|
+
#: (Model::Method definition) -> void
|
31
27
|
def on_define_method(definition)
|
32
28
|
owner = definition.owner
|
33
29
|
return unless owner.is_a?(Model::Class)
|
@@ -35,7 +31,8 @@ module Spoom
|
|
35
31
|
@index.ignore(definition) if ignored_subclass?(owner)
|
36
32
|
end
|
37
33
|
|
38
|
-
|
34
|
+
# @override
|
35
|
+
#: (Send send) -> void
|
39
36
|
def on_send(send)
|
40
37
|
return unless send.recv.nil? && CALLBACKS.include?(send.name)
|
41
38
|
|
@@ -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(
|
@@ -17,65 +15,76 @@ module Spoom
|
|
17
15
|
"to_param",
|
18
16
|
)
|
19
17
|
|
20
|
-
CALLBACKS =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
].freeze,
|
46
|
-
T::Array[String],
|
47
|
-
)
|
18
|
+
CALLBACKS = [
|
19
|
+
"after_commit",
|
20
|
+
"after_create_commit",
|
21
|
+
"after_create",
|
22
|
+
"after_destroy_commit",
|
23
|
+
"after_destroy",
|
24
|
+
"after_find",
|
25
|
+
"after_initialize",
|
26
|
+
"after_rollback",
|
27
|
+
"after_save_commit",
|
28
|
+
"after_save",
|
29
|
+
"after_touch",
|
30
|
+
"after_update_commit",
|
31
|
+
"after_update",
|
32
|
+
"after_validation",
|
33
|
+
"around_create",
|
34
|
+
"around_destroy",
|
35
|
+
"around_save",
|
36
|
+
"around_update",
|
37
|
+
"before_create",
|
38
|
+
"before_destroy",
|
39
|
+
"before_save",
|
40
|
+
"before_update",
|
41
|
+
"before_validation",
|
42
|
+
].freeze #: Array[String]
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
"create!",
|
54
|
-
"insert",
|
55
|
-
"insert!",
|
56
|
-
"new",
|
57
|
-
"update",
|
58
|
-
"update!",
|
59
|
-
"upsert",
|
60
|
-
].freeze,
|
61
|
-
T::Array[String],
|
62
|
-
)
|
44
|
+
CALLBACK_CONDITIONS = [
|
45
|
+
"if",
|
46
|
+
"unless",
|
47
|
+
].freeze #: Array[String]
|
63
48
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
49
|
+
CRUD_METHODS = [
|
50
|
+
"assign_attributes",
|
51
|
+
"create",
|
52
|
+
"create!",
|
53
|
+
"insert",
|
54
|
+
"insert!",
|
55
|
+
"new",
|
56
|
+
"update",
|
57
|
+
"update!",
|
58
|
+
"upsert",
|
59
|
+
].freeze #: Array[String]
|
60
|
+
|
61
|
+
ARRAY_METHODS = [
|
62
|
+
"insert_all",
|
63
|
+
"insert_all!",
|
64
|
+
"upsert_all",
|
65
|
+
].freeze #: Array[String]
|
72
66
|
|
73
|
-
|
67
|
+
# @override
|
68
|
+
#: (Send send) -> void
|
74
69
|
def on_send(send)
|
75
70
|
if send.recv.nil? && CALLBACKS.include?(send.name)
|
71
|
+
# Process direct symbol arguments
|
76
72
|
send.each_arg(Prism::SymbolNode) do |arg|
|
77
73
|
@index.reference_method(arg.unescaped, send.location)
|
78
74
|
end
|
75
|
+
|
76
|
+
# Process hash arguments for conditions like if: :method_name
|
77
|
+
send.each_arg_assoc do |key, value|
|
78
|
+
key = key.slice.delete_suffix(":")
|
79
|
+
|
80
|
+
case key
|
81
|
+
when *CALLBACK_CONDITIONS
|
82
|
+
if value&.is_a?(Prism::SymbolNode)
|
83
|
+
@index.reference_method(value.unescaped, send.location)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
79
88
|
return
|
80
89
|
end
|
81
90
|
|
@@ -16,9 +16,10 @@ module Spoom
|
|
16
16
|
"before_teardown",
|
17
17
|
)
|
18
18
|
|
19
|
-
SETUP_AND_TEARDOWN_METHODS =
|
19
|
+
SETUP_AND_TEARDOWN_METHODS = ["setup", "teardown"] #: 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)
|
@@ -5,8 +5,6 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class GraphQL < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_classes_inheriting_from(
|
11
9
|
"GraphQL::Schema::Enum",
|
12
10
|
"GraphQL::Schema::Object",
|
@@ -24,7 +22,8 @@ module Spoom
|
|
24
22
|
"unsubscribed",
|
25
23
|
)
|
26
24
|
|
27
|
-
|
25
|
+
# @override
|
26
|
+
#: (Send send) -> void
|
28
27
|
def on_send(send)
|
29
28
|
return unless send.recv.nil? && send.name == "field"
|
30
29
|
|
@@ -5,8 +5,6 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class Minitest < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_classes_named(/Test$/)
|
11
9
|
|
12
10
|
ignore_methods_named(
|
@@ -18,13 +16,15 @@ module Spoom
|
|
18
16
|
"teardown",
|
19
17
|
)
|
20
18
|
|
21
|
-
|
19
|
+
# @override
|
20
|
+
#: (Model::Method definition) -> void
|
22
21
|
def on_define_method(definition)
|
23
22
|
file = definition.location.file
|
24
23
|
@index.ignore(definition) if file.match?(%r{test/.*test\.rb$}) && definition.name.match?(/^test_/)
|
25
24
|
end
|
26
25
|
|
27
|
-
|
26
|
+
# @override
|
27
|
+
#: (Send send) -> void
|
28
28
|
def on_send(send)
|
29
29
|
case send.name
|
30
30
|
when "assert_predicate", "refute_predicate"
|
@@ -5,21 +5,21 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class Namespaces < Base
|
8
|
-
|
9
|
-
|
10
|
-
sig { override.params(definition: Model::Class).void }
|
8
|
+
# @override
|
9
|
+
#: (Model::Class definition) -> void
|
11
10
|
def on_define_class(definition)
|
12
11
|
@index.ignore(definition) if used_as_namespace?(definition)
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
# @override
|
15
|
+
#: (Model::Module definition) -> void
|
16
16
|
def on_define_module(definition)
|
17
17
|
@index.ignore(definition) if used_as_namespace?(definition)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
|
22
|
+
#: (Model::Namespace symbol_def) -> bool
|
23
23
|
def used_as_namespace?(symbol_def)
|
24
24
|
symbol_def.children.any?
|
25
25
|
end
|
@@ -5,23 +5,23 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class Rails < Base
|
8
|
-
extend T::Sig
|
9
|
-
|
10
8
|
ignore_constants_named("APP_PATH", "ENGINE_PATH", "ENGINE_ROOT")
|
11
9
|
|
12
|
-
|
10
|
+
# @override
|
11
|
+
#: (Model::Class definition) -> void
|
13
12
|
def on_define_class(definition)
|
14
13
|
@index.ignore(definition) if file_is_helper?(definition)
|
15
14
|
end
|
16
15
|
|
17
|
-
|
16
|
+
# @override
|
17
|
+
#: (Model::Module definition) -> void
|
18
18
|
def on_define_module(definition)
|
19
19
|
@index.ignore(definition) if file_is_helper?(definition)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
|
24
|
+
#: (Model::Namespace symbol_def) -> bool
|
25
25
|
def file_is_helper?(symbol_def)
|
26
26
|
symbol_def.location.file.match?(%r{app/helpers/.*\.rb$})
|
27
27
|
end
|
@@ -5,16 +5,15 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class Rubocop < Base
|
8
|
-
|
9
|
-
|
10
|
-
RUBOCOP_CONSTANTS = T.let(["MSG", "RESTRICT_ON_SEND"].to_set.freeze, T::Set[String])
|
8
|
+
RUBOCOP_CONSTANTS = ["MSG", "RESTRICT_ON_SEND"].to_set.freeze #: Set[String]
|
11
9
|
|
12
10
|
ignore_classes_inheriting_from(
|
13
11
|
"RuboCop::Cop::Cop",
|
14
12
|
"RuboCop::Cop::Base",
|
15
13
|
)
|
16
14
|
|
17
|
-
|
15
|
+
# @override
|
16
|
+
#: (Model::Constant definition) -> void
|
18
17
|
def on_define_constant(definition)
|
19
18
|
owner = definition.owner
|
20
19
|
return false unless owner.is_a?(Model::Class)
|
@@ -22,7 +21,8 @@ module Spoom
|
|
22
21
|
@index.ignore(definition) if ignored_subclass?(owner) && RUBOCOP_CONSTANTS.include?(definition.name)
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
# @override
|
25
|
+
#: (Model::Method definition) -> void
|
26
26
|
def on_define_method(definition)
|
27
27
|
return unless definition.name == "on_send"
|
28
28
|
|