spoom 1.1.1 → 1.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b209723354af5be10930893accb559ecbb62afc1469d2d8a12f7a7af44d67d6c
4
- data.tar.gz: 4bd2e43681783fceb004e5595218127b5838b5e09c47800c6d4d0905566e42f0
3
+ metadata.gz: 526b44a6bb1b2ec6b8b09a3bec42264f86b2803c561c4862d622c374893d529a
4
+ data.tar.gz: ac616a998a9800706ca28d805d5e975b35e78fb4c0b725463938b4b925f24728
5
5
  SHA512:
6
- metadata.gz: 99e8cccc29317edb58b84ba3a5713dfbfcf44c97bea40d2b4f30c256460983da7698847ea6fd9fc5a8c58c1aa6cb716e626a4540ac3e60302822b2d17efb194c
7
- data.tar.gz: 055571522e43f963a1ee79a1cbd138d10d8ca685a252e5bfc64fc696abbf1812ae796bef764ab2d95359d1236012fe6cc45cfc48074997273f30df02e018a8b1
6
+ metadata.gz: c6cf08eb1fe7d880e8dfae54352d554b83c41ff6878546b84d986fdbb17fa95244b1630f31aa0f1ccd14ef843dc71d80bd3236715d16165c7c1a0a6fc7271502
7
+ data.tar.gz: ea376f188b1a33a83784f4e7923ba4087cd2891f10deacf998b145c724f586f76e2cfda338011f50d7990b8b860720eb832f365c5a6541042453d3381e45c871
@@ -102,6 +102,7 @@ module Spoom
102
102
  path = File.expand_path(err.file)
103
103
  next unless path.start_with?(directory)
104
104
  next unless File.file?(path)
105
+ next unless files_to_bump.include?(path)
105
106
  path
106
107
  end.compact.uniq
107
108
 
@@ -133,7 +134,7 @@ module Spoom
133
134
  if dry && command
134
135
  say("\nRun `#{command}` to bump them")
135
136
  elsif dry
136
- say("\nRun `spoom bump --from #{from} --to #{to}` to bump them")
137
+ say("\nRun `spoom bump --from #{from} --to #{to}` locally then `commit the changes` and `push them`")
137
138
  end
138
139
  end
139
140
 
@@ -44,8 +44,9 @@ module Spoom
44
44
  path = exec_path
45
45
  sorbet = options[:sorbet]
46
46
 
47
- sha_before = Spoom::Git.last_commit(path: path)
48
- unless sha_before
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.with_clean_env do
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(sha_before, path: path)
111
+ Spoom::Git.checkout(ref_before, path: path)
111
112
  end
112
113
 
113
114
  desc "report", "Produce a typing coverage report"
@@ -9,7 +9,11 @@ module Spoom
9
9
  module Cli
10
10
  module Helper
11
11
  extend T::Sig
12
- include Thor::Shell
12
+ extend T::Helpers
13
+
14
+ include Colorize
15
+
16
+ requires_ancestor { Thor }
13
17
 
14
18
  # Print `message` on `$stdout`
15
19
  sig { params(message: String).void }
@@ -66,7 +70,7 @@ module Spoom
66
70
  # Return the path specified through `--path`
67
71
  sig { returns(String) }
68
72
  def exec_path
69
- T.unsafe(self).options[:path] # TODO: requires_ancestor
73
+ options[:path]
70
74
  end
71
75
 
72
76
  sig { returns(String) }
@@ -82,12 +86,12 @@ module Spoom
82
86
  # Colors
83
87
 
84
88
  # Color used to highlight expressions in backticks
85
- HIGHLIGHT_COLOR = :blue
89
+ HIGHLIGHT_COLOR = T.let(Spoom::Color::BLUE, Spoom::Color)
86
90
 
87
91
  # Is the `--color` option true?
88
92
  sig { returns(T::Boolean) }
89
93
  def color?
90
- T.unsafe(self).options[:color] # TODO: requires_ancestor
94
+ options[:color]
91
95
  end
92
96
 
93
97
  sig { params(string: String).returns(String) }
@@ -114,35 +118,35 @@ module Spoom
114
118
  end
115
119
 
116
120
  # Colorize a string if `color?`
117
- sig { params(string: String, color: Symbol).returns(String) }
118
- def colorize(string, color)
121
+ sig { params(string: String, color: Color).returns(String) }
122
+ def colorize(string, *color)
119
123
  return string unless color?
120
- string.colorize(color)
124
+ T.unsafe(self).set_color(string, *color)
121
125
  end
122
126
 
123
127
  sig { params(string: String).returns(String) }
124
128
  def blue(string)
125
- colorize(string, :blue)
129
+ colorize(string, Color::BLUE)
126
130
  end
127
131
 
128
132
  sig { params(string: String).returns(String) }
129
133
  def gray(string)
130
- colorize(string, :light_black)
134
+ colorize(string, Color::LIGHT_BLACK)
131
135
  end
132
136
 
133
137
  sig { params(string: String).returns(String) }
134
138
  def green(string)
135
- colorize(string, :green)
139
+ colorize(string, Color::GREEN)
136
140
  end
137
141
 
138
142
  sig { params(string: String).returns(String) }
139
143
  def red(string)
140
- colorize(string, :red)
144
+ colorize(string, Color::RED)
141
145
  end
142
146
 
143
147
  sig { params(string: String).returns(String) }
144
148
  def yellow(string)
145
- colorize(string, :yellow)
149
+ colorize(string, Color::YELLOW)
146
150
  end
147
151
  end
148
152
  end
@@ -0,0 +1,45 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Spoom
5
+ class Color < T::Enum
6
+ extend T::Sig
7
+
8
+ enums do
9
+ CLEAR = new("\e[0m")
10
+ BOLD = new("\e[1m")
11
+
12
+ BLACK = new("\e[30m")
13
+ RED = new("\e[31m")
14
+ GREEN = new("\e[32m")
15
+ YELLOW = new("\e[33m")
16
+ BLUE = new("\e[34m")
17
+ MAGENTA = new("\e[35m")
18
+ CYAN = new("\e[36m")
19
+ WHITE = new("\e[37m")
20
+
21
+ LIGHT_BLACK = new("\e[90m")
22
+ LIGHT_RED = new("\e[91m")
23
+ LIGHT_GREEN = new("\e[92m")
24
+ LIGHT_YELLOW = new("\e[93m")
25
+ LIGHT_BLUE = new("\e[94m")
26
+ LIGHT_MAGENTA = new("\e[95m")
27
+ LIGHT_CYAN = new("\e[96m")
28
+ LIGHT_WHITE = new("\e[97m")
29
+ end
30
+
31
+ sig { returns(String) }
32
+ def ansi_code
33
+ serialize
34
+ end
35
+ end
36
+
37
+ module Colorize
38
+ extend T::Sig
39
+
40
+ sig { params(string: String, color: Color).returns(String) }
41
+ def set_color(string, *color)
42
+ "#{color.map(&:ansi_code).join}#{string}#{Color::CLEAR.ansi_code}"
43
+ end
44
+ end
45
+ end
@@ -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,
@@ -156,7 +156,7 @@ module Spoom
156
156
  end
157
157
  print("\n")
158
158
  else
159
- print_colored(node.name, :blue)
159
+ print_colored(node.name, Color::BLUE)
160
160
  print("/")
161
161
  printn
162
162
  indent
@@ -180,15 +180,15 @@ module Spoom
180
180
  Spoom::Sorbet::Sigils.file_strictness(path)
181
181
  end
182
182
 
183
- sig { params(strictness: T.nilable(String)).returns(Symbol) }
183
+ sig { params(strictness: T.nilable(String)).returns(Color) }
184
184
  def strictness_color(strictness)
185
185
  case strictness
186
186
  when "false"
187
- :red
187
+ Color::RED
188
188
  when "true", "strict", "strong"
189
- :green
189
+ Color::GREEN
190
190
  else
191
- :uncolored
191
+ Color::CLEAR
192
192
  end
193
193
  end
194
194
  end
data/lib/spoom/git.rb CHANGED
@@ -20,7 +20,7 @@ module Spoom
20
20
  err = e.read.to_s
21
21
  e.close
22
22
  i.close
23
- [out, err, T.cast(s.value, Process::Status).success?]
23
+ [out, err, s.value.success?]
24
24
  end
25
25
 
26
26
  # Git commands
@@ -50,6 +50,13 @@ module Spoom
50
50
  exec("git show #{arg.join(' ')}", path: path)
51
51
  end
52
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
+
53
60
  # Utils
54
61
 
55
62
  # Get the commit epoch timestamp for a `sha`
@@ -93,7 +100,19 @@ module Spoom
93
100
  def self.sorbet_intro_commit(path: ".")
94
101
  res, _, status = Spoom::Git.log("--diff-filter=A --format='%h' -1 -- sorbet/config", path: path)
95
102
  return nil unless status
96
- 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
97
116
  end
98
117
  end
99
118
  end
data/lib/spoom/printer.rb CHANGED
@@ -8,6 +8,8 @@ module Spoom
8
8
  extend T::Sig
9
9
  extend T::Helpers
10
10
 
11
+ include Colorize
12
+
11
13
  abstract!
12
14
 
13
15
  sig { returns(T.any(IO, StringIO)) }
@@ -42,11 +44,10 @@ module Spoom
42
44
  # Print `string` colored with `color` into `out`
43
45
  #
44
46
  # Does not use colors unless `@colors`.
45
- sig { params(string: T.nilable(String), color: Symbol, colors: Symbol).void }
46
- def print_colored(string, color, *colors)
47
+ sig { params(string: T.nilable(String), color: Color).void }
48
+ def print_colored(string, *color)
47
49
  return unless string
48
- string = colorize(string, color)
49
- colors.each { |c| string = colorize(string, c) }
50
+ string = T.unsafe(self).colorize(string, *color)
50
51
  @out.print(string)
51
52
  end
52
53
 
@@ -72,9 +73,10 @@ module Spoom
72
73
  end
73
74
 
74
75
  # Colorize `string` with color if `@colors`
75
- sig { params(string: String, color: Symbol).returns(String) }
76
- def colorize(string, color)
77
- @colors ? string.colorize(color) : string
76
+ sig { params(string: String, color: Spoom::Color).returns(String) }
77
+ def colorize(string, *color)
78
+ return string unless @colors
79
+ T.unsafe(self).set_color(string, *color)
78
80
  end
79
81
  end
80
82
  end
@@ -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
@@ -56,7 +56,7 @@ module Spoom
56
56
 
57
57
  sig { override.params(printer: SymbolPrinter).void }
58
58
  def accept_printer(printer)
59
- printer.print_colored("#{line}:#{char}", :light_black)
59
+ printer.print_colored("#{line}:#{char}", Color::LIGHT_BLACK)
60
60
  end
61
61
 
62
62
  def to_s
@@ -81,7 +81,7 @@ module Spoom
81
81
  sig { override.params(printer: SymbolPrinter).void }
82
82
  def accept_printer(printer)
83
83
  printer.print_object(start)
84
- printer.print_colored("-", :light_black)
84
+ printer.print_colored("-", Color::LIGHT_BLACK)
85
85
  printer.print_object(self.end)
86
86
  end
87
87
 
@@ -106,7 +106,7 @@ module Spoom
106
106
 
107
107
  sig { override.params(printer: SymbolPrinter).void }
108
108
  def accept_printer(printer)
109
- printer.print_colored("#{printer.clean_uri(uri)}:", :light_black)
109
+ printer.print_colored("#{printer.clean_uri(uri)}:", Color::LIGHT_BLACK)
110
110
  printer.print_object(range)
111
111
  end
112
112
 
@@ -203,14 +203,14 @@ module Spoom
203
203
  printer.printt
204
204
  printer.print(kind_string)
205
205
  printer.print(' ')
206
- printer.print_colored(name, :blue, :bold)
207
- printer.print_colored(' (', :light_black)
206
+ printer.print_colored(name, Color::BLUE, Color::BOLD)
207
+ printer.print_colored(' (', Color::LIGHT_BLACK)
208
208
  if range
209
209
  printer.print_object(range)
210
210
  elsif location
211
211
  printer.print_object(location)
212
212
  end
213
- printer.print_colored(')', :light_black)
213
+ printer.print_colored(')', Color::LIGHT_BLACK)
214
214
  printer.printn
215
215
  unless children.empty?
216
216
  printer.indent
@@ -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.exist?(path)
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
@@ -82,7 +82,7 @@ module Spoom
82
82
  opts = {}
83
83
  opts[:chdir] = path
84
84
  out, err, status = Open3.capture3("bundle", "install", opts)
85
- [out, err, status.success?]
85
+ [out, err, T.must(status.success?)]
86
86
  end
87
87
 
88
88
  # Run a command with `bundle exec` in this project
@@ -91,7 +91,7 @@ module Spoom
91
91
  opts = {}
92
92
  opts[:chdir] = path
93
93
  out, err, status = Open3.capture3(["bundle", "exec", cmd, *args].join(' '), opts)
94
- [out, err, status.success?]
94
+ [out, err, T.must(status.success?)]
95
95
  end
96
96
 
97
97
  # Delete this project and its content
@@ -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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Spoom
5
- VERSION = "1.1.1"
5
+ VERSION = "1.1.5"
6
6
  end
data/lib/spoom.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- require "colorize"
5
4
  require "sorbet-runtime"
6
5
 
7
6
  module Spoom
@@ -27,6 +26,7 @@ module Spoom
27
26
  end
28
27
  end
29
28
 
29
+ require "spoom/colors"
30
30
  require "spoom/sorbet"
31
31
  require "spoom/cli"
32
32
  require "spoom/version"
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.1.1
4
+ version: 1.1.5
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-05-04 00:00:00.000000000 Z
11
+ date: 2021-10-18 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: '1.17'
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: '1.17'
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.5.9204
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.5.9204
69
69
  - !ruby/object:Gem::Dependency
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.6347
75
+ version: 0.5.9204
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.6347
82
+ version: 0.5.9204
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: thor
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.19.2
97
- - !ruby/object:Gem::Dependency
98
- name: colorize
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
97
  description:
112
98
  email:
113
99
  - ruby@shopify.com
@@ -128,6 +114,7 @@ files:
128
114
  - lib/spoom/cli/helper.rb
129
115
  - lib/spoom/cli/lsp.rb
130
116
  - lib/spoom/cli/run.rb
117
+ - lib/spoom/colors.rb
131
118
  - lib/spoom/coverage.rb
132
119
  - lib/spoom/coverage/d3.rb
133
120
  - lib/spoom/coverage/d3/base.rb
@@ -174,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
161
  - !ruby/object:Gem::Version
175
162
  version: '0'
176
163
  requirements: []
177
- rubygems_version: 3.0.3
164
+ rubygems_version: 3.2.20
178
165
  signing_key:
179
166
  specification_version: 4
180
167
  summary: Useful tools for Sorbet enthusiasts.