spoom 1.8.2 → 1.8.3

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: 9bf4851363229baee651a7eba14d9f45464db177f094f3b4da791a8b06b82d39
4
- data.tar.gz: 6aae091a64fb4cb9a55cea3b82307bd413e544c424bd160599eee48cfeefa1e0
3
+ metadata.gz: a2abc815d0eba3a4297d4ee83c8aeb6cfa8e70bcd734785e6db51e109692cb5b
4
+ data.tar.gz: 7c27a7d39af33be7c307cc1055ee8ad1930a3781a32fd6e44de50e936fc84ac2
5
5
  SHA512:
6
- metadata.gz: ac5bbdffd2be7bb1c8c795eff3e8c332212fd19f033805076af2eee3c11d39ac1d614927dda68997498ed2dc96d929b71c865b7b2f5babbf52283085a807f1c9
7
- data.tar.gz: 86d82cbeb9b56c7d4046c474e1880fb25c3dd32522a88f39fd3c0bb697b81d17641a4a5a7ac1603bcf319f18d513d429bbaea0ad1653cd29433ad51b0c9da195
6
+ metadata.gz: 063b6a30843d0a49533a0ae4c797370bd685e71f82887e0ed28d471a95944ff88e45602078a9b847c284cc4a447f7578c98c364b9340f4e06318701517aeb93d
7
+ data.tar.gz: fdcdc43a27d19ec879deb78fc9ad5fe817283444a35d8a3bc2ce027d3f3e9a704dd3780ef45138e062b7c6d83fb40f9c5291510a77dc90bf0f440c109091b927
@@ -3,6 +3,8 @@
3
3
 
4
4
  require "find"
5
5
  require "open3"
6
+ require "tempfile"
7
+ require "yaml"
6
8
 
7
9
  module Spoom
8
10
  module Cli
@@ -72,6 +74,11 @@ module Spoom
72
74
  exit(1)
73
75
  end
74
76
 
77
+ unless context.sorbet_config.typed_overrides.empty?
78
+ say_error("Cannot run `spoom bump` on a project that already uses Sorbet's `--typed-override` option")
79
+ exit(1)
80
+ end
81
+
75
82
  say("Checking files...")
76
83
 
77
84
  files_to_bump = context.srb_files_with_strictness(from, include_rbis: false)
@@ -90,18 +97,18 @@ module Spoom
90
97
  exit(0)
91
98
  end
92
99
 
93
- Sorbet::Sigils.change_sigil_in_files(files_to_bump, to)
94
-
95
100
  if force
101
+ Sorbet::Sigils.change_sigil_in_files(files_to_bump, to) unless dry
96
102
  print_changes(files_to_bump, command: cmd, from: from, to: to, dry: dry, path: exec_path)
97
- undo_changes(files_to_bump, from) if dry
98
103
  exit(files_to_bump.empty?)
99
104
  end
100
105
 
101
106
  error_url_base = Spoom::Sorbet::Errors::DEFAULT_ERROR_URL_BASE
107
+ typed_override_file = create_typed_override_file(context, files_to_bump, to)
102
108
  result = begin
103
109
  T.unsafe(context).srb_tc(
104
110
  *options[:sorbet_options].split(" "),
111
+ "--typed-override=#{T.must(typed_override_file.path)}",
105
112
  "--error-url-base=#{error_url_base}",
106
113
  capture_err: true,
107
114
  sorbet_bin: options[:sorbet],
@@ -114,7 +121,6 @@ module Spoom
114
121
  It means one of the file bumped to `typed: #{to}` made Sorbet crash.
115
122
  Run `spoom bump -f` locally followed by `bundle exec srb tc` to investigate the problem.
116
123
  ERR
117
- undo_changes(files_to_bump, from)
118
124
  exit(error.result.exit_code)
119
125
  rescue Spoom::Sorbet::Error::Killed => error
120
126
  say_error(<<~ERR, status: nil)
@@ -123,13 +129,14 @@ module Spoom
123
129
  It means Sorbet was killed while executing. Changes to files have not been applied.
124
130
  Re-run `spoom bump` to try again.
125
131
  ERR
126
- undo_changes(files_to_bump, from)
127
132
  exit(error.result.exit_code)
133
+ ensure
134
+ typed_override_file.close!
128
135
  end
129
136
 
130
137
  if result.status
138
+ Sorbet::Sigils.change_sigil_in_files(files_to_bump, to) unless dry
131
139
  print_changes(files_to_bump, command: cmd, from: from, to: to, dry: dry, path: exec_path)
132
- undo_changes(files_to_bump, from) if dry
133
140
  exit(files_to_bump.empty?)
134
141
  end
135
142
 
@@ -137,7 +144,6 @@ module Spoom
137
144
  # Sorbet will return exit code 100 if there are type checking errors.
138
145
  # If Sorbet returned something else, it means it didn't terminate normally.
139
146
  say_error(result.err, status: nil, nl: false)
140
- undo_changes(files_to_bump, from)
141
147
  exit(1)
142
148
  end
143
149
 
@@ -156,13 +162,11 @@ module Spoom
156
162
  path
157
163
  end.compact.uniq
158
164
 
159
- undo_changes(files_with_errors, from)
160
-
161
165
  say("Found #{errors.length} type checking error#{"s" if errors.length > 1}") if options[:count_errors]
162
166
 
163
167
  files_changed = files_to_bump - files_with_errors
168
+ Sorbet::Sigils.change_sigil_in_files(files_changed, to) unless dry
164
169
  print_changes(files_changed, command: cmd, from: from, to: to, dry: dry, path: exec_path)
165
- undo_changes(files_to_bump, from) if dry
166
170
  exit(files_changed.empty?)
167
171
  end
168
172
 
@@ -189,8 +193,16 @@ module Spoom
189
193
  end
190
194
  end
191
195
 
192
- def undo_changes(files, from_strictness)
193
- Sorbet::Sigils.change_sigil_in_files(files, from_strictness)
196
+ #: (Spoom::Context context, Array[String] files, String strictness) -> Tempfile
197
+ def create_typed_override_file(context, files, strictness)
198
+ relative_paths = files.map do |file|
199
+ relative_path = file.delete_prefix("#{context.absolute_path}/")
200
+ "./#{relative_path}"
201
+ end
202
+ typed_override_file = Tempfile.new(["spoom-typed-override", ".yml"])
203
+ typed_override_file.write(YAML.dump({ strictness => relative_paths }))
204
+ typed_override_file.flush
205
+ typed_override_file
194
206
  end
195
207
  end
196
208
  end
@@ -27,7 +27,7 @@ module Spoom
27
27
  DEFAULT_ALLOWED_EXTENSIONS = [".rb", ".rbi"].freeze #: Array[String]
28
28
 
29
29
  #: Array[String]
30
- attr_accessor :paths, :ignore, :allowed_extensions
30
+ attr_accessor :paths, :ignore, :allowed_extensions, :typed_overrides
31
31
 
32
32
  #: bool
33
33
  attr_accessor :no_stdlib
@@ -37,6 +37,7 @@ module Spoom
37
37
  @paths = [] #: Array[String]
38
38
  @ignore = [] #: Array[String]
39
39
  @allowed_extensions = [] #: Array[String]
40
+ @typed_overrides = [] #: Array[String]
40
41
  @no_stdlib = false #: bool
41
42
  end
42
43
 
@@ -46,6 +47,7 @@ module Spoom
46
47
  @paths = @paths.dup
47
48
  @ignore = @ignore.dup
48
49
  @allowed_extensions = @allowed_extensions.dup
50
+ @typed_overrides = @typed_overrides.dup
49
51
  end
50
52
 
51
53
  # Returns self as a string of options that can be passed to Sorbet
@@ -66,6 +68,7 @@ module Spoom
66
68
  opts.concat(paths.map { |p| "'#{p}'" })
67
69
  opts.concat(ignore.map { |p| "--ignore '#{p}'" })
68
70
  opts.concat(allowed_extensions.map { |ext| "--allowed-extension '#{ext}'" })
71
+ opts.concat(typed_overrides.map { |path| "--typed-override '#{path}'" })
69
72
  opts << "--no-stdlib" if @no_stdlib
70
73
  opts.join(" ")
71
74
  end
@@ -95,6 +98,12 @@ module Spoom
95
98
  when /^--ignore=/
96
99
  config.ignore << parse_option(line)
97
100
  next
101
+ when /^--typed-override$/
102
+ state = :typed_override
103
+ next
104
+ when /^--typed-override=/
105
+ config.typed_overrides << parse_option(line)
106
+ next
98
107
  when /^--file$/
99
108
  next
100
109
  when /^--file=/
@@ -124,6 +133,8 @@ module Spoom
124
133
  config.ignore << line
125
134
  when :extension
126
135
  config.allowed_extensions << line
136
+ when :typed_override
137
+ config.typed_overrides << line
127
138
  when :skip
128
139
  # nothing
129
140
  else
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.8.2"
5
+ VERSION = "1.8.3"
6
6
  end
data/rbi/spoom.rbi CHANGED
@@ -126,9 +126,11 @@ class Spoom::Cli::Srb::Bump < ::Thor
126
126
  sig { params(directory: ::String).void }
127
127
  def bump(directory = T.unsafe(nil)); end
128
128
 
129
+ sig { params(context: ::Spoom::Context, files: T::Array[::String], strictness: ::String).returns(::Tempfile) }
130
+ def create_typed_override_file(context, files, strictness); end
131
+
129
132
  def help(command = T.unsafe(nil), subcommand = T.unsafe(nil)); end
130
133
  def print_changes(files, command:, from: T.unsafe(nil), to: T.unsafe(nil), dry: T.unsafe(nil), path: T.unsafe(nil)); end
131
- def undo_changes(files, from_strictness); end
132
134
  end
133
135
 
134
136
  class Spoom::Cli::Srb::Coverage < ::Thor
@@ -2661,6 +2663,8 @@ class Spoom::Sorbet::Config
2661
2663
  def paths; end
2662
2664
 
2663
2665
  def paths=(_arg0); end
2666
+ def typed_overrides; end
2667
+ def typed_overrides=(_arg0); end
2664
2668
 
2665
2669
  private
2666
2670
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa