rubocop-on-rbs 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/config/default.yml +16 -4
- data/lib/rubocop/cop/rbs/lint/duplicate_overload.rb +35 -0
- data/lib/rubocop/cop/rbs/lint/{useless_overload_type_params.rb → redundant_overload_type_params.rb} +16 -4
- data/lib/rubocop/cop/rbs_cops.rb +2 -1
- data/lib/rubocop/rbs/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b70070f22849df33c71ad69c0f2a08c1a6a2d0523c19f779868dda630787de43
|
4
|
+
data.tar.gz: 43789ae285bc5e4f155ba5641fed3471cf27715e58007c02e26661d853304084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3dece661499c49c0f62c9db11c5a3ee5d0e926d4aedbced0c27b09fda4425eaea161663d22cbf3edf7f37a12fd83e56350b6832f4d90eeac17d027dd5c6f3f
|
7
|
+
data.tar.gz: '0662672318876ae0d61e604c3e5e9d7405000fb5632ece629ee7497ba5d45b9e9c0ebd1b11aa687472a07bf4b1fdde988f803975007841c47b21ed313ee3482c'
|
data/README.md
CHANGED
@@ -117,15 +117,13 @@ $ bundle exec rubocop --only RBS/Style
|
|
117
117
|
|
118
118
|
## Installation
|
119
119
|
|
120
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
121
|
-
|
122
120
|
Install the gem and add to the application's Gemfile by executing:
|
123
121
|
|
124
|
-
$ bundle add
|
122
|
+
$ bundle add rubocop-on-rbs --require false
|
125
123
|
|
126
124
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
127
125
|
|
128
|
-
$ gem install
|
126
|
+
$ gem install rubocop-on-rbs
|
129
127
|
|
130
128
|
## Usage
|
131
129
|
|
data/config/default.yml
CHANGED
@@ -11,6 +11,10 @@ Lint:
|
|
11
11
|
Exclude:
|
12
12
|
- '**/*.rbs'
|
13
13
|
|
14
|
+
Style:
|
15
|
+
Exclude:
|
16
|
+
- '**/*.rbs'
|
17
|
+
|
14
18
|
# RBS
|
15
19
|
|
16
20
|
RBS:
|
@@ -70,14 +74,25 @@ RBS/Layout/TrailingWhitespace:
|
|
70
74
|
## RBS/Lint
|
71
75
|
|
72
76
|
RBS/Lint:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
RBS/Lint/DuplicateOverload:
|
80
|
+
Severity: warning
|
81
|
+
Description: 'Checks that there are no repeated overload bodies'
|
82
|
+
Enabled: true
|
83
|
+
|
84
|
+
RBS/Lint/RedundantOverloadTypeParams:
|
73
85
|
Severity: warning
|
86
|
+
Description: 'Check redundant overload type params'
|
74
87
|
Enabled: true
|
75
88
|
|
76
89
|
RBS/Lint/Syntax:
|
90
|
+
Severity: fatal
|
77
91
|
Description: 'Check RBS syntax'
|
78
92
|
Enabled: true
|
79
93
|
|
80
94
|
RBS/Lint/TypeParamsArity:
|
95
|
+
Severity: warning
|
81
96
|
Description: 'Check type params arity'
|
82
97
|
Enabled: true
|
83
98
|
Expects:
|
@@ -123,11 +138,8 @@ RBS/Lint/TypeParamsArity:
|
|
123
138
|
hash: 2
|
124
139
|
range: 1
|
125
140
|
|
126
|
-
RBS/Lint/UselessOverloadTypeParams:
|
127
|
-
Description: 'Check useless overload type params'
|
128
|
-
Enabled: true
|
129
|
-
|
130
141
|
RBS/Lint/WillSyntaxError:
|
142
|
+
Severity: warning
|
131
143
|
Description: 'Check RBS will syntax error'
|
132
144
|
Enabled: true
|
133
145
|
|
@@ -0,0 +1,35 @@
|
|
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 overload bodies
|
8
|
+
#
|
9
|
+
# @example default
|
10
|
+
# # bad
|
11
|
+
# def foo: () -> void
|
12
|
+
# | () -> void
|
13
|
+
#
|
14
|
+
class DuplicateOverload < RuboCop::RBS::CopBase
|
15
|
+
MSG = 'Duplicate overload body detected.'
|
16
|
+
|
17
|
+
def on_rbs_def(decl)
|
18
|
+
overloads = decl.overloads
|
19
|
+
overloads.each_with_index do |overload, idx|
|
20
|
+
next if idx == overloads.size - 1
|
21
|
+
|
22
|
+
next_overloads = overloads[(idx + 1)..-1]
|
23
|
+
next_overloads.each do |next_overload|
|
24
|
+
next unless overload.method_type == next_overload.method_type
|
25
|
+
|
26
|
+
range = location_to_range(next_overload.method_type.location)
|
27
|
+
add_offense(range)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rubocop/cop/rbs/lint/{useless_overload_type_params.rb → redundant_overload_type_params.rb}
RENAMED
@@ -11,12 +11,15 @@ module RuboCop
|
|
11
11
|
# def foo: [T] () -> void
|
12
12
|
#
|
13
13
|
# # bad
|
14
|
-
# def bar: [T
|
14
|
+
# def bar: [T] () -> T
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# def baz: [T] () { () -> T } -> void
|
15
18
|
#
|
16
19
|
# # good
|
17
20
|
# def foo: [T] (Array[T]) -> T
|
18
|
-
class
|
19
|
-
MSG = '
|
21
|
+
class RedundantOverloadTypeParams < RuboCop::RBS::CopBase
|
22
|
+
MSG = 'Redundant overload type variable - `%<variable>s`.'
|
20
23
|
|
21
24
|
def on_rbs_def(decl)
|
22
25
|
decl.overloads.each do |overload|
|
@@ -24,7 +27,16 @@ module RuboCop
|
|
24
27
|
|
25
28
|
type_params = overload.method_type.type_params
|
26
29
|
|
27
|
-
|
30
|
+
types = []
|
31
|
+
overload.method_type.type.each_param do |param|
|
32
|
+
types << param.type
|
33
|
+
end
|
34
|
+
overload.method_type.block&.then do |block|
|
35
|
+
block.type.each_type do |t|
|
36
|
+
types << t
|
37
|
+
end
|
38
|
+
end
|
39
|
+
types.each do |type|
|
28
40
|
used_variable_in_type(type) do |var|
|
29
41
|
type_params.delete_if { |type_param| type_param.name == var.name }
|
30
42
|
end
|
data/lib/rubocop/cop/rbs_cops.rb
CHANGED
@@ -14,9 +14,10 @@ require_relative 'rbs/layout/space_before_colon'
|
|
14
14
|
require_relative 'rbs/layout/space_before_overload'
|
15
15
|
require_relative 'rbs/layout/trailing_whitespace'
|
16
16
|
|
17
|
+
require_relative 'rbs/lint/duplicate_overload'
|
18
|
+
require_relative 'rbs/lint/redundant_overload_type_params'
|
17
19
|
require_relative 'rbs/lint/syntax'
|
18
20
|
require_relative 'rbs/lint/type_params_arity'
|
19
|
-
require_relative 'rbs/lint/useless_overload_type_params'
|
20
21
|
require_relative 'rbs/lint/will_syntax_error'
|
21
22
|
|
22
23
|
require_relative 'rbs/style/block_return_boolish'
|
data/lib/rubocop/rbs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-on-rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbs
|
@@ -62,9 +62,10 @@ files:
|
|
62
62
|
- lib/rubocop/cop/rbs/layout/space_before_colon.rb
|
63
63
|
- lib/rubocop/cop/rbs/layout/space_before_overload.rb
|
64
64
|
- lib/rubocop/cop/rbs/layout/trailing_whitespace.rb
|
65
|
+
- lib/rubocop/cop/rbs/lint/duplicate_overload.rb
|
66
|
+
- lib/rubocop/cop/rbs/lint/redundant_overload_type_params.rb
|
65
67
|
- lib/rubocop/cop/rbs/lint/syntax.rb
|
66
68
|
- lib/rubocop/cop/rbs/lint/type_params_arity.rb
|
67
|
-
- lib/rubocop/cop/rbs/lint/useless_overload_type_params.rb
|
68
69
|
- lib/rubocop/cop/rbs/lint/will_syntax_error.rb
|
69
70
|
- lib/rubocop/cop/rbs/style/block_return_boolish.rb
|
70
71
|
- lib/rubocop/cop/rbs/style/classic_type.rb
|