rubocop-on-rbs 2.0.0 → 2.1.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/config/default.yml +2 -0
  4. data/lib/rubocop/cop/rbs/layout/annotation_indentation.rb +2 -1
  5. data/lib/rubocop/cop/rbs/layout/comment_indentation.rb +1 -1
  6. data/lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb +3 -2
  7. data/lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb +8 -0
  8. data/lib/rubocop/cop/rbs/layout/end_alignment.rb +2 -1
  9. data/lib/rubocop/cop/rbs/layout/extra_spacing.rb +1 -0
  10. data/lib/rubocop/cop/rbs/layout/indentation_width.rb +17 -2
  11. data/lib/rubocop/cop/rbs/layout/overload_indentation.rb +7 -5
  12. data/lib/rubocop/cop/rbs/layout/space_after_comma.rb +1 -0
  13. data/lib/rubocop/cop/rbs/layout/space_around_arrow.rb +4 -2
  14. data/lib/rubocop/cop/rbs/layout/space_around_braces.rb +6 -3
  15. data/lib/rubocop/cop/rbs/layout/space_before_colon.rb +1 -1
  16. data/lib/rubocop/cop/rbs/lint/ambiguous_keyword_argument_key.rb +3 -2
  17. data/lib/rubocop/cop/rbs/lint/ambiguous_operator_precedence.rb +2 -0
  18. data/lib/rubocop/cop/rbs/lint/duplicate_annotation.rb +2 -0
  19. data/lib/rubocop/cop/rbs/lint/duplicate_overload.rb +3 -2
  20. data/lib/rubocop/cop/rbs/lint/new_returns_void.rb +0 -2
  21. data/lib/rubocop/cop/rbs/lint/top_level_interface.rb +6 -4
  22. data/lib/rubocop/cop/rbs/lint/top_level_type_alias.rb +6 -4
  23. data/lib/rubocop/cop/rbs/lint/useless_access_modifier.rb +3 -3
  24. data/lib/rubocop/cop/rbs/style/class_with_singleton.rb +0 -1
  25. data/lib/rubocop/cop/rbs/style/classic_type.rb +6 -5
  26. data/lib/rubocop/cop/rbs/style/instance_with_instance.rb +0 -1
  27. data/lib/rubocop/cop/rbs/style/optional_nil.rb +1 -1
  28. data/lib/rubocop/cop/rbs/style/redundant_parentheses.rb +18 -5
  29. data/lib/rubocop/cop/rbs/style/true_false.rb +1 -1
  30. data/lib/rubocop/rbs/cop_base.rb +29 -1
  31. data/lib/rubocop/rbs/on_type_helper.rb +2 -0
  32. data/lib/rubocop/rbs/processed_rbs_source.rb +10 -5
  33. data/lib/rubocop/rbs/version.rb +1 -1
  34. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b6d2d8d5f69d9af653de61ac795ed71d7ce63663c65450dd842e4c1816c69f
4
- data.tar.gz: e81e32efe74897317c3eb4183cfb11e6e65b0bcaa04345261787dfc29eb92741
3
+ metadata.gz: 43791277046bd585b3979b68148eb004aa7212cbcdd5301f7d5001915cf20b8a
4
+ data.tar.gz: b261814ee8ff54554e351e018c688821df1fff4b1bc78c9b6440df53e8db2029
5
5
  SHA512:
6
- metadata.gz: 6f7a1fdceb0841f976a3cfe4147e9f17e43e13447702314e03747bbd0565f945615f23e952d7ffd08ba7dd00c46f34b2d5bfcd7d8692d94eaf901d528c776cd1
7
- data.tar.gz: f0949c448ec168f168b4d4c2b723670bac8e2dade272e8b569533314c366e26b89b805860f455f49f5a3d1f06294a7ad0334baa8c878ab043459b2cbf22c115f
6
+ metadata.gz: 0a2e89869da1c6353ba2cf7baec53629244a69538f94e0ae6523cae22165fd4775f78d5bbfd7a0925ce2b992567b256e73a956306d8c0022b599db89f67e092b
7
+ data.tar.gz: 53fea77b783bd0a3f53a2c59129e2cae7161c78c923cda78ce0ea7875e1a8ed53a2923df8aa438bb1143f3d0bfbfda410f6ab3c3ef0be1ca378664f7679b511c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.1.0] - 2026-09-27
4
+
5
+ * Drop support for Ruby v3.2 by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/153
6
+ * [RBS/Layout/IndentationWidth] Support `Width` option by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/157
7
+
3
8
  ## [2.0.0] - 2026-03-27
4
9
 
5
10
  * Support rbs v4 by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/145
data/config/default.yml CHANGED
@@ -77,6 +77,8 @@ RBS/Layout/ExtraSpacing:
77
77
  RBS/Layout/IndentationWidth:
78
78
  Description: 'Use 2 spaces for indentation'
79
79
  Enabled: true
80
+ # Number of spaces for each indentation level.
81
+ Width: 2
80
82
 
81
83
  RBS/Layout/OverloadIndentation:
82
84
  Description: 'Indent overload method'
@@ -35,7 +35,8 @@ module RuboCop
35
35
  when ::RBS::AST::Members::MethodDefinition
36
36
  member.overloads.each do |overload|
37
37
  overload.annotations.each do |annotation|
38
- ignore_poses << annotation.location.start_pos
38
+ location = annotation.location or next
39
+ ignore_poses << location.start_pos
39
40
  end
40
41
  end
41
42
  end
@@ -46,7 +46,7 @@ module RuboCop
46
46
 
47
47
  def line_after_comment(comment)
48
48
  lines = processed_source.lines
49
- lines[comment.location.start_line..].find { |line| !line.blank? }
49
+ lines[comment.location.start_line..]&.find { |line| !line.blank? }
50
50
  end
51
51
 
52
52
  def correct_indentation(next_line)
@@ -29,8 +29,9 @@ module RuboCop
29
29
  MSG = 'Keep a blank line before and after `<%<kind>s>`.'
30
30
 
31
31
  def on_rbs_class(decl)
32
- @class_or_module_def_first_line = decl.location.start_line
33
- @class_or_module_def_last_line = decl.location.end_line
32
+ location = decl.location or return
33
+ @class_or_module_def_first_line = location.start_line
34
+ @class_or_module_def_last_line = location.end_line
34
35
  end
35
36
  alias on_rbs_module on_rbs_class
36
37
 
@@ -4,11 +4,14 @@ module RuboCop
4
4
  module Cop
5
5
  module RBS
6
6
  module Layout
7
+ # @rbs module-self: RuboCop::RBS::CopBase
7
8
  module EmptyLinesAroundBody
8
9
  MSG_EXTRA = 'Extra empty line detected at %<kind>s body %<location>s.'
9
10
 
10
11
  private
11
12
 
13
+ # Main endpoint
14
+ #: (untyped decl) -> void
12
15
  def check(decl)
13
16
  first_line = decl.location.start_line
14
17
  last_line = decl.location.end_line
@@ -18,14 +21,19 @@ module RuboCop
18
21
  check_ending(last_line)
19
22
  end
20
23
 
24
+ # Check line after `class/module/interface`
25
+ #: (Integer first_line) -> void
21
26
  def check_beginning(first_line)
22
27
  check_source(first_line, 'beginning')
23
28
  end
24
29
 
30
+ # Check line before `end`
31
+ #: (Integer last_line) -> void
25
32
  def check_ending(last_line)
26
33
  check_source(last_line - 2, 'end')
27
34
  end
28
35
 
36
+ #: (Integer line_no, untyped desc) -> void
29
37
  def check_source(line_no, desc)
30
38
  return unless line_no.positive?
31
39
  return unless processed_source.lines[line_no]
@@ -42,7 +42,8 @@ module RuboCop
42
42
  end_loc = decl.location[:end]
43
43
  actual = end_loc.start_column
44
44
  if actual != expect
45
- line_start_pos = processed_source.raw_source.rindex(/\R/, end_loc.start_pos) + 1
45
+ newline_pos = processed_source.raw_source.rindex(/\R/, end_loc.start_pos) or return
46
+ line_start_pos = newline_pos + 1
46
47
  range = range_between(end_loc.start_pos, end_loc.end_pos)
47
48
  source = decl.location.source.each_line.first.strip
48
49
  message = "`end` at #{end_loc.start_line}, #{end_loc.start_column} is not aligned with " \
@@ -38,6 +38,7 @@ module RuboCop
38
38
  end
39
39
  end
40
40
 
41
+ #: () -> ::Set[Integer]
41
42
  def aligned_locations
42
43
  comments = processed_rbs_source.tokens.select(&:comment?)
43
44
  Set.new.tap do |aligned|
@@ -6,7 +6,7 @@ module RuboCop
6
6
  module Layout
7
7
  # Checks if the indentation width.
8
8
  #
9
- # @example
9
+ # @example Width: 2 (default)
10
10
  # # bad
11
11
  # class Foo
12
12
  # def foo: () -> void
@@ -17,6 +17,17 @@ module RuboCop
17
17
  # def foo: () -> void
18
18
  # end
19
19
  #
20
+ # @example Width: 4
21
+ # # bad
22
+ # class Foo
23
+ # def foo: () -> void
24
+ # end
25
+ #
26
+ # # good
27
+ # class Foo
28
+ # def foo: () -> void
29
+ # end
30
+ #
20
31
  class IndentationWidth < RuboCop::RBS::CopBase
21
32
  extend AutoCorrector
22
33
 
@@ -33,7 +44,7 @@ module RuboCop
33
44
  if decl.respond_to?(:members)
34
45
  check(decl, expect: expect)
35
46
  decl.members.each do |member|
36
- check_indentation(member, expect: expect + 2)
47
+ check_indentation(member, expect: expect + configured_indentation_width)
37
48
  end
38
49
  else
39
50
  check(decl, expect: expect)
@@ -52,6 +63,10 @@ module RuboCop
52
63
  end
53
64
  end
54
65
 
66
+ def configured_indentation_width
67
+ cop_config['Width'] || 2
68
+ end
69
+
55
70
  def line_start_pos(decl)
56
71
  rindex = processed_source.raw_source.rindex(/\R/, decl.location.start_pos)
57
72
  if rindex
@@ -26,11 +26,13 @@ module RuboCop
26
26
  extend AutoCorrector
27
27
 
28
28
  def on_rbs_def(decl)
29
- base_pos = decl.location.start_pos
30
- base_col = decl.location.start_column
31
- overload_starts = decl.overloads.map { |overload| overload.method_type.location.start_pos }
32
- tokens = ::RBS::Parser.lex(decl.location.source).value.reject { |t| t.type == :tTRIVIA }
33
- first_colon_column = base_col + tokens.find { |t| t.type == :pCOLON }&.location&.start_column
29
+ location = decl.location or return
30
+ base_pos = location.start_pos
31
+ base_col = location.start_column
32
+ overload_starts = decl.overloads.filter_map { |overload| overload.method_type.location&.start_pos }
33
+ tokens = ::RBS::Parser.lex(location.source).value.reject { |t| t.type == :tTRIVIA }
34
+ colon_column = tokens.find { |t| t.type == :pCOLON }&.location&.start_column or return
35
+ first_colon_column = base_col + colon_column
34
36
  ([nil] + tokens).each_cons(3) do |before, bar, after|
35
37
  next unless before
36
38
  next unless bar
@@ -20,6 +20,7 @@ module RuboCop
20
20
 
21
21
  def on_rbs_new_investigation
22
22
  processed_rbs_source.tokens.each_cons(2) do |comma, after|
23
+ next unless comma && after
23
24
  next unless comma.type == :pCOMMA
24
25
  next unless comma.location
25
26
  next unless comma.location.end_line == after.location.start_line
@@ -27,13 +27,15 @@ module RuboCop
27
27
 
28
28
  # @sig decl: ::RBS::AST::Members::MethodDefinition
29
29
  def on_rbs_def(decl)
30
- base = decl.location.start_pos
31
- tokens = ::RBS::Parser.lex(decl.location.source).value.reject { |t| t.type == :tTRIVIA }
30
+ location = decl.location or return
31
+ base = location.start_pos
32
+ tokens = ::RBS::Parser.lex(location.source).value.reject { |t| t.type == :tTRIVIA }
32
33
  ([nil] + tokens).each_cons(3) do |before, token, after|
33
34
  next unless token&.type == :pARROW
34
35
 
35
36
  loc = token&.location
36
37
  next unless loc
38
+ next unless after
37
39
 
38
40
  if before && (before.location.end_pos + 1 != loc.start_pos)
39
41
  next unless before.location.end_line == loc.start_line
@@ -18,9 +18,12 @@ module RuboCop
18
18
 
19
19
  # @sig decl: ::RBS::AST::Members::MethodDefinition
20
20
  def on_rbs_def(decl)
21
+ location = decl.location or return
21
22
  paren_level = 0
22
- tokens = ::RBS::Parser.lex(decl.location.source).value.reject { |t| t.type == :tTRIVIA }
23
+ tokens = ::RBS::Parser.lex(location.source).value.reject { |t| t.type == :tTRIVIA }
23
24
  ([nil] + tokens).each_cons(3) do |before, token, after|
25
+ next unless token && after
26
+
24
27
  case token.type
25
28
  when :pLPAREN # '('
26
29
  paren_level += 1
@@ -31,12 +34,12 @@ module RuboCop
31
34
  next unless (after.type == :pLPAREN || after.type == :pARROW)
32
35
  next unless paren_level == 0
33
36
 
34
- check_around_space(decl.location, before, token, after)
37
+ check_around_space(location, before, token, after)
35
38
  when :pRBRACE # '}'
36
39
  next unless after.type == :pARROW
37
40
  next unless paren_level == 0
38
41
 
39
- check_around_space(decl.location, before, token, after)
42
+ check_around_space(location, before, token, after)
40
43
  end
41
44
  end
42
45
  end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # @sig decl: ::RBS::AST::Members::MethodDefinition
19
19
  def on_rbs_def(decl)
20
20
  source = processed_source.raw_source
21
- loc = decl.location
21
+ loc = decl.location or return
22
22
  colon_start_pos = source.index(':', loc.start_pos)
23
23
  return unless colon_start_pos
24
24
 
@@ -20,8 +20,9 @@ module RuboCop
20
20
  next unless func.kind_of?(::RBS::Types::Function)
21
21
  next unless !func.required_keywords.empty? || !func.optional_keywords.empty?
22
22
 
23
- base_pos = overload.method_type.location.start_pos
24
- lex_result = ::RBS::Parser.lex(overload.method_type.location.source)
23
+ location = overload.method_type.location or next
24
+ base_pos = location.start_pos
25
+ lex_result = ::RBS::Parser.lex(location.source)
25
26
  buf = []
26
27
  lex_result.value.each do |token|
27
28
  case token.type
@@ -36,6 +36,8 @@ module RuboCop
36
36
 
37
37
  def check_type(type)
38
38
  on_type([::RBS::Types::Union], type) do |union|
39
+ next unless union.is_a?(::RBS::Types::Union)
40
+
39
41
  union.types.each do |t|
40
42
  case t
41
43
  when ::RBS::Types::Intersection
@@ -23,6 +23,7 @@ module RuboCop
23
23
  class DuplicateAnnotation < RuboCop::RBS::CopBase
24
24
  MSG = 'Duplicate annotation detected.'
25
25
 
26
+ #: (::RBS::AST::Members::MethodDefinition) -> void
26
27
  def on_rbs_def(decl)
27
28
  decl.annotations.each_with_index do |annotation, idx|
28
29
  next_annotations = decl.annotations[(idx + 1)..] or next
@@ -41,6 +42,7 @@ module RuboCop
41
42
  end
42
43
  end
43
44
 
45
+ #: (::RBS::AST::Annotation, Array[::RBS::AST::Annotation]) -> void
44
46
  def check_annotations(left_annotation, right_annotations)
45
47
  right_annotations.each do |right_annotation|
46
48
  next unless left_annotation == right_annotation
@@ -20,13 +20,14 @@ module RuboCop
20
20
  overloads.each_with_index do |overload, idx|
21
21
  next if idx == overloads.size - 1
22
22
 
23
- next_overloads = overloads[(idx + 1)..-1]
23
+ next_overloads = overloads[(idx + 1)..-1] or next
24
24
  next_overloads.each do |next_overload|
25
25
  a = method_type_with_untyped_return_type(overload.method_type)
26
26
  b = method_type_with_untyped_return_type(next_overload.method_type)
27
27
  next unless a == b
28
28
 
29
- range = location_to_range(next_overload.method_type.location)
29
+ location = next_overload.method_type.location or next
30
+ range = location_to_range(location)
30
31
  add_offense(range)
31
32
  end
32
33
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rbs_inline: enabled
4
-
5
3
  module RuboCop
6
4
  module Cop
7
5
  module RBS
@@ -27,17 +27,19 @@ module RuboCop
27
27
  end
28
28
 
29
29
  def on_rbs_class(decl)
30
- return unless @last_end_pos.nil? || (@last_end_pos < decl.location.end_pos)
30
+ location = decl.location or return
31
+ return unless @last_end_pos.nil? || (@last_end_pos < location.end_pos)
31
32
 
32
- @last_end_pos = decl.location.end_pos
33
+ @last_end_pos = location.end_pos
33
34
  end
34
35
  alias on_rbs_module on_rbs_class
35
36
 
36
37
  def on_rbs_interface(decl)
37
- return unless @last_end_pos.nil? || (@last_end_pos < decl.location.start_pos)
38
+ location = decl.location or return
39
+ return unless @last_end_pos.nil? || (@last_end_pos < location.start_pos)
38
40
  return unless decl.name.namespace.path.empty?
39
41
 
40
- range = location_to_range(decl.location)
42
+ range = location_to_range(location)
41
43
  add_offense(range)
42
44
  end
43
45
  end
@@ -23,18 +23,20 @@ module RuboCop
23
23
  end
24
24
 
25
25
  def on_rbs_class(decl)
26
- return unless @last_end_pos.nil? || (@last_end_pos < decl.location.end_pos)
26
+ location = decl.location or return
27
+ return unless @last_end_pos.nil? || (@last_end_pos < location.end_pos)
27
28
 
28
- @last_end_pos = decl.location.end_pos
29
+ @last_end_pos = location.end_pos
29
30
  end
30
31
  alias on_rbs_module on_rbs_class
31
32
  alias on_rbs_interface on_rbs_class
32
33
 
33
34
  def on_rbs_type_alias(decl)
34
- return unless @last_end_pos.nil? || (@last_end_pos < decl.location.start_pos)
35
+ location = decl.location or return
36
+ return unless @last_end_pos.nil? || (@last_end_pos < location.start_pos)
35
37
  return unless decl.name.namespace.path.empty?
36
38
 
37
- range = location_to_range(decl.location)
39
+ range = location_to_range(location)
38
40
  add_offense(range)
39
41
  end
40
42
  end
@@ -42,7 +42,7 @@ module RuboCop
42
42
  MSG = 'Useless `%<current>s` access modifier.'
43
43
 
44
44
  def on_rbs_class(decl)
45
- current = nil
45
+ current = nil #: ::RBS::AST::Members::Public | ::RBS::AST::Members::Private | nil
46
46
  unused = true
47
47
  decl.members.each do |member|
48
48
  next unless member.location
@@ -71,8 +71,8 @@ module RuboCop
71
71
  end
72
72
  end
73
73
 
74
- if unused && current
75
- range = location_to_range(current.location)
74
+ if unused && current && (location = current.location)
75
+ range = location_to_range(location)
76
76
  vis = case current
77
77
  when ::RBS::AST::Members::Public
78
78
  'public'
@@ -1,4 +1,3 @@
1
- # rbs_inline: enabled
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -20,7 +20,7 @@ module RuboCop
20
20
  class ClassicType < RuboCop::RBS::CopBase
21
21
  extend AutoCorrector
22
22
 
23
- Types = ::RBS::Types
23
+ Types = ::RBS::Types #: module-alias
24
24
 
25
25
  def on_rbs_def(decl)
26
26
  decl.overloads.each do |overload|
@@ -38,7 +38,7 @@ module RuboCop
38
38
  alias on_rbs_attribute on_rbs_constant
39
39
  alias on_rbs_var on_rbs_constant
40
40
 
41
- # @rbs type: ::RBS::Types::t
41
+ #: (::RBS::Types::t type) -> untyped
42
42
  def check_type(type)
43
43
  find_replacement(type) do |t, replaced|
44
44
  range = location_to_range(t.location)
@@ -48,6 +48,7 @@ module RuboCop
48
48
  end
49
49
  end
50
50
 
51
+ #: (::RBS::Types::t type) ?{ ([::RBS::Types::t, String]) -> untyped } -> untyped
51
52
  def find_replacement(type, &block)
52
53
  case type
53
54
  when Types::Record,
@@ -64,11 +65,11 @@ module RuboCop
64
65
  when Types::ClassInstance
65
66
  case type.name.to_s
66
67
  when 'TrueClass', '::TrueClass'
67
- block.call([type, 'true'])
68
+ block&.call([type, 'true'])
68
69
  when 'FalseClass', '::FalseClass'
69
- block.call([type, 'false'])
70
+ block&.call([type, 'false'])
70
71
  when 'NilClass', '::NilClass'
71
- block.call([type, 'nil'])
72
+ block&.call([type, 'nil'])
72
73
  end
73
74
  type.each_type do |arg|
74
75
  find_replacement(arg, &block)
@@ -1,4 +1,3 @@
1
- # rbs_inline: enabled
2
1
  # frozen_string_literal: true
3
2
 
4
3
  module RuboCop
@@ -46,7 +46,7 @@ module RuboCop
46
46
  when ::RBS::Types::Optional
47
47
  case type.type
48
48
  when ::RBS::Types::Bases::Nil
49
- block.call([type, ::RBS::Types::Bases::Nil.new(location: nil)])
49
+ block&.call([type, ::RBS::Types::Bases::Nil.new(location: nil)])
50
50
  else
51
51
  find_replacement(type.type, &block)
52
52
  end
@@ -52,6 +52,13 @@ module RuboCop
52
52
 
53
53
  attr_reader :processed_source
54
54
 
55
+ # @rbs processed_source: RuboCop::AST::ProcessedSource
56
+ # @rbs base: Integer
57
+ # @rbs tokens: Array[::RBS::Parser::Token]
58
+ # @rbs type: ::RBS::Types::t
59
+ # @rbs skip: Set[Integer]
60
+ # @rbs cop: RuboCop::RBS::CopBase
61
+ # @rbs return: void
55
62
  def initialize(processed_source:, base:, tokens:, type:, skip:, cop:)
56
63
  @processed_source = processed_source
57
64
  @base = base
@@ -63,6 +70,8 @@ module RuboCop
63
70
 
64
71
  def check
65
72
  @cop.on_type([::RBS::Types::Proc], @type) do |proc_type|
73
+ next unless proc_type.is_a?(::RBS::Types::Proc)
74
+
66
75
  before_token_if_lparen(@tokens, @base, proc_type.type) do |b|
67
76
  @skip << (b.location.start_pos + @base)
68
77
  end
@@ -86,7 +95,9 @@ module RuboCop
86
95
  case type.type.literal
87
96
  when Symbol
88
97
  # Skip optional with symbol literal (e.g. `(:sym)?`)
89
- @skip << type.location.start_pos
98
+ if (location = type.location)
99
+ @skip << location.start_pos
100
+ end
90
101
  end
91
102
  end
92
103
  end
@@ -122,8 +133,9 @@ module RuboCop
122
133
  extend AutoCorrector
123
134
 
124
135
  def on_rbs_def(decl)
125
- base = decl.location.start_pos
126
- tokens = tokenize(decl.location.source)
136
+ location = decl.location or return
137
+ base = location.start_pos
138
+ tokens = tokenize(location.source)
127
139
  skip = Set.new
128
140
  decl.overloads.each do |overload|
129
141
  before_token_if_lparen(tokens, base, overload.method_type.type) do |b|
@@ -152,9 +164,10 @@ module RuboCop
152
164
  end
153
165
 
154
166
  def on_rbs_constant(const)
155
- tokens = tokenize(const.location.source)
167
+ location = const.location or return
168
+ tokens = tokenize(location.source)
156
169
  type = const.type
157
- base = const.location.start_pos
170
+ base = location.start_pos
158
171
  check_type(tokens:, type:, base:)
159
172
  end
160
173
  alias on_rbs_global on_rbs_constant
@@ -82,7 +82,7 @@ module RuboCop
82
82
  end
83
83
  end
84
84
  replaced.insert(first_index || 0, ::RBS::Types::Bases::Bool.new(location: nil))
85
- block.call([type, ::RBS::Types::Union.new(types: replaced, location: nil)])
85
+ block&.call([type, ::RBS::Types::Union.new(types: replaced, location: nil)])
86
86
  end
87
87
  else
88
88
  type.each_type do |type|
@@ -9,7 +9,7 @@ module RuboCop
9
9
  include RuboCop::Cop::RangeHelp
10
10
  include RuboCop::RBS::OnTypeHelper
11
11
 
12
- attr_reader :processed_rbs_source
12
+ attr_reader :processed_rbs_source #: RuboCop::RBS::ProcessedRBSSource
13
13
 
14
14
  exclude_from_registry
15
15
 
@@ -34,6 +34,7 @@ module RuboCop
34
34
  @processed_rbs_source = RuboCop::RBS::ProcessedRBSSource.new(buffer)
35
35
  end
36
36
 
37
+ #: () -> void
37
38
  def investigation_rbs
38
39
  return unless processed_source.buffer.name.then { |n| n.end_with?(".rbs") || n == "(string)" }
39
40
 
@@ -65,22 +66,47 @@ module RuboCop
65
66
  end
66
67
  end
67
68
 
69
+ #: () -> void
68
70
  def on_rbs_new_investigation; end
71
+
72
+ #: () -> void
69
73
  def on_rbs_parsing_error; end
70
74
 
71
75
  # other on_* methods should sync with `#walk` method
76
+ #: (::RBS::AST::Declarations::Class) -> void
72
77
  def on_rbs_class(member); end
78
+
79
+ #: (::RBS::AST::Declarations::Module) -> void
73
80
  def on_rbs_module(member); end
81
+
82
+ #: (::RBS::AST::Declarations::Interface) -> void
74
83
  def on_rbs_interface(member); end
84
+
85
+ #: (::RBS::AST::Declarations::Constant) -> void
75
86
  def on_rbs_constant(const); end
87
+
88
+ #: (::RBS::AST::Declarations::Global) -> void
76
89
  def on_rbs_global(global); end
90
+
91
+ #: (::RBS::AST::Declarations::TypeAlias) -> void
77
92
  def on_rbs_type_alias(decl); end
93
+
94
+ #: (::RBS::AST::Members::MethodDefinition) -> void
78
95
  def on_rbs_def(member); end
96
+
97
+ #: (::RBS::AST::Members::Attribute) -> void
79
98
  def on_rbs_attribute(member); end
99
+
100
+ #: (::RBS::AST::Members::Public) -> void
80
101
  def on_rbs_public(member); end
102
+
103
+ #: (::RBS::AST::Members::Private) -> void
81
104
  def on_rbs_private(member); end
105
+
106
+ #: (::RBS::AST::Members::Var) -> void
82
107
  def on_rbs_var(member); end
83
108
 
109
+ #: (untyped) -> void
84
110
  def walk(decl)
85
111
  case decl
86
112
  when ::RBS::AST::Declarations::Module
@@ -111,6 +137,7 @@ module RuboCop
111
137
  end
112
138
  end
113
139
 
140
+ #: () -> ::RBS::Buffer
114
141
  def rbs_buffer
115
142
  ::RBS::Buffer.new(
116
143
  name: processed_source.buffer.name,
@@ -118,6 +145,7 @@ module RuboCop
118
145
  )
119
146
  end
120
147
 
148
+ #: (::RBS::Location[untyped, untyped]) -> Parser::Source::Range
121
149
  def location_to_range(location)
122
150
  range_between(location.start_pos, location.end_pos)
123
151
  end
@@ -3,6 +3,7 @@
3
3
  module RuboCop
4
4
  module RBS
5
5
  module OnTypeHelper
6
+ #: (Array[Class] types, ::RBS::Types::t type) { (::RBS::Types::t t) -> void } -> void
6
7
  def on_type(types, type, &block)
7
8
  case type
8
9
  when *types
@@ -13,6 +14,7 @@ module RuboCop
13
14
  end
14
15
  end
15
16
 
17
+ #: (Array[Class] types, ::RBS::Types::t type) { (::RBS::Types::t t) -> void } -> void
16
18
  def on_not_type(types, type, &block)
17
19
  case type
18
20
  when *types
@@ -2,14 +2,18 @@
2
2
 
3
3
  module RuboCop
4
4
  module RBS
5
+ # Fake for RuboCop::ProcessedSource
5
6
  class ProcessedRBSSource
6
- attr_reader :raw_source
7
+ # @rbs @tokens: ::Array[::RBS::Parser::Token]?
8
+
9
+ attr_reader :raw_source #: String
7
10
  attr_reader :source
8
- attr_reader :buffer
9
- attr_reader :directives
10
- attr_reader :decls
11
- attr_reader :error
11
+ attr_reader :buffer #: ::RBS::Buffer
12
+ attr_reader :directives #: ::Array[::RBS::AST::Directives::t]
13
+ attr_reader :decls #: ::Array[::RBS::AST::Declarations::t]
14
+ attr_reader :error #: ::RBS::ParsingError?
12
15
 
16
+ #: (::RBS::Buffer source) -> void
13
17
  def initialize(source)
14
18
  @raw_source = source.content
15
19
  @buffer, @directives, @decls = ::RBS::Parser.parse_signature(source)
@@ -23,6 +27,7 @@ module RuboCop
23
27
  @error.nil?
24
28
  end
25
29
 
30
+ #: () -> ::Array[::RBS::Parser::Token]
26
31
  def tokens
27
32
  @tokens ||= ::RBS::Parser.lex(buffer).value
28
33
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module RBS
5
- VERSION = '2.0.0'
5
+ VERSION = '2.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-on-rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
@@ -152,14 +152,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - ">="
154
154
  - !ruby/object:Gem::Version
155
- version: 3.2.0
155
+ version: 3.3.0
156
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 4.0.3
162
+ rubygems_version: 4.0.10
163
163
  specification_version: 4
164
164
  summary: RuboCop extension for RBS file.
165
165
  test_files: []