rubocop-on-rbs 1.3.0 → 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 +4 -4
- data/CHANGELOG.md +18 -0
- data/config/default.yml +8 -4
- data/lib/rubocop/cop/rbs/lint/new_returns_void.rb +43 -0
- data/lib/rubocop/cop/rbs/lint/will_syntax_error.rb +24 -2
- data/lib/rubocop/cop/rbs_cops.rb +1 -0
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22a2658fe60905c8ede887f40b3bf114cd42c945194d0a968804b2f30069af9c
|
4
|
+
data.tar.gz: 3922f3dd22bf0f1b2afd66c0bbf0b8f5449424c3e64dcaa976def99ecdcd47d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a690a213a8654d2a9dd28822d6b112848348340956fa7e533d727203b28db67ed8233adb997b728e9fca9bd820bc0688ab1f984eb0498b6dfa645a9165b2e575
|
7
|
+
data.tar.gz: 1ffdd5f0b4305ff3158187a052cb4cd5fcce2ddf3e0629e3847699e7094741c5db66ee9962f9fc252e34d7a7f6f7a514bc32736cd4003e0377911b725b5a4a1a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.3.0] - 2024-12-24
|
4
|
+
|
5
|
+
* Add RBS/Lint/AmbiguousKeywordArgumentKey by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/51
|
6
|
+
* Fix false positive for TopLevel* by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/52
|
7
|
+
* Support `RBS::AST::Members::Var` by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/53
|
8
|
+
* [RBS/Layout/SpaceAroundOperators] Support other declarations by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/54
|
9
|
+
* Support other declarations by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/55
|
10
|
+
* Use 3.4.0-rc1 by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/56
|
11
|
+
* Add RBS/Lint/UselessTypeAliasTypeParams by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/57
|
12
|
+
* Use "Unused" instead of "Useless" as much as possible. by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/58
|
13
|
+
* Check config/default.yml on CI by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/59
|
14
|
+
* Use "Unused" instead of "Useless" as much as possible. by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/60
|
15
|
+
* Add RBS/Layout/SpaceAfterComma by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/61
|
16
|
+
* Add RBS/Style/InstanceWithInstance by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/62
|
17
|
+
* Introduce rbs-inline by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/63
|
18
|
+
* Reimplement RBS/Style/InstanceWithInstance by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/64
|
19
|
+
* Add RBS/Style/ClassWithSingleton by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/65
|
20
|
+
|
3
21
|
## [1.2.0] - 2024-11-18
|
4
22
|
|
5
23
|
* Fix false positive when oneline class by @ksss in https://github.com/ksss/rubocop-on-rbs/pull/41
|
data/config/default.yml
CHANGED
@@ -121,6 +121,10 @@ RBS/Lint/LiteralIntersection:
|
|
121
121
|
Description: 'Check literal intersection'
|
122
122
|
Enabled: true
|
123
123
|
|
124
|
+
RBS/Lint/NewReturnsVoid:
|
125
|
+
Description: 'sigleton `new` method should not returns `void` type'
|
126
|
+
Enabled: true
|
127
|
+
|
124
128
|
RBS/Lint/Syntax:
|
125
129
|
Severity: fatal
|
126
130
|
Description: 'Check RBS syntax'
|
@@ -128,12 +132,12 @@ RBS/Lint/Syntax:
|
|
128
132
|
|
129
133
|
RBS/Lint/TopLevelInterface:
|
130
134
|
Description: 'Check top level interface'
|
131
|
-
Enabled:
|
135
|
+
Enabled: true
|
132
136
|
VersionAdded: '1.2.0'
|
133
137
|
|
134
138
|
RBS/Lint/TopLevelTypeAlias:
|
135
139
|
Description: 'Check top level type alias'
|
136
|
-
Enabled:
|
140
|
+
Enabled: true
|
137
141
|
VersionAdded: '1.2.0'
|
138
142
|
|
139
143
|
RBS/Lint/UselessAccessModifier:
|
@@ -164,7 +168,7 @@ RBS/Style/BlockReturnBoolish:
|
|
164
168
|
|
165
169
|
RBS/Style/ClassWithSingleton:
|
166
170
|
Description: 'Check `class` with singleton context'
|
167
|
-
Enabled:
|
171
|
+
Enabled: true
|
168
172
|
|
169
173
|
RBS/Style/ClassicType:
|
170
174
|
Description: 'Use simple type'
|
@@ -184,7 +188,7 @@ RBS/Style/InitializeReturnType:
|
|
184
188
|
|
185
189
|
RBS/Style/InstanceWithInstance:
|
186
190
|
Description: 'Check `instance` with instance context'
|
187
|
-
Enabled:
|
191
|
+
Enabled: true
|
188
192
|
|
189
193
|
RBS/Style/OptionalNil:
|
190
194
|
Description: 'Use nil instead of nil?'
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rbs_inline: enabled
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module RBS
|
8
|
+
module Lint
|
9
|
+
# Checks that there are void types in the return type of `.new` method
|
10
|
+
# `self.new` is a special and fundamental method, and extra care should be taken regarding its return value.
|
11
|
+
# In most cases, assigning it `void` is an unintended mistake.
|
12
|
+
#
|
13
|
+
# @example default
|
14
|
+
# # bad
|
15
|
+
# def self.new: () -> void
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# def self.new: () -> instance
|
19
|
+
#
|
20
|
+
class NewReturnsVoid < RuboCop::RBS::CopBase
|
21
|
+
MSG = "Don't use `void` in self.new method. Did you mean `instance`?"
|
22
|
+
|
23
|
+
# @rbs decl: RBS::AST::Members::MethodDefinition
|
24
|
+
def on_rbs_def(decl)
|
25
|
+
return unless decl.kind == :singleton
|
26
|
+
return unless decl.name == :new
|
27
|
+
|
28
|
+
decl.overloads.each do |overload|
|
29
|
+
return_type = overload.method_type.type.return_type
|
30
|
+
case return_type
|
31
|
+
when ::RBS::Types::Bases::Void
|
32
|
+
next unless return_type.location
|
33
|
+
|
34
|
+
range = location_to_range(return_type.location)
|
35
|
+
add_offense(range)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -45,14 +45,26 @@ module RuboCop
|
|
45
45
|
check_module_or_class(decl)
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def check_type_params(decl)
|
49
49
|
decl.type_params.each do |param|
|
50
50
|
if ub = param.upper_bound
|
51
51
|
void_type_context_validator(ub)
|
52
52
|
no_self_type_validator(ub)
|
53
53
|
no_classish_type_validator(ub)
|
54
54
|
end
|
55
|
+
|
56
|
+
if param.respond_to?(:default_type)
|
57
|
+
if dt = param.default_type
|
58
|
+
void_type_context_validator(dt)
|
59
|
+
no_self_type_validator(dt)
|
60
|
+
no_classish_type_validator(dt)
|
61
|
+
end
|
62
|
+
end
|
55
63
|
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def check_module_or_class(decl)
|
67
|
+
check_type_params(decl)
|
56
68
|
|
57
69
|
decl.each_member do |member|
|
58
70
|
case member
|
@@ -79,6 +91,8 @@ module RuboCop
|
|
79
91
|
end
|
80
92
|
|
81
93
|
def on_rbs_interface(decl)
|
94
|
+
check_type_params(decl)
|
95
|
+
|
82
96
|
decl.members.each do |member|
|
83
97
|
case member
|
84
98
|
when AST::Members::MethodDefinition
|
@@ -96,7 +110,14 @@ module RuboCop
|
|
96
110
|
void_type_context_validator(decl.type)
|
97
111
|
end
|
98
112
|
alias on_rbs_global on_rbs_constant
|
99
|
-
|
113
|
+
|
114
|
+
def on_rbs_type_alias(decl)
|
115
|
+
no_self_type_validator(decl.type)
|
116
|
+
no_classish_type_validator(decl.type)
|
117
|
+
void_type_context_validator(decl.type)
|
118
|
+
|
119
|
+
check_type_params(decl)
|
120
|
+
end
|
100
121
|
|
101
122
|
private
|
102
123
|
|
@@ -166,6 +187,7 @@ module RuboCop
|
|
166
187
|
end
|
167
188
|
when Types::Proc
|
168
189
|
void_type_context_validator(type.type)
|
190
|
+
void_type_context_validator(type.self_type) if type.self_type
|
169
191
|
if type.block
|
170
192
|
void_type_context_validator(type.block.type)
|
171
193
|
void_type_context_validator(type.block.self_type) if type.block.self_type
|
data/lib/rubocop/cop/rbs_cops.rb
CHANGED
@@ -26,6 +26,7 @@ require_relative 'rbs/lint/ambiguous_keyword_argument_key'
|
|
26
26
|
require_relative 'rbs/lint/ambiguous_operator_precedence'
|
27
27
|
require_relative 'rbs/lint/duplicate_overload'
|
28
28
|
require_relative 'rbs/lint/literal_intersection'
|
29
|
+
require_relative 'rbs/lint/new_returns_void'
|
29
30
|
require_relative 'rbs/lint/syntax'
|
30
31
|
require_relative 'rbs/lint/top_level_interface'
|
31
32
|
require_relative 'rbs/lint/top_level_type_alias'
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-02-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rbs
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/rubocop/cop/rbs/lint/ambiguous_operator_precedence.rb
|
88
88
|
- lib/rubocop/cop/rbs/lint/duplicate_overload.rb
|
89
89
|
- lib/rubocop/cop/rbs/lint/literal_intersection.rb
|
90
|
+
- lib/rubocop/cop/rbs/lint/new_returns_void.rb
|
90
91
|
- lib/rubocop/cop/rbs/lint/syntax.rb
|
91
92
|
- lib/rubocop/cop/rbs/lint/top_level_interface.rb
|
92
93
|
- lib/rubocop/cop/rbs/lint/top_level_type_alias.rb
|