Skip to content

Commit d5f7426

Browse files
mickeytglmarcoroth
andauthored
Ruby: Re-enable Sorbet check (#465)
Now that Sorbet supports RBS aliases, this PR updates the Gemfile and modifies the files under `/lib` to fix any type errors raised by Sorbet Resolves #114 --------- Co-authored-by: Marco Roth <marco.roth@intergga.ch>
1 parent 59b29a3 commit d5f7426

File tree

27 files changed

+512
-226
lines changed

27 files changed

+512
-226
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ jobs:
5656
- name: Steep
5757
run: bundle exec steep check
5858

59+
- name: Sorbet
60+
run: bundle exec srb tc
61+
5962
- name: RBS Inline
6063
run: bundle exec rake rbs_inline
6164

62-
# - name: Sorbet
63-
# run: bundle exec srb tc
64-
6565
- name: clang-tidy version
6666
run: clang-tidy-21 --version
6767

lib/herb/ast/helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
module Herb
55
module AST
66
module Helpers
7-
#: (Herb::AST::Node) -> bool
7+
#: (Herb::AST::Node?) -> bool
88
def erb_outputs?(node)
99
return false unless node.is_a?(Herb::AST::ERBContentNode)
1010

11-
opening = node.tag_opening&.value
12-
opening&.include?("=") && !opening&.start_with?("<%#")
11+
opening = node.tag_opening&.value || ""
12+
opening.include?("=") && !opening.start_with?("<%#")
1313
end
1414

1515
#: (String) -> bool

lib/herb/ast/node.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
# typed: true
33

44
module Herb
5+
#: type serialized_node = {
6+
#| type: String,
7+
#| location: serialized_location?,
8+
#| errors: Array[serialized_error]
9+
#| }
510
module AST
611
class Node
712
attr_reader :type #: String
813
attr_reader :location #: Location
914
attr_reader :errors #: Array[Herb::Errors::Error]
1015

11-
#: (String, Location, Array[Herb::Errors::Error]) -> void
16+
#: (String, Location, ?Array[Herb::Errors::Error]) -> void
1217
def initialize(type, location, errors = [])
1318
@type = type
1419
@location = location
@@ -19,7 +24,7 @@ def initialize(type, location, errors = [])
1924
def to_hash
2025
{
2126
type: type,
22-
location: location&.to_hash,
27+
location: location.to_hash,
2328
errors: errors.map(&:to_hash),
2429
}
2530
end

lib/herb/engine.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
# typed: false
23

34
require "json"
45
require "time"

lib/herb/engine/debug_visitor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
# typed: false
23

34
module Herb
45
class Engine
@@ -31,6 +32,7 @@ def initialize(file_path: nil, project_path: nil)
3132
@in_html_comment = false
3233
@in_html_doctype = false
3334
@erb_nodes_to_wrap = [] #: Array[Herb::AST::ERBContentNode]
35+
@top_level_elements = [] #: Array[Herb::AST::HTMLElementNode]
3436
end
3537

3638
def visit_document_node(node)
@@ -149,8 +151,6 @@ def replace_erb_nodes_recursive(node)
149151
end
150152

151153
def find_top_level_elements(document_node)
152-
@top_level_elements = [] #: Array[Herb::AST::HTMLElementNode]
153-
154154
document_node.children.each do |child|
155155
@top_level_elements << child if child.is_a?(Herb::AST::HTMLElementNode)
156156
end

lib/herb/lex_result.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
# typed: true
23

34
module Herb
45
class LexResult < Result

lib/herb/location.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# typed: true
33

44
module Herb
5+
#: type serialized_location = {
6+
#| start: serialized_position,
7+
#| end: serialized_position
8+
#| }
59
class Location
610
attr_reader :start #: Position
711
attr_reader :end #: Position
@@ -28,9 +32,9 @@ def self.[](start_line, start_column, end_line, end_column)
2832
#: () -> serialized_location
2933
def to_hash
3034
{
31-
start: start,
32-
end: self.end,
33-
} #: Herb::serialized_location
35+
start: start.to_hash,
36+
end: self.end.to_hash,
37+
}
3438
end
3539

3640
#: (?untyped) -> String

lib/herb/parse_result.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
# typed: true
23

34
require "json"
45

lib/herb/position.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# typed: true
33

44
module Herb
5+
#: type serialized_position = { line: Integer, column: Integer }
56
class Position
67
attr_reader :line #: Integer
78
attr_reader :column #: Integer

lib/herb/range.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# typed: true
33

44
module Herb
5+
#: type serialized_range = [Integer, Integer]
56
class Range
67
attr_reader :from #: Integer
78
attr_reader :to #: Integer

0 commit comments

Comments
 (0)