spoom 1.6.0 → 1.6.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 +1 -1
- data/lib/spoom/cli/helper.rb +8 -6
- data/lib/spoom/cli/srb/coverage.rb +1 -1
- data/lib/spoom/cli/srb/sigs.rb +9 -3
- data/lib/spoom/cli/srb/tc.rb +16 -1
- data/lib/spoom/context/exec.rb +1 -1
- data/lib/spoom/context.rb +1 -1
- data/lib/spoom/coverage/report.rb +3 -3
- data/lib/spoom/coverage/snapshot.rb +1 -1
- data/lib/spoom/deadcode/index.rb +3 -3
- data/lib/spoom/deadcode/plugins/actionpack.rb +14 -17
- data/lib/spoom/deadcode/plugins/active_record.rb +41 -50
- data/lib/spoom/deadcode/plugins/active_support.rb +1 -1
- data/lib/spoom/deadcode/plugins/rubocop.rb +1 -1
- data/lib/spoom/deadcode/plugins.rb +21 -27
- data/lib/spoom/deadcode/remover.rb +21 -20
- data/lib/spoom/file_collector.rb +1 -1
- data/lib/spoom/file_tree.rb +5 -5
- data/lib/spoom/model/builder.rb +6 -9
- data/lib/spoom/model/model.rb +6 -6
- data/lib/spoom/model/namespace_visitor.rb +1 -1
- data/lib/spoom/model/references_visitor.rb +1 -1
- data/lib/spoom/poset.rb +5 -5
- data/lib/spoom/sorbet/assertions.rb +3 -3
- data/lib/spoom/sorbet/config.rb +6 -6
- data/lib/spoom/sorbet/errors.rb +71 -14
- data/lib/spoom/sorbet/lsp/base.rb +1 -1
- data/lib/spoom/sorbet/lsp/structures.rb +29 -32
- data/lib/spoom/sorbet/lsp.rb +5 -5
- data/lib/spoom/sorbet/sigils.rb +9 -12
- data/lib/spoom/sorbet/sigs.rb +27 -21
- data/lib/spoom/sorbet.rb +3 -3
- data/lib/spoom/version.rb +1 -1
- data/lib/spoom.rb +1 -1
- data/rbi/spoom.rbi +23 -578
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2f7a10c996ca4d114ec5d34f9c0a08aa1e3ab5ed8ac1853997ff5725635d61c
|
4
|
+
data.tar.gz: c2cb5939f9fa17f7737dc9ca65f0a232bfc04241a0eeb21ec4770616f0990da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4127b9180f965024a9e8afd64789bd21a2174e63933440e6c01085d54263b4f7edbc94a3e9869432c511f65dcc0c2ea8e2d1035e6e22a5f5b809a415ec49c24
|
7
|
+
data.tar.gz: 0b70e5d289ac509cbd45c8a69a5f27aeefe580d934acca250ac2feaa4d6b0a4f3cb73972e27c1524f05749b8d17f03c67fd0fe89b14a8e0528e9983576683ceb
|
data/README.md
CHANGED
@@ -221,6 +221,20 @@ Count the number of type-checking errors if all files were bumped to true:
|
|
221
221
|
$ spoom srb bump --count-errors --dry
|
222
222
|
```
|
223
223
|
|
224
|
+
#### Translate sigs between RBI and RBS
|
225
|
+
|
226
|
+
Translate all file sigs from RBI to RBS:
|
227
|
+
|
228
|
+
```
|
229
|
+
$ spoom srb sigs translate
|
230
|
+
```
|
231
|
+
|
232
|
+
Translate one file's sigs from RBS to RBI:
|
233
|
+
|
234
|
+
```
|
235
|
+
$ spoom srb sigs translate --from rbs --to rbi /path/to/file.rb
|
236
|
+
```
|
237
|
+
|
224
238
|
#### Interact with Sorbet LSP mode
|
225
239
|
|
226
240
|
**Experimental**
|
@@ -6,7 +6,7 @@ require "minitest"
|
|
6
6
|
module Spoom
|
7
7
|
module BacktraceFilter
|
8
8
|
class Minitest < ::Minitest::BacktraceFilter
|
9
|
-
SORBET_PATHS =
|
9
|
+
SORBET_PATHS = Gem.loaded_specs["sorbet-runtime"].full_require_paths.freeze #: Array[String]
|
10
10
|
|
11
11
|
# @override
|
12
12
|
#: (Array[String]? bt) -> Array[String]
|
data/lib/spoom/cli/helper.rb
CHANGED
@@ -56,7 +56,7 @@ module Spoom
|
|
56
56
|
# Returns the context at `--path` (by default the current working directory)
|
57
57
|
#: -> Context
|
58
58
|
def context
|
59
|
-
@context ||=
|
59
|
+
@context ||= Context.new(exec_path) #: Context?
|
60
60
|
end
|
61
61
|
|
62
62
|
# Raise if `spoom` is not ran inside a context with a `sorbet/config` file
|
@@ -81,15 +81,17 @@ module Spoom
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# Collect files from `paths`, defaulting to `exec_path`
|
84
|
-
#: (Array[String] paths) -> Array[String]
|
85
|
-
def collect_files(paths)
|
84
|
+
#: (Array[String] paths, ?include_rbi_files: bool) -> Array[String]
|
85
|
+
def collect_files(paths, include_rbi_files: false)
|
86
86
|
paths << exec_path if paths.empty?
|
87
87
|
|
88
88
|
files = paths.flat_map do |path|
|
89
89
|
if File.file?(path)
|
90
90
|
path
|
91
91
|
else
|
92
|
-
|
92
|
+
exts = ["rb"]
|
93
|
+
exts << "rbi" if include_rbi_files
|
94
|
+
Dir.glob("#{path}/**/*.{#{exts.join(",")}}")
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -104,7 +106,7 @@ module Spoom
|
|
104
106
|
# Colors
|
105
107
|
|
106
108
|
# Color used to highlight expressions in backticks
|
107
|
-
HIGHLIGHT_COLOR =
|
109
|
+
HIGHLIGHT_COLOR = Spoom::Color::BLUE #: Spoom::Color
|
108
110
|
|
109
111
|
# Is the `--color` option true?
|
110
112
|
#: -> bool
|
@@ -118,7 +120,7 @@ module Spoom
|
|
118
120
|
|
119
121
|
res = StringIO.new
|
120
122
|
word = StringIO.new
|
121
|
-
in_ticks =
|
123
|
+
in_ticks = false #: bool
|
122
124
|
string.chars.each do |c|
|
123
125
|
if c == "`" && !in_ticks
|
124
126
|
in_ticks = true
|
@@ -89,7 +89,7 @@ module Spoom
|
|
89
89
|
|
90
90
|
context.git_checkout!(ref: commit.sha)
|
91
91
|
|
92
|
-
snapshot =
|
92
|
+
snapshot = nil #: Spoom::Coverage::Snapshot?
|
93
93
|
if options[:bundle_install]
|
94
94
|
Bundler.with_unbundled_env do
|
95
95
|
next unless bundle_install(path, commit.sha)
|
data/lib/spoom/cli/srb/sigs.rb
CHANGED
@@ -12,6 +12,12 @@ module Spoom
|
|
12
12
|
desc "translate", "Translate signatures from/to RBI and RBS"
|
13
13
|
option :from, type: :string, aliases: :f, desc: "From format", enum: ["rbi", "rbs"], default: "rbi"
|
14
14
|
option :to, type: :string, aliases: :t, desc: "To format", enum: ["rbi", "rbs"], default: "rbs"
|
15
|
+
option :positional_names,
|
16
|
+
type: :boolean,
|
17
|
+
aliases: :p,
|
18
|
+
desc: "Use positional names when translating from RBI to RBS",
|
19
|
+
default: true
|
20
|
+
option :include_rbi_files, type: :boolean, desc: "Include RBI files", default: false
|
15
21
|
def translate(*paths)
|
16
22
|
from = options[:from]
|
17
23
|
to = options[:to]
|
@@ -21,7 +27,7 @@ module Spoom
|
|
21
27
|
exit(1)
|
22
28
|
end
|
23
29
|
|
24
|
-
files = collect_files(paths)
|
30
|
+
files = collect_files(paths, include_rbi_files: options[:include_rbi_files])
|
25
31
|
|
26
32
|
say("Translating signatures from `#{from}` to `#{to}` " \
|
27
33
|
"in `#{files.size}` file#{files.size == 1 ? "" : "s"}...\n\n")
|
@@ -29,7 +35,7 @@ module Spoom
|
|
29
35
|
case from
|
30
36
|
when "rbi"
|
31
37
|
transformed_files = transform_files(files) do |_file, contents|
|
32
|
-
Spoom::Sorbet::Sigs.rbi_to_rbs(contents)
|
38
|
+
Spoom::Sorbet::Sigs.rbi_to_rbs(contents, positional_names: options[:positional_names])
|
33
39
|
end
|
34
40
|
when "rbs"
|
35
41
|
transformed_files = transform_files(files) do |_file, contents|
|
@@ -119,7 +125,7 @@ module Spoom
|
|
119
125
|
gem "#{spec.name}", path: "#{copy_context.absolute_path}"
|
120
126
|
RB
|
121
127
|
exec(tapioca_context, "bundle install")
|
122
|
-
exec(tapioca_context, "bundle exec tapioca gem #{spec.name} --no-loc --no-file-header")
|
128
|
+
exec(tapioca_context, "bundle exec tapioca gem #{spec.name} --no-doc --no-loc --no-file-header")
|
123
129
|
|
124
130
|
rbi_path = tapioca_context.glob("sorbet/rbi/gems/#{spec.name}@*.rbi").first
|
125
131
|
unless rbi_path && tapioca_context.file?(rbi_path)
|
data/lib/spoom/cli/srb/tc.rb
CHANGED
@@ -22,6 +22,7 @@ module Spoom
|
|
22
22
|
option :format, type: :string, aliases: :f, desc: "Format line output"
|
23
23
|
option :uniq, type: :boolean, aliases: :u, desc: "Remove duplicated lines"
|
24
24
|
option :count, type: :boolean, default: true, desc: "Show errors count"
|
25
|
+
option :junit_output_path, type: :string, desc: "Output failures to XML file formatted for JUnit"
|
25
26
|
option :sorbet, type: :string, desc: "Path to custom Sorbet bin"
|
26
27
|
option :sorbet_options, type: :string, default: "", desc: "Pass options to Sorbet"
|
27
28
|
def tc(*paths_to_select)
|
@@ -32,6 +33,7 @@ module Spoom
|
|
32
33
|
uniq = options[:uniq]
|
33
34
|
format = options[:format]
|
34
35
|
count = options[:count]
|
36
|
+
junit_output_path = options[:junit_output_path]
|
35
37
|
sorbet = options[:sorbet]
|
36
38
|
|
37
39
|
unless limit || code || sort
|
@@ -55,6 +57,12 @@ module Spoom
|
|
55
57
|
|
56
58
|
if result.status
|
57
59
|
say_error(result.err, status: nil, nl: false)
|
60
|
+
if junit_output_path
|
61
|
+
doc = Spoom::Sorbet::Errors.to_junit_xml([])
|
62
|
+
file = File.open(junit_output_path, "w")
|
63
|
+
doc.write(output: file, indent: 2)
|
64
|
+
file.close
|
65
|
+
end
|
58
66
|
exit(0)
|
59
67
|
end
|
60
68
|
|
@@ -94,6 +102,13 @@ module Spoom
|
|
94
102
|
say_error(line, status: nil)
|
95
103
|
end
|
96
104
|
|
105
|
+
if junit_output_path
|
106
|
+
doc = Spoom::Sorbet::Errors.to_junit_xml(errors)
|
107
|
+
file = File.open(junit_output_path, "w")
|
108
|
+
doc.write(output: file, indent: 2)
|
109
|
+
file.close
|
110
|
+
end
|
111
|
+
|
97
112
|
if count
|
98
113
|
if errors_count == errors.size
|
99
114
|
say_error("Errors: #{errors_count}", status: nil)
|
@@ -132,7 +147,7 @@ module Spoom
|
|
132
147
|
def colorize_message(message)
|
133
148
|
return message unless color?
|
134
149
|
|
135
|
-
cyan =
|
150
|
+
cyan = false #: bool
|
136
151
|
word = StringIO.new
|
137
152
|
message.chars.each do |c|
|
138
153
|
if c == "`"
|
data/lib/spoom/context/exec.rb
CHANGED
@@ -31,7 +31,7 @@ module Spoom
|
|
31
31
|
#: (String command, ?capture_err: bool) -> ExecResult
|
32
32
|
def exec(command, capture_err: true)
|
33
33
|
Bundler.with_unbundled_env do
|
34
|
-
opts =
|
34
|
+
opts = { chdir: absolute_path } #: Hash[Symbol, untyped]
|
35
35
|
|
36
36
|
if capture_err
|
37
37
|
out, err, status = Open3.capture3(command, opts)
|
data/lib/spoom/context.rb
CHANGED
@@ -45,7 +45,7 @@ module Spoom
|
|
45
45
|
# Call `#make!` to create it.
|
46
46
|
#: (String absolute_path) -> void
|
47
47
|
def initialize(absolute_path)
|
48
|
-
@absolute_path =
|
48
|
+
@absolute_path = ::File.expand_path(absolute_path) #: String
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -40,7 +40,7 @@ module Spoom
|
|
40
40
|
|
41
41
|
abstract!
|
42
42
|
|
43
|
-
TEMPLATE =
|
43
|
+
TEMPLATE = "#{Spoom::SPOOM_PATH}/templates/page.erb" #: String
|
44
44
|
|
45
45
|
#: String
|
46
46
|
attr_reader :title
|
@@ -88,7 +88,7 @@ module Spoom
|
|
88
88
|
class Card < Template
|
89
89
|
extend T::Sig
|
90
90
|
|
91
|
-
TEMPLATE =
|
91
|
+
TEMPLATE = "#{Spoom::SPOOM_PATH}/templates/card.erb" #: String
|
92
92
|
|
93
93
|
#: String?
|
94
94
|
attr_reader :title, :body
|
@@ -120,7 +120,7 @@ module Spoom
|
|
120
120
|
end
|
121
121
|
|
122
122
|
class Snapshot < Card
|
123
|
-
TEMPLATE =
|
123
|
+
TEMPLATE = "#{Spoom::SPOOM_PATH}/templates/card_snapshot.erb" #: String
|
124
124
|
|
125
125
|
#: Coverage::Snapshot
|
126
126
|
attr_reader :snapshot
|
@@ -25,7 +25,7 @@ module Spoom
|
|
25
25
|
prop :sigils_excluding_rbis, T::Hash[String, Integer], default: Hash.new(0)
|
26
26
|
|
27
27
|
# The strictness name as found in the Sorbet metrics file
|
28
|
-
STRICTNESSES =
|
28
|
+
STRICTNESSES = ["ignore", "false", "true", "strict", "strong", "stdlib"].freeze #: Array[String]
|
29
29
|
|
30
30
|
#: (?out: (IO | StringIO), ?colors: bool, ?indent_level: Integer) -> void
|
31
31
|
def print(out: $stdout, colors: true, indent_level: 0)
|
data/lib/spoom/deadcode/index.rb
CHANGED
@@ -24,9 +24,9 @@ module Spoom
|
|
24
24
|
#: (Model model) -> void
|
25
25
|
def initialize(model)
|
26
26
|
@model = model
|
27
|
-
@definitions =
|
28
|
-
@references =
|
29
|
-
@ignored =
|
27
|
+
@definitions = {} #: Hash[String, Array[Definition]]
|
28
|
+
@references = {} #: Hash[String, Array[Model::Reference]]
|
29
|
+
@ignored = Set.new #: Set[Model::SymbolDef]
|
30
30
|
end
|
31
31
|
|
32
32
|
# Indexing
|
@@ -7,23 +7,20 @@ module Spoom
|
|
7
7
|
class ActionPack < Base
|
8
8
|
ignore_classes_inheriting_from("ApplicationController")
|
9
9
|
|
10
|
-
CALLBACKS =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
].freeze,
|
25
|
-
T::Array[String],
|
26
|
-
)
|
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]
|
27
24
|
|
28
25
|
# @override
|
29
26
|
#: (Model::Method definition) -> void
|
@@ -15,58 +15,49 @@ module Spoom
|
|
15
15
|
"to_param",
|
16
16
|
)
|
17
17
|
|
18
|
-
CALLBACKS =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
].freeze,
|
44
|
-
T::Array[String],
|
45
|
-
)
|
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]
|
46
43
|
|
47
|
-
CRUD_METHODS =
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
].freeze,
|
59
|
-
T::Array[String],
|
60
|
-
)
|
44
|
+
CRUD_METHODS = [
|
45
|
+
"assign_attributes",
|
46
|
+
"create",
|
47
|
+
"create!",
|
48
|
+
"insert",
|
49
|
+
"insert!",
|
50
|
+
"new",
|
51
|
+
"update",
|
52
|
+
"update!",
|
53
|
+
"upsert",
|
54
|
+
].freeze #: Array[String]
|
61
55
|
|
62
|
-
ARRAY_METHODS =
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
].freeze,
|
68
|
-
T::Array[String],
|
69
|
-
)
|
56
|
+
ARRAY_METHODS = [
|
57
|
+
"insert_all",
|
58
|
+
"insert_all!",
|
59
|
+
"upsert_all",
|
60
|
+
].freeze #: Array[String]
|
70
61
|
|
71
62
|
# @override
|
72
63
|
#: (Send send) -> void
|
@@ -5,7 +5,7 @@ module Spoom
|
|
5
5
|
module Deadcode
|
6
6
|
module Plugins
|
7
7
|
class Rubocop < Base
|
8
|
-
RUBOCOP_CONSTANTS =
|
8
|
+
RUBOCOP_CONSTANTS = ["MSG", "RESTRICT_ON_SEND"].to_set.freeze #: Set[String]
|
9
9
|
|
10
10
|
ignore_classes_inheriting_from(
|
11
11
|
"RuboCop::Cop::Cop",
|
@@ -25,34 +25,28 @@ module Spoom
|
|
25
25
|
module Deadcode
|
26
26
|
DEFAULT_CUSTOM_PLUGINS_PATH = ".spoom/deadcode/plugins"
|
27
27
|
|
28
|
-
DEFAULT_PLUGINS =
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
]).freeze,
|
33
|
-
T::Set[T.class_of(Plugins::Base)],
|
34
|
-
)
|
28
|
+
DEFAULT_PLUGINS = Set.new([
|
29
|
+
Spoom::Deadcode::Plugins::Namespaces,
|
30
|
+
Spoom::Deadcode::Plugins::Ruby,
|
31
|
+
]).freeze #: Set[singleton(Plugins::Base)]
|
35
32
|
|
36
|
-
PLUGINS_FOR_GEM =
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}.freeze,
|
54
|
-
T::Hash[String, T.class_of(Plugins::Base)],
|
55
|
-
)
|
33
|
+
PLUGINS_FOR_GEM = {
|
34
|
+
"actionmailer" => Spoom::Deadcode::Plugins::ActionMailer,
|
35
|
+
"actionpack" => Spoom::Deadcode::Plugins::ActionPack,
|
36
|
+
"activejob" => Spoom::Deadcode::Plugins::ActiveJob,
|
37
|
+
"activemodel" => Spoom::Deadcode::Plugins::ActiveModel,
|
38
|
+
"activerecord" => Spoom::Deadcode::Plugins::ActiveRecord,
|
39
|
+
"activesupport" => Spoom::Deadcode::Plugins::ActiveSupport,
|
40
|
+
"graphql" => Spoom::Deadcode::Plugins::GraphQL,
|
41
|
+
"minitest" => Spoom::Deadcode::Plugins::Minitest,
|
42
|
+
"rails" => Spoom::Deadcode::Plugins::Rails,
|
43
|
+
"rake" => Spoom::Deadcode::Plugins::Rake,
|
44
|
+
"rspec" => Spoom::Deadcode::Plugins::RSpec,
|
45
|
+
"rubocop" => Spoom::Deadcode::Plugins::Rubocop,
|
46
|
+
"sorbet-runtime" => Spoom::Deadcode::Plugins::Sorbet,
|
47
|
+
"sorbet-static" => Spoom::Deadcode::Plugins::Sorbet,
|
48
|
+
"thor" => Spoom::Deadcode::Plugins::Thor,
|
49
|
+
}.freeze #: Hash[String, singleton(Plugins::Base)]
|
56
50
|
|
57
51
|
class << self
|
58
52
|
#: (Context context) -> Set[singleton(Plugins::Base)]
|
@@ -31,11 +31,11 @@ module Spoom
|
|
31
31
|
#: (String source, Definition::Kind? kind, Location location) -> void
|
32
32
|
def initialize(source, kind, location)
|
33
33
|
@old_source = source
|
34
|
-
@new_source =
|
34
|
+
@new_source = source.dup #: String
|
35
35
|
@kind = kind
|
36
36
|
@location = location
|
37
37
|
|
38
|
-
@node_context =
|
38
|
+
@node_context = NodeFinder.find(source, location, kind) #: NodeContext
|
39
39
|
end
|
40
40
|
|
41
41
|
#: -> void
|
@@ -99,8 +99,10 @@ module Spoom
|
|
99
99
|
prev_node = context.previous_node
|
100
100
|
next_node = context.next_node
|
101
101
|
|
102
|
-
|
103
|
-
|
102
|
+
has_prev_node_on_different_line = prev_node && prev_node.location.end_line != node.location.start_line
|
103
|
+
has_next_node_on_different_line = next_node && next_node.location.start_line != node.location.end_line
|
104
|
+
|
105
|
+
if has_prev_node_on_different_line && has_next_node_on_different_line
|
104
106
|
# We have a node before and after, but on different lines, we need to remove the whole line
|
105
107
|
#
|
106
108
|
# ~~~
|
@@ -164,8 +166,10 @@ module Spoom
|
|
164
166
|
prev_node = context.previous_node
|
165
167
|
next_node = context.next_node
|
166
168
|
|
167
|
-
|
168
|
-
|
169
|
+
has_prev_node_on_different_line = prev_node && prev_node.location.end_line != context.node.location.start_line
|
170
|
+
has_next_node_on_different_line = next_node && next_node.location.start_line != context.node.location.end_line
|
171
|
+
|
172
|
+
if has_prev_node_on_different_line && has_next_node_on_different_line
|
169
173
|
# We have a node before and after, but on different lines, we need to remove the whole line
|
170
174
|
#
|
171
175
|
# ~~~
|
@@ -275,7 +279,7 @@ module Spoom
|
|
275
279
|
|
276
280
|
# Adjust the lines to remove to include previous blank lines
|
277
281
|
prev_context = NodeContext.new(@old_source, @node_context.comments, first_node, context.nesting)
|
278
|
-
before =
|
282
|
+
before = prev_context.previous_node #: (Prism::Node | Prism::Comment)?
|
279
283
|
|
280
284
|
# There may be an unrelated comment between the current node and the one before
|
281
285
|
# if there is, we only want to delete lines up to the last comment found
|
@@ -329,7 +333,7 @@ module Spoom
|
|
329
333
|
|
330
334
|
#: (Prism::CallNode node, name: String, kind: Definition::Kind?) -> String
|
331
335
|
def transform_sig(node, name:, kind:)
|
332
|
-
type =
|
336
|
+
type = nil #: String?
|
333
337
|
|
334
338
|
block = T.cast(node.block, Prism::BlockNode)
|
335
339
|
statements = T.cast(block.body, Prism::StatementsNode)
|
@@ -428,7 +432,7 @@ module Spoom
|
|
428
432
|
|
429
433
|
#: -> NodeContext?
|
430
434
|
def sclass_context
|
431
|
-
sclass =
|
435
|
+
sclass = nil #: Prism::SingletonClassNode?
|
432
436
|
|
433
437
|
nesting = @nesting.dup
|
434
438
|
until nesting.empty? || sclass
|
@@ -473,7 +477,7 @@ module Spoom
|
|
473
477
|
|
474
478
|
#: (Integer start_line, Integer end_line) -> Array[Prism::Comment]
|
475
479
|
def comments_between_lines(start_line, end_line)
|
476
|
-
comments =
|
480
|
+
comments = [] #: Array[Prism::Comment]
|
477
481
|
|
478
482
|
(start_line + 1).upto(end_line - 1) do |line|
|
479
483
|
comment = @comments[line]
|
@@ -485,7 +489,7 @@ module Spoom
|
|
485
489
|
|
486
490
|
#: (Prism::Node node) -> Array[Prism::Comment]
|
487
491
|
def attached_comments(node)
|
488
|
-
comments =
|
492
|
+
comments = [] #: Array[Prism::Comment]
|
489
493
|
|
490
494
|
start_line = node.location.start_line - 1
|
491
495
|
start_line.downto(1) do |line|
|
@@ -500,7 +504,7 @@ module Spoom
|
|
500
504
|
|
501
505
|
#: -> Array[Prism::Node]
|
502
506
|
def attached_sigs
|
503
|
-
nodes =
|
507
|
+
nodes = [] #: Array[Prism::Node]
|
504
508
|
|
505
509
|
previous_nodes.reverse_each do |prev_node|
|
506
510
|
break unless sorbet_signature?(prev_node)
|
@@ -553,12 +557,9 @@ module Spoom
|
|
553
557
|
raise Error, "Can't find node at #{location}, expected #{kind} but got #{node.class}"
|
554
558
|
end
|
555
559
|
|
556
|
-
comments_by_line =
|
557
|
-
|
558
|
-
|
559
|
-
end,
|
560
|
-
T::Hash[Integer, Prism::Comment],
|
561
|
-
)
|
560
|
+
comments_by_line = result.comments.to_h do |comment|
|
561
|
+
[comment.location.start_line, comment]
|
562
|
+
end #: Hash[Integer, Prism::Comment]
|
562
563
|
|
563
564
|
NodeContext.new(source, comments_by_line, node, visitor.nodes_nesting)
|
564
565
|
end
|
@@ -599,8 +600,8 @@ module Spoom
|
|
599
600
|
super()
|
600
601
|
@location = location
|
601
602
|
@kind = kind
|
602
|
-
@node =
|
603
|
-
@nodes_nesting =
|
603
|
+
@node = nil #: Prism::Node?
|
604
|
+
@nodes_nesting = [] #: Array[Prism::Node]
|
604
605
|
end
|
605
606
|
|
606
607
|
# @override
|
data/lib/spoom/file_collector.rb
CHANGED
@@ -16,7 +16,7 @@ module Spoom
|
|
16
16
|
# the list.
|
17
17
|
#: (?allow_extensions: Array[String], ?allow_mime_types: Array[String], ?exclude_patterns: Array[String]) -> void
|
18
18
|
def initialize(allow_extensions: [], allow_mime_types: [], exclude_patterns: [])
|
19
|
-
@files =
|
19
|
+
@files = [] #: Array[String]
|
20
20
|
@allow_extensions = allow_extensions
|
21
21
|
@allow_mime_types = allow_mime_types
|
22
22
|
@exclude_patterns = exclude_patterns
|