spoom 1.7.13 → 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: 02432e9390507a5cc9072d83c3eaf7952d430fdb4329cf5e33e969513d21f58b
4
- data.tar.gz: 693d74660c7aa1faad796f5a948bb06302c1b8d62dc3855665ea1125cb0ee1fd
3
+ metadata.gz: '0726847d39f3461a3ac2998e8a84c235633275b9f15549e7ecaa24730496e12a'
4
+ data.tar.gz: a21f1fc2df2b4b9467d59c676aea601b733711709895daa47f80d8af5543f301
5
5
  SHA512:
6
- metadata.gz: 3f34e8b9207ed4b538ef2ca5450041aa62baede9429d295e4348b68008cfe3df43e7e0f626b6e41e872e808afebeabe34bcd33536c6e6520e053b5b9be43a76d
7
- data.tar.gz: b4e28008f5529e134664d250bd17f2934ed978045861031d9f4b9e5d13a4e7fbde24b86d07fbeca9e0e4e114a1e6bc07bf599efa4c0e1a5ee7ccfa322c57ab3b
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
@@ -13,35 +13,6 @@ module Spoom
13
13
  def accept_printer(printer) = raise NotImplementedError, "Abstract method called"
14
14
  end
15
15
 
16
- class Hover < T::Struct
17
- include PrintableSymbol
18
-
19
- const :contents, String
20
- const :range, T.nilable(Range)
21
-
22
- class << self
23
- #: (Hash[untyped, untyped] json) -> Hover
24
- def from_json(json)
25
- Hover.new(
26
- contents: json["contents"]["value"],
27
- range: json["range"] ? Range.from_json(json["range"]) : nil,
28
- )
29
- end
30
- end
31
-
32
- # @override
33
- #: (SymbolPrinter printer) -> void
34
- def accept_printer(printer)
35
- printer.print("#{contents}\n")
36
- printer.print_object(range) if range
37
- end
38
-
39
- #: -> String
40
- def to_s
41
- "#{contents} (#{range})."
42
- end
43
- end
44
-
45
16
  class Position < T::Struct
46
17
  include PrintableSymbol
47
18
 
@@ -100,6 +71,35 @@ module Spoom
100
71
  end
101
72
  end
102
73
 
74
+ class Hover < T::Struct
75
+ include PrintableSymbol
76
+
77
+ const :contents, String
78
+ const :range, T.nilable(Range)
79
+
80
+ class << self
81
+ #: (Hash[untyped, untyped] json) -> Hover
82
+ def from_json(json)
83
+ Hover.new(
84
+ contents: json["contents"]["value"],
85
+ range: json["range"] ? Range.from_json(json["range"]) : nil,
86
+ )
87
+ end
88
+ end
89
+
90
+ # @override
91
+ #: (SymbolPrinter printer) -> void
92
+ def accept_printer(printer)
93
+ printer.print("#{contents}\n")
94
+ printer.print_object(range) if range
95
+ end
96
+
97
+ #: -> String
98
+ def to_s
99
+ "#{contents} (#{range})."
100
+ end
101
+ end
102
+
103
103
  class Location < T::Struct
104
104
  include PrintableSymbol
105
105
 
@@ -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)
@@ -305,7 +305,7 @@ module Spoom
305
305
  end
306
306
 
307
307
  if sigs.any? { |_, sig| sig.is_overridable }
308
- @rewriter << Source::Insert.new(insert_pos, "# @overridable\n")
308
+ @rewriter << Source::Insert.new(insert_pos, "# @overridable\n#{indent}")
309
309
  end
310
310
  end
311
311
 
@@ -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.13"
5
+ VERSION = "1.7.15"
6
6
  end
data/rbi/spoom.rbi CHANGED
@@ -1836,7 +1836,7 @@ class Spoom::LSP::Hover < ::T::Struct
1836
1836
  include ::Spoom::LSP::PrintableSymbol
1837
1837
 
1838
1838
  const :contents, ::String
1839
- const :range, T.nilable(T::Range[T.untyped])
1839
+ const :range, T.nilable(::Spoom::LSP::Range)
1840
1840
 
1841
1841
  sig { override.params(printer: ::Spoom::LSP::SymbolPrinter).void }
1842
1842
  def accept_printer(printer); end
@@ -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.13
4
+ version: 1.7.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa