spoom 1.3.3 → 1.4.0

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: e839292b23e8582e1e7b4317c6431de9b7d59e68b2c4dbb4015f75619a995601
4
- data.tar.gz: 4853e7e2df4398e635e616df0f7354b8d37c67bef76ed12a0ec6efc16de1edc0
3
+ metadata.gz: d5092fe76b8efe0ff767f07a12a7f3d7510712f5a1272a215a9dacf52a79d4e7
4
+ data.tar.gz: 9240cb7c29a3c97fa7ce3acb052ed1f1fc68694430e911940e98374e2797c70b
5
5
  SHA512:
6
- metadata.gz: 940d6b9ec69c6eb767a1ccf2fc33767e552080010f94b14a77301f66b57a113f0619efb1e3ca357b04af782b3d9cbe07ff81f349adb814aef8c4d3fc8ea65de1
7
- data.tar.gz: 7de4600f896698ea578887b0f417fd9a7f31d3689e6b69e514905b671197c62abf5f232c9471b364f0e4c3509c81848a7ca08d09c73c4cba4cba036963e34192
6
+ metadata.gz: 926cef525dd3377f34f3c75d52d61eb3db48c046a15976f26f54b895ac9a66a3fd56a603f406c14a4c78746ac7869ae2a19d4904f46859027acf34daf2949f41
7
+ data.tar.gz: 317ef71ab107c477d02faf49f9e1f01a38c28231c9d945a66471624e942b6a4ae31f5fec2f05abf1d58aec97a3f5803a4b8f1044a49c9863b8ebe11237f4007e
@@ -8,7 +8,7 @@ module Spoom
8
8
  extend T::Sig
9
9
 
10
10
  ignore_classes_inheriting_from("ActiveModel::EachValidator")
11
- ignore_methods_named("validate_each")
11
+ ignore_methods_named("validate_each", "persisted?")
12
12
 
13
13
  sig { override.params(send: Send).void }
14
14
  def on_send(send)
@@ -7,21 +7,39 @@ module Spoom
7
7
  class Minitest < Base
8
8
  extend T::Sig
9
9
 
10
- ignore_classes_named(/Test$/)
11
-
12
- ignore_methods_named(
13
- "after_all",
14
- "around",
15
- "around_all",
16
- "before_all",
17
- "setup",
18
- "teardown",
10
+ ignore_classes_inheriting_from("Minitest::Test")
11
+
12
+ MINITEST_METHODS = T.let(
13
+ Set.new([
14
+ "after_all",
15
+ "around",
16
+ "around_all",
17
+ "before_all",
18
+ "setup",
19
+ "teardown",
20
+ ]),
21
+ T::Set[String],
19
22
  )
20
23
 
21
24
  sig { override.params(definition: Model::Method).void }
22
25
  def on_define_method(definition)
23
- file = definition.location.file
24
- @index.ignore(definition) if file.match?(%r{test/.*test\.rb$}) && definition.name.match?(/^test_/)
26
+ return unless definition.name.start_with?("test_") || MINITEST_METHODS.include?(definition.name)
27
+
28
+ owner = definition.owner
29
+ return unless owner.is_a?(Model::Class)
30
+
31
+ @index.ignore(definition) if ignored_subclass?(owner)
32
+ end
33
+
34
+ sig { override.params(send: Send).void }
35
+ def on_send(send)
36
+ case send.name
37
+ when "assert_predicate", "refute_predicate"
38
+ name = send.args[1]&.slice
39
+ return unless name
40
+
41
+ @index.reference_method(name.delete_prefix(":"), send.location)
42
+ end
25
43
  end
26
44
  end
27
45
  end
@@ -15,42 +15,73 @@ module Spoom
15
15
  sig { params(location_string: String).returns(Location) }
16
16
  def from_string(location_string)
17
17
  file, rest = location_string.split(":", 2)
18
- raise LocationError, "Invalid location string: #{location_string}" unless file && rest
18
+ raise LocationError, "Invalid location string `#{location_string}`: missing file name" unless file
19
+
20
+ return new(file) if rest.nil?
19
21
 
20
22
  start_line, rest = rest.split(":", 2)
21
- raise LocationError, "Invalid location string: #{location_string}" unless start_line && rest
23
+ if rest.nil?
24
+ start_line, end_line = T.must(start_line).split("-", 2)
25
+ raise LocationError, "Invalid location string `#{location_string}`: missing end line" unless end_line
26
+
27
+ return new(file, start_line: start_line.to_i, end_line: end_line.to_i) if end_line
28
+ end
22
29
 
23
30
  start_column, rest = rest.split("-", 2)
24
- raise LocationError, "Invalid location string: #{location_string}" unless start_column && rest
31
+ raise LocationError, "Invalid location string `#{location_string}`: missing end line and column" if rest.nil?
25
32
 
26
33
  end_line, end_column = rest.split(":", 2)
27
- raise LocationError, "Invalid location string: #{location_string}" unless end_line && end_column
28
-
29
- new(file, start_line.to_i, start_column.to_i, end_line.to_i, end_column.to_i)
34
+ raise LocationError,
35
+ "Invalid location string `#{location_string}`: missing end column" unless end_line && end_column
36
+
37
+ new(
38
+ file,
39
+ start_line: start_line.to_i,
40
+ start_column: start_column.to_i,
41
+ end_line: end_line.to_i,
42
+ end_column: end_column.to_i,
43
+ )
30
44
  end
31
45
 
32
46
  sig { params(file: String, location: Prism::Location).returns(Location) }
33
47
  def from_prism(file, location)
34
- new(file, location.start_line, location.start_column, location.end_line, location.end_column)
48
+ new(
49
+ file,
50
+ start_line: location.start_line,
51
+ start_column: location.start_column,
52
+ end_line: location.end_line,
53
+ end_column: location.end_column,
54
+ )
35
55
  end
36
56
  end
37
57
 
38
58
  sig { returns(String) }
39
59
  attr_reader :file
40
60
 
41
- sig { returns(Integer) }
61
+ sig { returns(T.nilable(Integer)) }
42
62
  attr_reader :start_line, :start_column, :end_line, :end_column
43
63
 
44
64
  sig do
45
65
  params(
46
66
  file: String,
47
- start_line: Integer,
48
- start_column: Integer,
49
- end_line: Integer,
50
- end_column: Integer,
67
+ start_line: T.nilable(Integer),
68
+ start_column: T.nilable(Integer),
69
+ end_line: T.nilable(Integer),
70
+ end_column: T.nilable(Integer),
51
71
  ).void
52
72
  end
53
- def initialize(file, start_line, start_column, end_line, end_column)
73
+ def initialize(file, start_line: nil, start_column: nil, end_line: nil, end_column: nil)
74
+ raise LocationError,
75
+ "Invalid location: end line is required if start line is provided" if start_line && !end_line
76
+ raise LocationError,
77
+ "Invalid location: start line is required if end line is provided" if !start_line && end_line
78
+ raise LocationError,
79
+ "Invalid location: end column is required if start column is provided" if start_column && !end_column
80
+ raise LocationError,
81
+ "Invalid location: start column is required if end column is provided" if !start_column && end_column
82
+ raise LocationError,
83
+ "Invalid location: lines are required if columns are provided" if start_column && !start_line
84
+
54
85
  @file = file
55
86
  @start_line = start_line
56
87
  @start_column = start_column
@@ -61,10 +92,12 @@ module Spoom
61
92
  sig { params(other: Location).returns(T::Boolean) }
62
93
  def include?(other)
63
94
  return false unless @file == other.file
64
- return false if @start_line > other.start_line
65
- return false if @start_line == other.start_line && @start_column > other.start_column
66
- return false if @end_line < other.end_line
67
- return false if @end_line == other.end_line && @end_column < other.end_column
95
+ return false if (@start_line || -Float::INFINITY) > (other.start_line || -Float::INFINITY)
96
+ return false if @start_line == other.start_line &&
97
+ (@start_column || -Float::INFINITY) > (other.start_column || -Float::INFINITY)
98
+ return false if (@end_line || Float::INFINITY) < (other.end_line || Float::INFINITY)
99
+ return false if @end_line == other.end_line &&
100
+ (@end_column || Float::INFINITY) < (other.end_column || Float::INFINITY)
68
101
 
69
102
  true
70
103
  end
@@ -73,12 +106,34 @@ module Spoom
73
106
  def <=>(other)
74
107
  return unless Location === other
75
108
 
76
- to_s <=> other.to_s
109
+ comparison_array_self = [
110
+ @file,
111
+ @start_line || -Float::INFINITY,
112
+ @start_column || -Float::INFINITY,
113
+ @end_line || Float::INFINITY,
114
+ @end_column || Float::INFINITY,
115
+ ]
116
+
117
+ comparison_array_other = [
118
+ other.file,
119
+ other.start_line || -Float::INFINITY,
120
+ other.start_column || -Float::INFINITY,
121
+ other.end_line || Float::INFINITY,
122
+ other.end_column || Float::INFINITY,
123
+ ]
124
+
125
+ comparison_array_self <=> comparison_array_other
77
126
  end
78
127
 
79
128
  sig { returns(String) }
80
129
  def to_s
81
- "#{@file}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}"
130
+ if @start_line && @start_column
131
+ "#{@file}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}"
132
+ elsif @start_line
133
+ "#{@file}:#{@start_line}-#{@end_line}"
134
+ else
135
+ @file
136
+ end
82
137
  end
83
138
  end
84
139
  end
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.3.3"
5
+ VERSION = "1.4.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-09 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.19.2
125
- description:
125
+ description:
126
126
  email:
127
127
  - ruby@shopify.com
128
128
  executables:
@@ -218,7 +218,7 @@ licenses:
218
218
  - MIT
219
219
  metadata:
220
220
  allowed_push_host: https://rubygems.org
221
- post_install_message:
221
+ post_install_message:
222
222
  rdoc_options: []
223
223
  require_paths:
224
224
  - lib
@@ -233,8 +233,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
235
  requirements: []
236
- rubygems_version: 3.5.14
237
- signing_key:
236
+ rubygems_version: 3.5.3
237
+ signing_key:
238
238
  specification_version: 4
239
239
  summary: Useful tools for Sorbet enthusiasts.
240
240
  test_files: []