rubocop-on-rbs 1.7.0 → 1.8.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/config/default.yml +8 -6
- data/lib/rubocop/cop/rbs/lint/duplicate_annotation.rb +57 -0
- data/lib/rubocop/cop/rbs/lint/duplicate_overload.rb +15 -5
- data/lib/rubocop/cop/rbs/lint/implicitly_returns_nil.rb +64 -0
- data/lib/rubocop/cop/rbs_cops.rb +2 -0
- data/lib/rubocop/rbs/cop_base.rb +6 -0
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f48492da2f7f96f52584db83f1ead670446908414b91ebf0a27a7d6ccb82c1e
|
4
|
+
data.tar.gz: c5374fcc49b860034ef0852e3a4d2a86c99867e96581033884116b707844c597
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fceeab927591e1507529a6b55d1b30f8b8bd7b5d700846777109a0e2b84c61380b5bee05d721d5eb5a08ffee4c184875d7956327c7feea6d469742c66f5affc7
|
7
|
+
data.tar.gz: 618f0de58a7bf00f68f0df67cca9d82da6723715af26eb1740211ab16bf53be66604782ec251fcbfdb313c933f30eb535e19f932b1d029fc462c8782189599a0
|
data/config/default.yml
CHANGED
@@ -26,8 +26,6 @@ RBS:
|
|
26
26
|
|
27
27
|
RBS/Layout:
|
28
28
|
Enabled: true
|
29
|
-
DocumentationBaseURL: 'https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages'
|
30
|
-
DocumentationExtension: '.adoc'
|
31
29
|
|
32
30
|
RBS/Layout/CommentIndentation:
|
33
31
|
Description: 'Use 2 spaces for comment indentation'
|
@@ -113,8 +111,6 @@ RBS/Layout/TrailingWhitespace:
|
|
113
111
|
RBS/Lint:
|
114
112
|
Severity: warning
|
115
113
|
Enabled: true
|
116
|
-
DocumentationBaseURL: 'https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages'
|
117
|
-
DocumentationExtension: '.adoc'
|
118
114
|
|
119
115
|
RBS/Lint/AmbiguousKeywordArgumentKey:
|
120
116
|
Description: 'Check ambiguous keyword argument key'
|
@@ -124,10 +120,18 @@ RBS/Lint/AmbiguousOperatorPrecedence:
|
|
124
120
|
Description: 'Check ambiguous operator precedence'
|
125
121
|
Enabled: true
|
126
122
|
|
123
|
+
RBS/Lint/DuplicateAnnotation:
|
124
|
+
Description: 'Checks that there are no repeated annotations'
|
125
|
+
Enabled: true
|
126
|
+
|
127
127
|
RBS/Lint/DuplicateOverload:
|
128
128
|
Description: 'Checks that there are no repeated overload bodies'
|
129
129
|
Enabled: true
|
130
130
|
|
131
|
+
RBS/Lint/ImplicitlyReturnsNil:
|
132
|
+
Description: 'Check implicitly returns nil'
|
133
|
+
Enabled: true
|
134
|
+
|
131
135
|
RBS/Lint/LiteralIntersection:
|
132
136
|
Description: 'Check literal intersection'
|
133
137
|
Enabled: true
|
@@ -176,8 +180,6 @@ RBS/Lint/WillSyntaxError:
|
|
176
180
|
|
177
181
|
RBS/Style:
|
178
182
|
Enabled: true
|
179
|
-
DocumentationBaseURL: 'https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages'
|
180
|
-
DocumentationExtension: '.adoc'
|
181
183
|
|
182
184
|
RBS/Style/BlockReturnBoolish:
|
183
185
|
Description: 'Use `bool` for block return type'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Lint
|
7
|
+
# Checks that there are no repeated annotations.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# def %a{foo} %a{foo} def foo: () -> void
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# def %a{foo} foo: %a{foo} () -> void
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# def foo: %a{foo} %a{foo} () -> void
|
18
|
+
#
|
19
|
+
# # not bad
|
20
|
+
# def foo: %a{foo} () -> void
|
21
|
+
# | %a{foo} (Integer) -> void
|
22
|
+
#
|
23
|
+
class DuplicateAnnotation < RuboCop::RBS::CopBase
|
24
|
+
MSG = 'Duplicate annotation detected.'
|
25
|
+
|
26
|
+
def on_rbs_def(decl)
|
27
|
+
decl.annotations.each_with_index do |annotation, idx|
|
28
|
+
next_annotations = decl.annotations[(idx + 1)..] or next
|
29
|
+
check_annotations(annotation, next_annotations)
|
30
|
+
|
31
|
+
decl.overloads.each do |overload|
|
32
|
+
check_annotations(annotation, overload.annotations)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
decl.overloads.each do |overload|
|
37
|
+
overload.annotations.each_with_index do |overload_annotation, idx|
|
38
|
+
next_annotations = overload.annotations[(idx + 1)..] or next
|
39
|
+
check_annotations(overload_annotation, next_annotations)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def check_annotations(left_annotation, right_annotations)
|
45
|
+
right_annotations.each do |right_annotation|
|
46
|
+
next unless left_annotation == right_annotation
|
47
|
+
next unless right_annotation.location
|
48
|
+
|
49
|
+
range = location_to_range(right_annotation.location)
|
50
|
+
add_offense(range)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -4,15 +4,16 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module RBS
|
6
6
|
module Lint
|
7
|
-
# Checks that there are no repeated overload bodies
|
7
|
+
# Checks that there are no repeated overload bodies.
|
8
|
+
# This cop ignores the difference of return type.
|
8
9
|
#
|
9
|
-
# @example
|
10
|
+
# @example
|
10
11
|
# # bad
|
11
12
|
# def foo: () -> void
|
12
|
-
# | () ->
|
13
|
+
# | () -> top
|
13
14
|
#
|
14
15
|
class DuplicateOverload < RuboCop::RBS::CopBase
|
15
|
-
MSG = 'Duplicate overload
|
16
|
+
MSG = 'Duplicate overload arguments detected.'
|
16
17
|
|
17
18
|
def on_rbs_def(decl)
|
18
19
|
overloads = decl.overloads
|
@@ -21,13 +22,22 @@ module RuboCop
|
|
21
22
|
|
22
23
|
next_overloads = overloads[(idx + 1)..-1]
|
23
24
|
next_overloads.each do |next_overload|
|
24
|
-
|
25
|
+
a = method_type_with_untyped_return_type(overload.method_type)
|
26
|
+
b = method_type_with_untyped_return_type(next_overload.method_type)
|
27
|
+
next unless a == b
|
25
28
|
|
26
29
|
range = location_to_range(next_overload.method_type.location)
|
27
30
|
add_offense(range)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def method_type_with_untyped_return_type(method_type)
|
38
|
+
type = method_type.type.with_return_type(::RBS::Types::Bases::Any.new(location: nil))
|
39
|
+
method_type.update(type:)
|
40
|
+
end
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RBS
|
6
|
+
module Lint
|
7
|
+
# This cop checks for conflicts between `implicitly-returns-nil` annotations and return types.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# %a{implicitly-returns-nil}
|
12
|
+
# def foo: () -> Integer?
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# %a{implicitly-returns-nil}
|
16
|
+
# def foo: () -> Integer
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# def foo: () -> Integer?
|
20
|
+
#
|
21
|
+
class ImplicitlyReturnsNil < RuboCop::RBS::CopBase
|
22
|
+
extend AutoCorrector
|
23
|
+
|
24
|
+
MSG = "There is a conflict between `%<annotation>s` and return type `%<return_type>s`."
|
25
|
+
|
26
|
+
def on_rbs_def(decl)
|
27
|
+
decl.overloads.each do |overload|
|
28
|
+
annotation = find_implicitly_returns_nil(decl) || find_implicitly_returns_nil(overload)
|
29
|
+
next unless annotation
|
30
|
+
next unless overload_returns_nil?(overload)
|
31
|
+
|
32
|
+
return_type = overload.method_type.type.return_type.to_s
|
33
|
+
range = location_to_range(annotation.location)
|
34
|
+
message = format(MSG, annotation: annotation.location.source, return_type:)
|
35
|
+
add_offense(range, message:)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def find_implicitly_returns_nil(decl)
|
42
|
+
decl.annotations.find { |a| a.string == 'implicitly-returns-nil' }
|
43
|
+
end
|
44
|
+
|
45
|
+
def overload_returns_nil?(overload)
|
46
|
+
returns_nil?(overload.method_type.type.return_type)
|
47
|
+
end
|
48
|
+
|
49
|
+
def returns_nil?(type)
|
50
|
+
case type
|
51
|
+
when ::RBS::Types::Bases::Nil,
|
52
|
+
::RBS::Types::Optional
|
53
|
+
true
|
54
|
+
when ::RBS::Types::Union
|
55
|
+
type.types.any? { |t| returns_nil?(t) }
|
56
|
+
else
|
57
|
+
false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/rubocop/cop/rbs_cops.rb
CHANGED
@@ -25,7 +25,9 @@ require_relative 'rbs/layout/trailing_whitespace'
|
|
25
25
|
|
26
26
|
require_relative 'rbs/lint/ambiguous_keyword_argument_key'
|
27
27
|
require_relative 'rbs/lint/ambiguous_operator_precedence'
|
28
|
+
require_relative 'rbs/lint/duplicate_annotation'
|
28
29
|
require_relative 'rbs/lint/duplicate_overload'
|
30
|
+
require_relative 'rbs/lint/implicitly_returns_nil'
|
29
31
|
require_relative 'rbs/lint/literal_intersection'
|
30
32
|
require_relative 'rbs/lint/new_returns_void'
|
31
33
|
require_relative 'rbs/lint/rest_keyword_hash'
|
data/lib/rubocop/rbs/cop_base.rb
CHANGED
@@ -13,6 +13,12 @@ module RuboCop
|
|
13
13
|
|
14
14
|
exclude_from_registry
|
15
15
|
|
16
|
+
def self.documentation_url(_config = nil)
|
17
|
+
base = "cops_#{department.to_s.downcase.tr('/', '_')}"
|
18
|
+
fragment = cop_name.downcase.gsub(/[^a-z]/, '')
|
19
|
+
"https://github.com/ksss/rubocop-on-rbs/blob/v#{VERSION}/docs/modules/ROOT/pages/#{base}.adoc##{fragment}"
|
20
|
+
end
|
21
|
+
|
16
22
|
def on_new_investigation
|
17
23
|
# Called here when valid as Ruby
|
18
24
|
investigation_rbs()
|
data/lib/rubocop/rbs/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-on-rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: lint_roller
|
@@ -106,7 +106,9 @@ files:
|
|
106
106
|
- lib/rubocop/cop/rbs/layout/trailing_whitespace.rb
|
107
107
|
- lib/rubocop/cop/rbs/lint/ambiguous_keyword_argument_key.rb
|
108
108
|
- lib/rubocop/cop/rbs/lint/ambiguous_operator_precedence.rb
|
109
|
+
- lib/rubocop/cop/rbs/lint/duplicate_annotation.rb
|
109
110
|
- lib/rubocop/cop/rbs/lint/duplicate_overload.rb
|
111
|
+
- lib/rubocop/cop/rbs/lint/implicitly_returns_nil.rb
|
110
112
|
- lib/rubocop/cop/rbs/lint/literal_intersection.rb
|
111
113
|
- lib/rubocop/cop/rbs/lint/new_returns_void.rb
|
112
114
|
- lib/rubocop/cop/rbs/lint/rest_keyword_hash.rb
|
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
162
|
+
rubygems_version: 3.7.0.dev
|
161
163
|
specification_version: 4
|
162
164
|
summary: RuboCop extension for RBS file.
|
163
165
|
test_files: []
|