spoom 1.0.9 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/spoom/cli/bump.rb +17 -2
- data/lib/spoom/cli/coverage.rb +6 -5
- data/lib/spoom/cli/helper.rb +5 -2
- data/lib/spoom/cli/run.rb +1 -1
- data/lib/spoom/coverage/d3/timeline.rb +146 -9
- data/lib/spoom/coverage/report.rb +10 -0
- data/lib/spoom/coverage/snapshot.rb +3 -1
- data/lib/spoom/coverage.rb +14 -1
- data/lib/spoom/git.rb +22 -2
- data/lib/spoom/sorbet/config.rb +13 -0
- data/lib/spoom/sorbet/sigils.rb +1 -1
- data/lib/spoom/test_helpers/project.rb +10 -0
- data/lib/spoom/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5782933918e2b2f81d28af1fe48f3727fdd81970bcaeed0549fa1b1fb594523
|
4
|
+
data.tar.gz: 5d980328f5d64277f3c03a2cccc589b067d2b4648aad29476d9a1f26b2175d5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e80bccb9cad071234a117a66aa6c37bbdf8787a0399b436e0c07062521fa974b28ee9f94f9bf0c2964fcfe4c6689ddf551ad3e6f9b87e2fb6caa12ad1987a381
|
7
|
+
data.tar.gz: c635b37ef3dcadc64251d627e3574d7a8fef883afdc1dab8e32a68765f94a10ca7a5e696f88cee533369332efc69562eec005d7f032e7f02067871285b49ba64
|
data/README.md
CHANGED
@@ -226,6 +226,12 @@ Bump files using a custom instance of Sorbet:
|
|
226
226
|
$ spoom bump --from false --to true --sorbet /path/to/sorbet/bin
|
227
227
|
```
|
228
228
|
|
229
|
+
Count the number of type-checking errors if all files were bumped to true:
|
230
|
+
|
231
|
+
```
|
232
|
+
$ spoom bump --count-errors --dry
|
233
|
+
```
|
234
|
+
|
229
235
|
#### Interact with Sorbet LSP mode
|
230
236
|
|
231
237
|
**Experimental**
|
data/lib/spoom/cli/bump.rb
CHANGED
@@ -26,6 +26,8 @@ module Spoom
|
|
26
26
|
desc: "Only change specified list (one file by line)"
|
27
27
|
option :suggest_bump_command, type: :string,
|
28
28
|
desc: "Command to suggest if files can be bumped"
|
29
|
+
option :count_errors, type: :boolean, default: false,
|
30
|
+
desc: "Count the number of errors if all files were bumped"
|
29
31
|
sig { params(directory: String).void }
|
30
32
|
def bump(directory = ".")
|
31
33
|
in_sorbet_project!
|
@@ -48,6 +50,11 @@ module Spoom
|
|
48
50
|
exit(1)
|
49
51
|
end
|
50
52
|
|
53
|
+
if options[:count_errors] && !dry
|
54
|
+
say_error("`--count-errors` can only be used with `--dry`")
|
55
|
+
exit(1)
|
56
|
+
end
|
57
|
+
|
51
58
|
say("Checking files...")
|
52
59
|
|
53
60
|
directory = File.expand_path(directory)
|
@@ -76,7 +83,12 @@ module Spoom
|
|
76
83
|
exit(files_to_bump.empty?)
|
77
84
|
end
|
78
85
|
|
79
|
-
output, no_errors = Sorbet.srb_tc(
|
86
|
+
output, no_errors = Sorbet.srb_tc(
|
87
|
+
"--no-error-sections",
|
88
|
+
path: exec_path,
|
89
|
+
capture_err: true,
|
90
|
+
sorbet_bin: options[:sorbet]
|
91
|
+
)
|
80
92
|
|
81
93
|
if no_errors
|
82
94
|
print_changes(files_to_bump, command: cmd, from: from, to: to, dry: dry, path: exec_path)
|
@@ -90,11 +102,14 @@ module Spoom
|
|
90
102
|
path = File.expand_path(err.file)
|
91
103
|
next unless path.start_with?(directory)
|
92
104
|
next unless File.file?(path)
|
105
|
+
next unless files_to_bump.include?(path)
|
93
106
|
path
|
94
107
|
end.compact.uniq
|
95
108
|
|
96
109
|
undo_changes(files_with_errors, from)
|
97
110
|
|
111
|
+
say("Found #{errors.length} type checking error#{'s' if errors.length > 1}") if options[:count_errors]
|
112
|
+
|
98
113
|
files_changed = files_to_bump - files_with_errors
|
99
114
|
print_changes(files_changed, command: cmd, from: from, to: to, dry: dry, path: exec_path)
|
100
115
|
undo_changes(files_to_bump, from) if dry
|
@@ -119,7 +134,7 @@ module Spoom
|
|
119
134
|
if dry && command
|
120
135
|
say("\nRun `#{command}` to bump them")
|
121
136
|
elsif dry
|
122
|
-
say("\nRun `spoom bump --from #{from} --to #{to}`
|
137
|
+
say("\nRun `spoom bump --from #{from} --to #{to}` locally then `commit the changes` and `push them`")
|
123
138
|
end
|
124
139
|
end
|
125
140
|
|
data/lib/spoom/cli/coverage.rb
CHANGED
@@ -15,7 +15,7 @@ module Spoom
|
|
15
15
|
|
16
16
|
desc "snapshot", "Run srb tc and display metrics"
|
17
17
|
option :save, type: :string, lazy_default: DATA_DIR, desc: "Save snapshot data as json"
|
18
|
-
option :rbi, type: :boolean, default: true, desc: "
|
18
|
+
option :rbi, type: :boolean, default: true, desc: "Include RBI files in metrics"
|
19
19
|
option :sorbet, type: :string, desc: "Path to custom Sorbet bin"
|
20
20
|
def snapshot
|
21
21
|
in_sorbet_project!
|
@@ -44,8 +44,9 @@ module Spoom
|
|
44
44
|
path = exec_path
|
45
45
|
sorbet = options[:sorbet]
|
46
46
|
|
47
|
-
|
48
|
-
unless
|
47
|
+
ref_before = Spoom::Git.current_branch
|
48
|
+
ref_before = Spoom::Git.last_commit(path: path) unless ref_before
|
49
|
+
unless ref_before
|
49
50
|
say_error("Not in a git repository")
|
50
51
|
say_error("\nSpoom needs to checkout into your previous commits to build the timeline.", status: nil)
|
51
52
|
exit(1)
|
@@ -90,7 +91,7 @@ module Spoom
|
|
90
91
|
|
91
92
|
snapshot = T.let(nil, T.nilable(Spoom::Coverage::Snapshot))
|
92
93
|
if options[:bundle_install]
|
93
|
-
Bundler.
|
94
|
+
Bundler.with_unbundled_env do
|
94
95
|
next unless bundle_install(path, sha)
|
95
96
|
snapshot = Spoom::Coverage.snapshot(path: path, sorbet_bin: sorbet)
|
96
97
|
end
|
@@ -107,7 +108,7 @@ module Spoom
|
|
107
108
|
File.write(file, snapshot.to_json)
|
108
109
|
say(" Snapshot data saved under `#{file}`\n\n")
|
109
110
|
end
|
110
|
-
Spoom::Git.checkout(
|
111
|
+
Spoom::Git.checkout(ref_before, path: path)
|
111
112
|
end
|
112
113
|
|
113
114
|
desc "report", "Produce a typing coverage report"
|
data/lib/spoom/cli/helper.rb
CHANGED
@@ -9,8 +9,11 @@ module Spoom
|
|
9
9
|
module Cli
|
10
10
|
module Helper
|
11
11
|
extend T::Sig
|
12
|
+
extend T::Helpers
|
12
13
|
include Thor::Shell
|
13
14
|
|
15
|
+
requires_ancestor Thor
|
16
|
+
|
14
17
|
# Print `message` on `$stdout`
|
15
18
|
sig { params(message: String).void }
|
16
19
|
def say(message)
|
@@ -66,7 +69,7 @@ module Spoom
|
|
66
69
|
# Return the path specified through `--path`
|
67
70
|
sig { returns(String) }
|
68
71
|
def exec_path
|
69
|
-
|
72
|
+
options[:path]
|
70
73
|
end
|
71
74
|
|
72
75
|
sig { returns(String) }
|
@@ -87,7 +90,7 @@ module Spoom
|
|
87
90
|
# Is the `--color` option true?
|
88
91
|
sig { returns(T::Boolean) }
|
89
92
|
def color?
|
90
|
-
|
93
|
+
options[:color]
|
91
94
|
end
|
92
95
|
|
93
96
|
sig { params(string: String).returns(String) }
|
data/lib/spoom/cli/run.rb
CHANGED
@@ -17,7 +17,7 @@ module Spoom
|
|
17
17
|
desc "tc", "Run `srb tc`"
|
18
18
|
option :limit, type: :numeric, aliases: :l, desc: "Limit displayed errors"
|
19
19
|
option :code, type: :numeric, aliases: :c, desc: "Filter displayed errors by code"
|
20
|
-
option :sort, type: :string, aliases: :s, desc: "Sort errors", enum: SORT_ENUM,
|
20
|
+
option :sort, type: :string, aliases: :s, desc: "Sort errors", enum: SORT_ENUM, default: SORT_LOC
|
21
21
|
option :format, type: :string, aliases: :f, desc: "Format line output"
|
22
22
|
option :uniq, type: :boolean, aliases: :u, desc: "Remove duplicated lines"
|
23
23
|
option :count, type: :boolean, default: true, desc: "Show errors count"
|
@@ -36,10 +36,28 @@ module Spoom
|
|
36
36
|
pointer-events: none;
|
37
37
|
}
|
38
38
|
|
39
|
+
.area {
|
40
|
+
fill-opacity: 0.5;
|
41
|
+
}
|
42
|
+
|
43
|
+
.line {
|
44
|
+
stroke-width: 2;
|
45
|
+
fill: transparent;
|
46
|
+
}
|
47
|
+
|
48
|
+
.dot {
|
49
|
+
r: 2;
|
50
|
+
fill: #888;
|
51
|
+
}
|
52
|
+
|
39
53
|
.inverted .grid line {
|
40
54
|
stroke: #777;
|
41
55
|
}
|
42
56
|
|
57
|
+
.inverted .area {
|
58
|
+
fill-opacity: 0.9;
|
59
|
+
}
|
60
|
+
|
43
61
|
.inverted .axis text {
|
44
62
|
fill: #fff;
|
45
63
|
}
|
@@ -47,6 +65,10 @@ module Spoom
|
|
47
65
|
.inverted .axis line {
|
48
66
|
stroke: #fff;
|
49
67
|
}
|
68
|
+
|
69
|
+
.inverted .dot {
|
70
|
+
fill: #fff;
|
71
|
+
}
|
50
72
|
CSS
|
51
73
|
end
|
52
74
|
|
@@ -170,7 +192,6 @@ module Spoom
|
|
170
192
|
.y1((d) => yScale_#{id}(#{y}))
|
171
193
|
.curve(d3.#{curve}))
|
172
194
|
.attr("fill", "#{color}")
|
173
|
-
.attr("fill-opacity", 0.5)
|
174
195
|
HTML
|
175
196
|
end
|
176
197
|
|
@@ -185,8 +206,6 @@ module Spoom
|
|
185
206
|
.y((d) => yScale_#{id}(#{y}))
|
186
207
|
.curve(d3.#{curve}))
|
187
208
|
.attr("stroke", "#{color}")
|
188
|
-
.attr("stroke-width", 3)
|
189
|
-
.attr("fill", "transparent")
|
190
209
|
HTML
|
191
210
|
end
|
192
211
|
|
@@ -198,10 +217,8 @@ module Spoom
|
|
198
217
|
.enter()
|
199
218
|
.append("circle")
|
200
219
|
.attr("class", "dot")
|
201
|
-
.attr("r", 3)
|
202
220
|
.attr("cx", (d) => xScale_#{id}(parseDate(d.timestamp)))
|
203
221
|
.attr("cy", (d, i) => yScale_#{id}(#{y}))
|
204
|
-
.attr("fill", "#aaa")
|
205
222
|
.on("mouseover", (d) => tooltip.style("opacity", 1))
|
206
223
|
.on("mousemove", tooltip_#{id})
|
207
224
|
.on("mouseleave", (d) => tooltip.style("opacity", 0));
|
@@ -381,18 +398,15 @@ module Spoom
|
|
381
398
|
layer.append("path")
|
382
399
|
.attr("class", "area")
|
383
400
|
.attr("d", area_#{id})
|
384
|
-
.attr("fill", (d) =>
|
385
|
-
.attr("fill-opacity", 0.9)
|
401
|
+
.attr("fill", (d) => #{color})
|
386
402
|
|
387
403
|
svg_#{id}.selectAll("circle")
|
388
404
|
.data(points_#{id})
|
389
405
|
.enter()
|
390
406
|
.append("circle")
|
391
407
|
.attr("class", "dot")
|
392
|
-
.attr("r", 2)
|
393
408
|
.attr("cx", (d) => xScale_#{id}(parseDate(#{y})))
|
394
409
|
.attr("cy", (d, i) => yScale_#{id}(d[1]))
|
395
|
-
.attr("fill", "#fff")
|
396
410
|
.on("mouseover", (d) => tooltip.style("opacity", 1))
|
397
411
|
.on("mousemove", tooltip_#{id})
|
398
412
|
.on("mouseleave", (d) => tooltip.style("opacity", 0));
|
@@ -480,6 +494,129 @@ module Spoom
|
|
480
494
|
JS
|
481
495
|
end
|
482
496
|
end
|
497
|
+
|
498
|
+
class RBIs < Stacked
|
499
|
+
extend T::Sig
|
500
|
+
|
501
|
+
sig { params(id: String, snapshots: T::Array[Snapshot]).void }
|
502
|
+
def initialize(id, snapshots)
|
503
|
+
keys = ['rbis', 'files']
|
504
|
+
data = snapshots.map do |snapshot|
|
505
|
+
{
|
506
|
+
timestamp: snapshot.commit_timestamp,
|
507
|
+
commit: snapshot.commit_sha,
|
508
|
+
total: snapshot.files,
|
509
|
+
values: { files: snapshot.files - snapshot.rbi_files, rbis: snapshot.rbi_files },
|
510
|
+
}
|
511
|
+
end
|
512
|
+
super(id, data, keys)
|
513
|
+
end
|
514
|
+
|
515
|
+
sig { override.returns(String) }
|
516
|
+
def tooltip
|
517
|
+
<<~JS
|
518
|
+
function tooltip_#{id}(d) {
|
519
|
+
moveTooltip(d)
|
520
|
+
.html("commit <b>" + d.data.commit + "</b><br>"
|
521
|
+
+ d3.timeFormat("%y/%m/%d")(parseDate(d.data.timestamp)) + "<br><br>"
|
522
|
+
+ "Files: <b>" + d.data.values.files + "</b><br>"
|
523
|
+
+ "RBIs: <b>" + d.data.values.rbis + "</b><br><br>"
|
524
|
+
+ "Total: <b>" + d.data.total + "</b>")
|
525
|
+
}
|
526
|
+
JS
|
527
|
+
end
|
528
|
+
|
529
|
+
sig { override.returns(String) }
|
530
|
+
def script
|
531
|
+
<<~JS
|
532
|
+
#{tooltip}
|
533
|
+
|
534
|
+
var data_#{id} = #{@data.to_json};
|
535
|
+
var keys_#{id} = #{T.unsafe(@keys).to_json};
|
536
|
+
|
537
|
+
var stack_#{id} = d3.stack()
|
538
|
+
.keys(keys_#{id})
|
539
|
+
.value((d, key) => d.values[key]);
|
540
|
+
|
541
|
+
var layers_#{id} = stack_#{id}(data_#{id});
|
542
|
+
|
543
|
+
var points_#{id} = []
|
544
|
+
layers_#{id}.forEach(function(d) {
|
545
|
+
d.forEach(function(p) {
|
546
|
+
p.key = d.key
|
547
|
+
points_#{id}.push(p);
|
548
|
+
});
|
549
|
+
})
|
550
|
+
|
551
|
+
function draw_#{id}() {
|
552
|
+
var width_#{id} = document.getElementById("#{id}").clientWidth;
|
553
|
+
var height_#{id} = 200;
|
554
|
+
|
555
|
+
d3.select("##{id}").selectAll("*").remove()
|
556
|
+
|
557
|
+
var svg_#{id} = d3.select("##{id}")
|
558
|
+
.attr("width", width_#{id})
|
559
|
+
.attr("height", height_#{id});
|
560
|
+
|
561
|
+
#{plot}
|
562
|
+
}
|
563
|
+
|
564
|
+
draw_#{id}();
|
565
|
+
window.addEventListener("resize", draw_#{id});
|
566
|
+
JS
|
567
|
+
end
|
568
|
+
|
569
|
+
sig { override.params(y: String, color: String, curve: String).returns(String) }
|
570
|
+
def line(y:, color: 'strictnessColor(d.key)', curve: 'curveCatmullRom.alpha(1)')
|
571
|
+
<<~JS
|
572
|
+
var area_#{id} = d3.area()
|
573
|
+
.x((d) => xScale_#{id}(parseDate(#{y})))
|
574
|
+
.y0((d) => yScale_#{id}(d[0]))
|
575
|
+
.y1((d) => yScale_#{id}(d[1]))
|
576
|
+
.curve(d3.#{curve});
|
577
|
+
|
578
|
+
var layer = svg_#{id}.selectAll(".layer")
|
579
|
+
.data(layers_#{id})
|
580
|
+
.enter().append("g")
|
581
|
+
.attr("class", "layer")
|
582
|
+
|
583
|
+
layer.append("path")
|
584
|
+
.attr("class", "area")
|
585
|
+
.attr("d", area_#{id})
|
586
|
+
.attr("fill", (d) => #{color})
|
587
|
+
|
588
|
+
layer.append("path")
|
589
|
+
.attr("class", "line")
|
590
|
+
.attr("d", d3.line()
|
591
|
+
.x((d) => xScale_#{id}(parseDate(#{y})))
|
592
|
+
.y((d, i) => yScale_#{id}(d[1]))
|
593
|
+
.curve(d3.#{curve}))
|
594
|
+
.attr("stroke", (d) => #{color})
|
595
|
+
|
596
|
+
svg_#{id}.selectAll("circle")
|
597
|
+
.data(points_#{id})
|
598
|
+
.enter()
|
599
|
+
.append("circle")
|
600
|
+
.attr("class", "dot")
|
601
|
+
.attr("cx", (d) => xScale_#{id}(parseDate(#{y})))
|
602
|
+
.attr("cy", (d, i) => yScale_#{id}(d[1]))
|
603
|
+
.on("mouseover", (d) => tooltip.style("opacity", 1))
|
604
|
+
.on("mousemove", tooltip_#{id})
|
605
|
+
.on("mouseleave", (d) => tooltip.style("opacity", 0));
|
606
|
+
JS
|
607
|
+
end
|
608
|
+
|
609
|
+
sig { override.returns(String) }
|
610
|
+
def plot
|
611
|
+
<<~JS
|
612
|
+
#{x_scale}
|
613
|
+
#{y_scale(min: '0', max: "d3.max(data_#{id}, (d) => d.total + 10)", ticks: 'tickValues([0, 25, 50, 75, 100])')}
|
614
|
+
#{line(y: 'd.data.timestamp', color: "d.key == 'rbis' ? '#8673ff' : '#007bff'")}
|
615
|
+
#{x_ticks}
|
616
|
+
#{y_ticks(ticks: 'tickValues([25, 50, 75])', format: 'd', padding: 20)}
|
617
|
+
JS
|
618
|
+
end
|
619
|
+
end
|
483
620
|
end
|
484
621
|
end
|
485
622
|
end
|
@@ -194,6 +194,15 @@ module Spoom
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
+
class RBIs < Timeline
|
198
|
+
extend T::Sig
|
199
|
+
|
200
|
+
sig { params(snapshots: T::Array[Coverage::Snapshot], title: String).void }
|
201
|
+
def initialize(snapshots:, title: "RBIs Timeline")
|
202
|
+
super(title: title, timeline: D3::Timeline::RBIs.new("timeline_rbis", snapshots))
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
197
206
|
class Versions < Timeline
|
198
207
|
extend T::Sig
|
199
208
|
|
@@ -298,6 +307,7 @@ module Spoom
|
|
298
307
|
cards << Cards::Timeline::Sigils.new(snapshots: snapshots)
|
299
308
|
cards << Cards::Timeline::Calls.new(snapshots: snapshots)
|
300
309
|
cards << Cards::Timeline::Sigs.new(snapshots: snapshots)
|
310
|
+
cards << Cards::Timeline::RBIs.new(snapshots: snapshots)
|
301
311
|
cards << Cards::Timeline::Versions.new(snapshots: snapshots)
|
302
312
|
cards << Cards::Timeline::Runtimes.new(snapshots: snapshots)
|
303
313
|
cards << Cards::SorbetIntro.new(sorbet_intro_commit: sorbet_intro_commit, sorbet_intro_date: sorbet_intro_date)
|
@@ -13,6 +13,7 @@ module Spoom
|
|
13
13
|
prop :commit_sha, T.nilable(String), default: nil
|
14
14
|
prop :commit_timestamp, T.nilable(Integer), default: nil
|
15
15
|
prop :files, Integer, default: 0
|
16
|
+
prop :rbi_files, Integer, default: 0
|
16
17
|
prop :modules, Integer, default: 0
|
17
18
|
prop :classes, Integer, default: 0
|
18
19
|
prop :singleton_classes, Integer, default: 0
|
@@ -46,6 +47,7 @@ module Spoom
|
|
46
47
|
snapshot.commit_sha = obj.fetch("commit_sha", nil)
|
47
48
|
snapshot.commit_timestamp = obj.fetch("commit_timestamp", nil)
|
48
49
|
snapshot.files = obj.fetch("files", 0)
|
50
|
+
snapshot.rbi_files = obj.fetch("rbi_files", 0)
|
49
51
|
snapshot.modules = obj.fetch("modules", 0)
|
50
52
|
snapshot.classes = obj.fetch("classes", 0)
|
51
53
|
snapshot.singleton_classes = obj.fetch("singleton_classes", 0)
|
@@ -86,7 +88,7 @@ module Spoom
|
|
86
88
|
end
|
87
89
|
printl("Content:")
|
88
90
|
indent
|
89
|
-
printl("files: #{snapshot.files}")
|
91
|
+
printl("files: #{snapshot.files} (including #{snapshot.rbi_files} RBIs)")
|
90
92
|
printl("modules: #{snapshot.modules}")
|
91
93
|
printl("classes: #{snapshot.classes - snapshot.singleton_classes}")
|
92
94
|
printl("methods: #{methods}")
|
data/lib/spoom/coverage.rb
CHANGED
@@ -21,6 +21,9 @@ module Spoom
|
|
21
21
|
|
22
22
|
metrics = Spoom::Sorbet.srb_metrics(
|
23
23
|
"--no-config",
|
24
|
+
"--no-error-sections",
|
25
|
+
"--no-error-count",
|
26
|
+
"--isolate-error-code=0",
|
24
27
|
new_config.options_string,
|
25
28
|
path: path,
|
26
29
|
capture_err: true,
|
@@ -54,6 +57,9 @@ module Spoom
|
|
54
57
|
snapshot.version_static = Spoom::Sorbet.version_from_gemfile_lock(gem: "sorbet-static", path: path)
|
55
58
|
snapshot.version_runtime = Spoom::Sorbet.version_from_gemfile_lock(gem: "sorbet-runtime", path: path)
|
56
59
|
|
60
|
+
files = Spoom::Sorbet.srb_files(new_config, path: path)
|
61
|
+
snapshot.rbi_files = files.count { |file| file.end_with?(".rbi") }
|
62
|
+
|
57
63
|
snapshot
|
58
64
|
end
|
59
65
|
|
@@ -81,8 +87,15 @@ module Spoom
|
|
81
87
|
def self.sigils_tree(path: ".")
|
82
88
|
config = sorbet_config(path: path)
|
83
89
|
files = Sorbet.srb_files(config, path: path)
|
84
|
-
|
90
|
+
|
91
|
+
extensions = config.allowed_extensions
|
92
|
+
extensions = [".rb"] if extensions.empty?
|
93
|
+
extensions -= [".rbi"]
|
94
|
+
|
95
|
+
pattern = /\.(#{Regexp.union(extensions.map { |ext| ext[1..-1] })})$/
|
96
|
+
files.select! { |file| file =~ pattern }
|
85
97
|
files.reject! { |file| file =~ %r{/test/} }
|
98
|
+
|
86
99
|
FileTree.new(files, strip_prefix: path)
|
87
100
|
end
|
88
101
|
end
|
data/lib/spoom/git.rb
CHANGED
@@ -14,11 +14,12 @@ module Spoom
|
|
14
14
|
return "", "Error: `#{path}` is not a directory.", false unless File.directory?(path)
|
15
15
|
opts = {}
|
16
16
|
opts[:chdir] = path
|
17
|
-
|
17
|
+
i, o, e, s = Open3.popen3(*T.unsafe([command, *T.unsafe(arg), opts]))
|
18
18
|
out = o.read.to_s
|
19
19
|
o.close
|
20
20
|
err = e.read.to_s
|
21
21
|
e.close
|
22
|
+
i.close
|
22
23
|
[out, err, T.cast(s.value, Process::Status).success?]
|
23
24
|
end
|
24
25
|
|
@@ -49,6 +50,13 @@ module Spoom
|
|
49
50
|
exec("git show #{arg.join(' ')}", path: path)
|
50
51
|
end
|
51
52
|
|
53
|
+
sig { params(path: String).returns(T.nilable(String)) }
|
54
|
+
def self.current_branch(path: ".")
|
55
|
+
out, _, status = exec("git branch --show-current", path: path)
|
56
|
+
return nil unless status
|
57
|
+
out.strip
|
58
|
+
end
|
59
|
+
|
52
60
|
# Utils
|
53
61
|
|
54
62
|
# Get the commit epoch timestamp for a `sha`
|
@@ -92,7 +100,19 @@ module Spoom
|
|
92
100
|
def self.sorbet_intro_commit(path: ".")
|
93
101
|
res, _, status = Spoom::Git.log("--diff-filter=A --format='%h' -1 -- sorbet/config", path: path)
|
94
102
|
return nil unless status
|
95
|
-
res.strip
|
103
|
+
res.strip!
|
104
|
+
return nil if res.empty?
|
105
|
+
res
|
106
|
+
end
|
107
|
+
|
108
|
+
# Get the hash of the commit removing the `sorbet/config` file
|
109
|
+
sig { params(path: String).returns(T.nilable(String)) }
|
110
|
+
def self.sorbet_removal_commit(path: ".")
|
111
|
+
res, _, status = Spoom::Git.log("--diff-filter=D --format='%h' -1 -- sorbet/config", path: path)
|
112
|
+
return nil unless status
|
113
|
+
res.strip!
|
114
|
+
return nil if res.empty?
|
115
|
+
res
|
96
116
|
end
|
97
117
|
end
|
98
118
|
end
|
data/lib/spoom/sorbet/config.rb
CHANGED
@@ -29,11 +29,15 @@ module Spoom
|
|
29
29
|
sig { returns(T::Array[String]) }
|
30
30
|
attr_reader :paths, :ignore, :allowed_extensions
|
31
31
|
|
32
|
+
sig { returns(T::Boolean) }
|
33
|
+
attr_accessor :no_stdlib
|
34
|
+
|
32
35
|
sig { void }
|
33
36
|
def initialize
|
34
37
|
@paths = T.let([], T::Array[String])
|
35
38
|
@ignore = T.let([], T::Array[String])
|
36
39
|
@allowed_extensions = T.let([], T::Array[String])
|
40
|
+
@no_stdlib = T.let(false, T::Boolean)
|
37
41
|
end
|
38
42
|
|
39
43
|
sig { returns(Config) }
|
@@ -42,6 +46,7 @@ module Spoom
|
|
42
46
|
new_config.paths.concat(@paths)
|
43
47
|
new_config.ignore.concat(@ignore)
|
44
48
|
new_config.allowed_extensions.concat(@allowed_extensions)
|
49
|
+
new_config.no_stdlib = @no_stdlib
|
45
50
|
new_config
|
46
51
|
end
|
47
52
|
|
@@ -63,6 +68,7 @@ module Spoom
|
|
63
68
|
opts.concat(paths)
|
64
69
|
opts.concat(ignore.map { |p| "--ignore #{p}" })
|
65
70
|
opts.concat(allowed_extensions.map { |ext| "--allowed-extension #{ext}" })
|
71
|
+
opts << "--no-stdlib" if @no_stdlib
|
66
72
|
opts.join(" ")
|
67
73
|
end
|
68
74
|
|
@@ -106,12 +112,19 @@ module Spoom
|
|
106
112
|
when /^--dir=/
|
107
113
|
config.paths << parse_option(line)
|
108
114
|
next
|
115
|
+
when /^--no-stdlib$/
|
116
|
+
config.no_stdlib = true
|
117
|
+
next
|
109
118
|
when /^--.*=/
|
110
119
|
next
|
111
120
|
when /^--/
|
112
121
|
state = :skip
|
113
122
|
when /^-.*=?/
|
114
123
|
next
|
124
|
+
when /^#/
|
125
|
+
next
|
126
|
+
when /^$/
|
127
|
+
next
|
115
128
|
else
|
116
129
|
case state
|
117
130
|
when :ignore
|
data/lib/spoom/sorbet/sigils.rb
CHANGED
@@ -55,7 +55,7 @@ module Spoom
|
|
55
55
|
# * returns nil if no sigil
|
56
56
|
sig { params(path: T.any(String, Pathname)).returns(T.nilable(String)) }
|
57
57
|
def self.file_strictness(path)
|
58
|
-
return nil unless File.
|
58
|
+
return nil unless File.file?(path)
|
59
59
|
content = File.read(path, encoding: Encoding::ASCII_8BIT)
|
60
60
|
strictness_in_content(content)
|
61
61
|
end
|
@@ -100,6 +100,16 @@ module Spoom
|
|
100
100
|
FileUtils.rm_rf(path)
|
101
101
|
end
|
102
102
|
|
103
|
+
sig { params(name: String).void }
|
104
|
+
def create_and_checkout_branch(name)
|
105
|
+
Spoom::Git.exec("git checkout -b #{name}", path: path)
|
106
|
+
end
|
107
|
+
|
108
|
+
sig { returns(T.nilable(String)) }
|
109
|
+
def current_branch
|
110
|
+
Spoom::Git.current_branch(path: path)
|
111
|
+
end
|
112
|
+
|
103
113
|
private
|
104
114
|
|
105
115
|
# Create an absolute path from `self.path` and `rel_path`
|
data/lib/spoom/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spoom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Terrasa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.10
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.10
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: sorbet
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.5.
|
75
|
+
version: 0.5.6347
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.5.
|
82
|
+
version: 0.5.6347
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: thor
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
174
|
- !ruby/object:Gem::Version
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
|
-
rubygems_version: 3.
|
177
|
+
rubygems_version: 3.2.20
|
178
178
|
signing_key:
|
179
179
|
specification_version: 4
|
180
180
|
summary: Useful tools for Sorbet enthusiasts.
|