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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/config/default.yml +2 -0
- data/lib/rubocop/cop/rbs/layout/annotation_indentation.rb +2 -1
- data/lib/rubocop/cop/rbs/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_access_modifier.rb +3 -2
- data/lib/rubocop/cop/rbs/layout/empty_lines_around_body.rb +8 -0
- data/lib/rubocop/cop/rbs/layout/end_alignment.rb +2 -1
- data/lib/rubocop/cop/rbs/layout/extra_spacing.rb +1 -0
- data/lib/rubocop/cop/rbs/layout/indentation_width.rb +17 -2
- data/lib/rubocop/cop/rbs/layout/overload_indentation.rb +7 -5
- data/lib/rubocop/cop/rbs/layout/space_after_comma.rb +1 -0
- data/lib/rubocop/cop/rbs/layout/space_around_arrow.rb +4 -2
- data/lib/rubocop/cop/rbs/layout/space_around_braces.rb +6 -3
- data/lib/rubocop/cop/rbs/layout/space_before_colon.rb +1 -1
- data/lib/rubocop/cop/rbs/lint/ambiguous_keyword_argument_key.rb +3 -2
- data/lib/rubocop/cop/rbs/lint/ambiguous_operator_precedence.rb +2 -0
- data/lib/rubocop/cop/rbs/lint/duplicate_annotation.rb +2 -0
- data/lib/rubocop/cop/rbs/lint/duplicate_overload.rb +3 -2
- data/lib/rubocop/cop/rbs/lint/new_returns_void.rb +0 -2
- data/lib/rubocop/cop/rbs/lint/top_level_interface.rb +6 -4
- data/lib/rubocop/cop/rbs/lint/top_level_type_alias.rb +6 -4
- data/lib/rubocop/cop/rbs/lint/useless_access_modifier.rb +3 -3
- data/lib/rubocop/cop/rbs/style/class_with_singleton.rb +0 -1
- data/lib/rubocop/cop/rbs/style/classic_type.rb +6 -5
- data/lib/rubocop/cop/rbs/style/instance_with_instance.rb +0 -1
- data/lib/rubocop/cop/rbs/style/optional_nil.rb +1 -1
- data/lib/rubocop/cop/rbs/style/redundant_parentheses.rb +18 -5
- data/lib/rubocop/cop/rbs/style/true_false.rb +1 -1
- data/lib/rubocop/rbs/cop_base.rb +29 -1
- data/lib/rubocop/rbs/on_type_helper.rb +2 -0
- data/lib/rubocop/rbs/processed_rbs_source.rb +10 -5
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 43791277046bd585b3979b68148eb004aa7212cbcdd5301f7d5001915cf20b8a
|
|
4
|
+
data.tar.gz: b261814ee8ff54554e351e018c688821df1fff4b1bc78c9b6440df53e8db2029
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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..]
|
|
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
|
-
|
|
33
|
-
@
|
|
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
|
-
|
|
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 " \
|
|
@@ -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 +
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
24
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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
|
|
@@ -27,17 +27,19 @@ module RuboCop
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def on_rbs_class(decl)
|
|
30
|
-
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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'
|
|
@@ -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
|
-
|
|
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
|
|
68
|
+
block&.call([type, 'true'])
|
|
68
69
|
when 'FalseClass', '::FalseClass'
|
|
69
|
-
block
|
|
70
|
+
block&.call([type, 'false'])
|
|
70
71
|
when 'NilClass', '::NilClass'
|
|
71
|
-
block
|
|
72
|
+
block&.call([type, 'nil'])
|
|
72
73
|
end
|
|
73
74
|
type.each_type do |arg|
|
|
74
75
|
find_replacement(arg, &block)
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
167
|
+
location = const.location or return
|
|
168
|
+
tokens = tokenize(location.source)
|
|
156
169
|
type = const.type
|
|
157
|
-
base =
|
|
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
|
|
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|
|
data/lib/rubocop/rbs/cop_base.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/rubocop/rbs/version.rb
CHANGED
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.
|
|
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.
|
|
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.
|
|
162
|
+
rubygems_version: 4.0.10
|
|
163
163
|
specification_version: 4
|
|
164
164
|
summary: RuboCop extension for RBS file.
|
|
165
165
|
test_files: []
|