spoom 1.7.14 → 1.7.15

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: 7e36809d27f631413357c7b2287d7c51de3b8ed7d17ed7da03d4943bed071b23
4
- data.tar.gz: b299e3da2929b3a80b1466566e22b207ddceeab71f8ee98ccbc85d259f39fcf8
3
+ metadata.gz: '0726847d39f3461a3ac2998e8a84c235633275b9f15549e7ecaa24730496e12a'
4
+ data.tar.gz: a21f1fc2df2b4b9467d59c676aea601b733711709895daa47f80d8af5543f301
5
5
  SHA512:
6
- metadata.gz: c39b635f9e3b26ca6bfa42ae4d89758d83e7f5c06bc4b7e263dae5f6b3b3debd7845e6cf90fdf54b854b1a8019957bc662dc36a05f2e560f6bb7e65a0dc224ba
7
- data.tar.gz: f1ec06e214fc1f98ceb3915d659fe745951515e2edbd16219ebe1f77cb4d3ab79a28409b352dc35f92f9c9dbe85dcf176e696d7b1d48eae7bd665f21f12f997e
6
+ metadata.gz: 625897a0c781818fefa36d6bf2c49c9674300d162e54d939e53b3b2e4b128d9dd97674c5418364e018e1cc01513ac664048191a9fdeda0667b7c41218815688c
7
+ data.tar.gz: 8b269cb7ec6f258e4403f83993609985078fba2512d7d96fc89ad8d63522cd2913e30019edb1ae2e7b7aeaf2f4476c6d5141cc4aa594ca317db04a7cb975d4b0
@@ -213,8 +213,10 @@ module Spoom
213
213
  contents = contents.force_encoding(encoding)
214
214
  end
215
215
 
216
- contents = block.call(file, contents)
217
- File.write(file, contents)
216
+ new_contents = block.call(file, contents)
217
+ next if new_contents == contents
218
+
219
+ File.write(file, new_contents)
218
220
  transformed_count += 1
219
221
  rescue RBI::Error => error
220
222
  say_warning("Can't parse #{file}: #{error.message}")
@@ -10,12 +10,16 @@ module Spoom
10
10
  #: -> String?
11
11
  def read_gemfile
12
12
  read("Gemfile")
13
+ rescue Errno::ENOENT, Errno::EACCES
14
+ nil
13
15
  end
14
16
 
15
17
  # Read the contents of the Gemfile.lock in this context directory
16
18
  #: -> String?
17
19
  def read_gemfile_lock
18
20
  read("Gemfile.lock")
21
+ rescue Errno::ENOENT, Errno::EACCES
22
+ nil
19
23
  end
20
24
 
21
25
  # Set the `contents` of the Gemfile in this context directory
@@ -45,9 +49,10 @@ module Spoom
45
49
 
46
50
  #: -> Hash[String, Bundler::LazySpecification]
47
51
  def gemfile_lock_specs
48
- return {} unless file?("Gemfile.lock")
52
+ lockfile = read_gemfile_lock
53
+ return {} unless lockfile
49
54
 
50
- parser = Bundler::LockfileParser.new(read_gemfile_lock)
55
+ parser = Bundler::LockfileParser.new(lockfile)
51
56
  parser.specs.to_h { |spec| [spec.name, spec] }
52
57
  end
53
58
 
@@ -42,10 +42,15 @@ module Spoom
42
42
  sorbet_bin: sorbet_bin,
43
43
  capture_err: capture_err,
44
44
  )
45
- return unless file?(metrics_file)
46
45
 
47
46
  metrics_path = absolute_path_to(metrics_file)
48
- metrics = Spoom::Sorbet::Metrics::MetricsFileParser.parse_file(metrics_path)
47
+
48
+ begin
49
+ metrics = Spoom::Sorbet::Metrics::MetricsFileParser.parse_file(metrics_path)
50
+ rescue Errno::ENOENT, Errno::EACCES
51
+ return
52
+ end
53
+
49
54
  remove!(metrics_file)
50
55
  metrics
51
56
  end
@@ -33,11 +33,17 @@ module Spoom
33
33
 
34
34
  return if excluded_path?(path)
35
35
 
36
- if File.file?(path)
36
+ begin
37
+ stat = File.stat(path)
38
+ rescue Errno::ENOENT, Errno::EACCES
39
+ return
40
+ end
41
+
42
+ if stat.file?
37
43
  visit_file(path)
38
- elsif File.directory?(path)
44
+ elsif stat.directory?
39
45
  visit_directory(path)
40
- else # rubocop:disable Style/EmptyElse
46
+ else
41
47
  # Ignore aliases, sockets, etc.
42
48
  end
43
49
  end
@@ -10,6 +10,7 @@ module Spoom
10
10
  DEFAULT_PREFIX = "ruby_typer.unknown."
11
11
 
12
12
  class << self
13
+ # Raises if `path` doesn't point to a valid file that we have access to (see `File.read` for details)
13
14
  #: (String path, ?String prefix) -> Hash[String, Integer]
14
15
  def parse_file(path, prefix = DEFAULT_PREFIX)
15
16
  parse_string(File.read(path), prefix)
@@ -44,6 +44,13 @@ module Spoom
44
44
  SIGIL_REGEXP.match(content)&.[](1)
45
45
  end
46
46
 
47
+ # returns true if the passed content contains a valid sigil
48
+ #: (String content) -> bool
49
+ def contains_valid_sigil?(content)
50
+ strictness = strictness_in_content(content)
51
+ !!strictness && valid_strictness?(strictness)
52
+ end
53
+
47
54
  # returns a string which is the passed content but with the sigil updated to a new strictness
48
55
  #: (String content, String new_strictness) -> String
49
56
  def update_sigil(content, new_strictness)
@@ -7,6 +7,33 @@ module Spoom
7
7
  class RBSCommentsToSorbetSigs < Translator
8
8
  include Spoom::RBS::ExtractRBSComments
9
9
 
10
+ RBS_ANNOTATION_MARKERS = [
11
+ "# @abstract",
12
+ "# @interface",
13
+ "# @sealed",
14
+ "# @final",
15
+ "# @requires_ancestor:",
16
+ "# @override",
17
+ "# @overridable",
18
+ "# @without_runtime",
19
+ ].freeze #: Array[String]
20
+ RBS_REWRITE_PATTERN = Regexp.union(["#:", "#|", *RBS_ANNOTATION_MARKERS]).freeze #: Regexp
21
+ private_constant :RBS_ANNOTATION_MARKERS, :RBS_REWRITE_PATTERN
22
+
23
+ class << self
24
+ #: (String source) -> bool
25
+ def contains_rbs_syntax?(source)
26
+ Sigils.contains_valid_sigil?(source) && source.match?(RBS_REWRITE_PATTERN)
27
+ end
28
+
29
+ #: (String ruby_contents, file: String, ?max_line_length: Integer?) -> String
30
+ def rewrite_if_needed(ruby_contents, file:, max_line_length: nil)
31
+ return ruby_contents unless contains_rbs_syntax?(ruby_contents)
32
+
33
+ new(ruby_contents, file:, max_line_length:).rewrite
34
+ end
35
+ end
36
+
10
37
  #: (String, file: String, ?max_line_length: Integer?) -> void
11
38
  def initialize(ruby_contents, file:, max_line_length: nil)
12
39
  super(ruby_contents, file: file)
@@ -55,7 +55,7 @@ module Spoom
55
55
  # It also handles type members and class annotations.
56
56
  #: (String ruby_contents, file: String, ?max_line_length: Integer?) -> String
57
57
  def rbs_comments_to_sorbet_sigs(ruby_contents, file:, max_line_length: nil)
58
- RBSCommentsToSorbetSigs.new(ruby_contents, file: file, max_line_length: max_line_length).rewrite
58
+ RBSCommentsToSorbetSigs.rewrite_if_needed(ruby_contents, file: file, max_line_length: max_line_length)
59
59
  end
60
60
 
61
61
  # Converts all `T.let` and `T.cast` nodes to RBS comments in the given Ruby code.
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.7.14"
5
+ VERSION = "1.7.15"
6
6
  end
data/rbi/spoom.rbi CHANGED
@@ -2823,6 +2823,9 @@ module Spoom::Sorbet::Sigils
2823
2823
  sig { params(path_list: T::Array[::String], new_strictness: ::String).returns(T::Array[::String]) }
2824
2824
  def change_sigil_in_files(path_list, new_strictness); end
2825
2825
 
2826
+ sig { params(content: ::String).returns(T::Boolean) }
2827
+ def contains_valid_sigil?(content); end
2828
+
2826
2829
  sig { params(path: T.any(::Pathname, ::String)).returns(T.nilable(::String)) }
2827
2830
  def file_strictness(path); end
2828
2831
 
@@ -2938,8 +2941,19 @@ class Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs < ::Spoom::Sorbet::Trans
2938
2941
 
2939
2942
  sig { params(node: ::Prism::CallNode).void }
2940
2943
  def visit_attr(node); end
2944
+
2945
+ class << self
2946
+ sig { params(source: ::String).returns(T::Boolean) }
2947
+ def contains_rbs_syntax?(source); end
2948
+
2949
+ sig { params(ruby_contents: ::String, file: ::String, max_line_length: T.nilable(::Integer)).returns(::String) }
2950
+ def rewrite_if_needed(ruby_contents, file:, max_line_length: T.unsafe(nil)); end
2951
+ end
2941
2952
  end
2942
2953
 
2954
+ Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs::RBS_ANNOTATION_MARKERS = T.let(T.unsafe(nil), Array)
2955
+ Spoom::Sorbet::Translate::RBSCommentsToSorbetSigs::RBS_REWRITE_PATTERN = T.let(T.unsafe(nil), Regexp)
2956
+
2943
2957
  class Spoom::Sorbet::Translate::SorbetAssertionsToRBSComments < ::Spoom::Sorbet::Translate::Translator
2944
2958
  sig do
2945
2959
  params(
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.7.14
4
+ version: 1.7.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa