rubocop-on-rbs 1.4.2 → 1.6.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 +2 -0
- data/README.md +10 -17
- data/lib/rubocop/cop/rbs/style/duplicated_type.rb +6 -0
- data/lib/rubocop/cop/rbs/style/optional_nil.rb +16 -6
- data/lib/rubocop/cop/rbs/style/true_false.rb +16 -6
- data/lib/rubocop/rbs/plugin.rb +29 -0
- data/lib/rubocop/rbs/version.rb +1 -1
- data/lib/rubocop/rbs.rb +0 -6
- data/lib/rubocop-on-rbs.rb +1 -4
- metadata +30 -9
- data/lib/rubocop/rbs/inject.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 442a7571452e14e42efbd73d0f0313f983f631a983fd5c861f5c54d333538fd6
|
4
|
+
data.tar.gz: 1803e6bdf3eb67a025a3d1286966bef98eb695cf16e7edf83a717d748f995eca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '037319b5e7725a91470530891915c93227eddf4899ad8ad1a332f23bf23c3abedfc47f34618fbaa5c9672ad37d3e0badd32c7dec13f6319622dd653726f0d76d'
|
7
|
+
data.tar.gz: f2009c6f0af208cb65f96d410461c435f5a5a919253f191af1ae58f96ab54137e95c1e56d433aaac474126cbe7740a8320fd475c5d5487277ec47c0f92b46c30
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -33,20 +33,10 @@ def foo: ( void) -> untyped
|
|
33
33
|
|
34
34
|
## Support VSCode
|
35
35
|
|
36
|
-
|
36
|
+
[vscode-rubocop](https://github.com/rubocop/vscode-rubocop) with [rubocop.additionalLanguages](https://github.com/rubocop/vscode-rubocop?tab=readme-ov-file#rubocopadditionallanguages) option is recommended.
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
```
|
41
|
-
$ code ~/.vscode/extensions/rubocop.vscode-rubocop-X.Y.Z/
|
42
|
-
```
|
43
|
-
|
44
|
-
Search `documentSelector:[{`.
|
45
|
-
|
46
|
-
Then, Edit to add following to `documentSelector[]`
|
47
|
-
|
48
|
-
```js
|
49
|
-
{scheme:"file",language:"rbs"}
|
38
|
+
```json
|
39
|
+
"rubocop.additionalLanguages": ["rbs"]
|
50
40
|
```
|
51
41
|
|
52
42
|
Additionally, by configuring the `settings.json` below, you can enable auto-correction to run on file save.
|
@@ -137,13 +127,13 @@ ways to do this:
|
|
137
127
|
Put this into your `.rubocop.yml`.
|
138
128
|
|
139
129
|
```yaml
|
140
|
-
|
130
|
+
plugins: rubocop-on-rbs
|
141
131
|
```
|
142
132
|
|
143
133
|
Alternatively, use the following array notation when specifying multiple extensions.
|
144
134
|
|
145
135
|
```yaml
|
146
|
-
|
136
|
+
plugins:
|
147
137
|
- rubocop-other-extension
|
148
138
|
- rubocop-on-rbs
|
149
139
|
```
|
@@ -151,10 +141,13 @@ require:
|
|
151
141
|
Now you can run `rubocop` and it will automatically load the RuboCop on RBS
|
152
142
|
cops together with the standard cops.
|
153
143
|
|
144
|
+
> [!NOTE]
|
145
|
+
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
|
146
|
+
|
154
147
|
### Command line
|
155
148
|
|
156
149
|
```sh
|
157
|
-
$ rubocop --
|
150
|
+
$ rubocop --plugin rubocop-on-rbs
|
158
151
|
```
|
159
152
|
|
160
153
|
### Rake task
|
@@ -163,7 +156,7 @@ $ rubocop --require rubocop-on-rbs
|
|
163
156
|
require 'rubocop/rake_task'
|
164
157
|
|
165
158
|
RuboCop::RakeTask.new do |task|
|
166
|
-
task.
|
159
|
+
task.plugins << 'rubocop-on-rbs'
|
167
160
|
end
|
168
161
|
```
|
169
162
|
|
@@ -25,6 +25,12 @@ module RuboCop
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def on_rbs_constant(decl) = check_type(decl.type)
|
29
|
+
alias on_rbs_global on_rbs_constant
|
30
|
+
alias on_rbs_type_alias on_rbs_constant
|
31
|
+
alias on_rbs_attribute on_rbs_constant
|
32
|
+
alias on_rbs_var on_rbs_constant
|
33
|
+
|
28
34
|
# @rbs type: ::RBS::Types::t
|
29
35
|
def check_type(type)
|
30
36
|
case type
|
@@ -17,16 +17,26 @@ module RuboCop
|
|
17
17
|
def on_rbs_def(decl)
|
18
18
|
decl.overloads.each do |overload|
|
19
19
|
overload.method_type.each_type do |type|
|
20
|
-
|
21
|
-
range = location_to_range(t.location)
|
22
|
-
add_offense(range, message: "Use `#{replaced}` instead of `#{t}`") do |corrector|
|
23
|
-
corrector.replace(range, replaced.to_s)
|
24
|
-
end
|
25
|
-
end
|
20
|
+
check_type(type)
|
26
21
|
end
|
27
22
|
end
|
28
23
|
end
|
29
24
|
|
25
|
+
def check_type(type)
|
26
|
+
find_replacement(type) do |t, replaced|
|
27
|
+
range = location_to_range(t.location)
|
28
|
+
add_offense(range, message: "Use `#{replaced}` instead of `#{t}`") do |corrector|
|
29
|
+
corrector.replace(range, replaced.to_s)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_rbs_constant(const) = check_type(const.type)
|
35
|
+
alias on_rbs_global on_rbs_constant
|
36
|
+
alias on_rbs_type_alias on_rbs_constant
|
37
|
+
alias on_rbs_attribute on_rbs_constant
|
38
|
+
alias on_rbs_var on_rbs_constant
|
39
|
+
|
30
40
|
# @rbs type: ::RBS::Types::t
|
31
41
|
def find_replacement(type, &block)
|
32
42
|
case type
|
@@ -20,12 +20,22 @@ module RuboCop
|
|
20
20
|
def on_rbs_def(decl)
|
21
21
|
decl.overloads.each do |overload|
|
22
22
|
overload.method_type.each_type do |type|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
check_type(type)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_rbs_constant(const) = check_type(const.type)
|
29
|
+
alias on_rbs_global on_rbs_constant
|
30
|
+
alias on_rbs_type_alias on_rbs_constant
|
31
|
+
alias on_rbs_attribute on_rbs_constant
|
32
|
+
alias on_rbs_var on_rbs_constant
|
33
|
+
|
34
|
+
def check_type(type)
|
35
|
+
find_replacement(type) do |t, replaced|
|
36
|
+
range = location_to_range(t.location)
|
37
|
+
add_offense(range, message: "Use `#{replaced}` instead of `#{t}`") do |corrector|
|
38
|
+
corrector.replace(range, replaced.to_s)
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lint_roller'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module RBS
|
7
|
+
# A plugin that integrates RuboCop on RBS with RuboCop's plugin system.
|
8
|
+
class Plugin < LintRoller::Plugin
|
9
|
+
def about
|
10
|
+
LintRoller::About.new(
|
11
|
+
name: 'rubocop-on-rbs',
|
12
|
+
version: RuboCop::RBS::VERSION,
|
13
|
+
homepage: 'https://github.com/ksss/rubocop-on-rbs',
|
14
|
+
description: 'A RuboCop extension focused on enforcing RBS best practices and coding conventions.'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def supported?(context)
|
19
|
+
context.engine == :rubocop
|
20
|
+
end
|
21
|
+
|
22
|
+
def rules(_context)
|
23
|
+
project_root = Pathname.new(__dir__).join('../../..')
|
24
|
+
|
25
|
+
LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/rubocop/rbs/version.rb
CHANGED
data/lib/rubocop/rbs.rb
CHANGED
@@ -5,11 +5,5 @@ require_relative 'rbs/version'
|
|
5
5
|
module RuboCop
|
6
6
|
module RBS
|
7
7
|
class Error < StandardError; end
|
8
|
-
|
9
|
-
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
10
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
11
|
-
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
12
|
-
|
13
|
-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
14
8
|
end
|
15
9
|
end
|
data/lib/rubocop-on-rbs.rb
CHANGED
@@ -6,9 +6,6 @@ require_relative 'rubocop/rbs'
|
|
6
6
|
require_relative 'rubocop/rbs/version'
|
7
7
|
require_relative 'rubocop/rbs/on_type_helper'
|
8
8
|
require_relative 'rubocop/rbs/cop_base'
|
9
|
-
require_relative 'rubocop/rbs/inject'
|
10
9
|
require_relative 'rubocop/rbs/processed_rbs_source'
|
11
|
-
|
12
|
-
RuboCop::RBS::Inject.defaults!
|
13
|
-
|
10
|
+
require_relative 'rubocop/rbs/plugin'
|
14
11
|
require_relative 'rubocop/cop/rbs_cops'
|
metadata
CHANGED
@@ -1,14 +1,28 @@
|
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-25 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: lint_roller
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.1'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.1'
|
12
26
|
- !ruby/object:Gem::Dependency
|
13
27
|
name: rbs
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -27,16 +41,22 @@ dependencies:
|
|
27
41
|
name: rubocop
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
29
43
|
requirements:
|
30
|
-
- - "
|
44
|
+
- - ">="
|
31
45
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
46
|
+
version: 1.72.1
|
47
|
+
- - "<"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
33
50
|
type: :runtime
|
34
51
|
prerelease: false
|
35
52
|
version_requirements: !ruby/object:Gem::Requirement
|
36
53
|
requirements:
|
37
|
-
- - "
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.72.1
|
57
|
+
- - "<"
|
38
58
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
59
|
+
version: '2.0'
|
40
60
|
- !ruby/object:Gem::Dependency
|
41
61
|
name: zlib
|
42
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,8 +128,8 @@ files:
|
|
108
128
|
- lib/rubocop/cop/rbs_cops.rb
|
109
129
|
- lib/rubocop/rbs.rb
|
110
130
|
- lib/rubocop/rbs/cop_base.rb
|
111
|
-
- lib/rubocop/rbs/inject.rb
|
112
131
|
- lib/rubocop/rbs/on_type_helper.rb
|
132
|
+
- lib/rubocop/rbs/plugin.rb
|
113
133
|
- lib/rubocop/rbs/processed_rbs_source.rb
|
114
134
|
- lib/rubocop/rbs/version.rb
|
115
135
|
homepage: https://github.com/ksss/rubocop-on-rbs
|
@@ -119,6 +139,7 @@ metadata:
|
|
119
139
|
homepage_uri: https://github.com/ksss/rubocop-on-rbs
|
120
140
|
source_code_uri: https://github.com/ksss/rubocop-on-rbs
|
121
141
|
changelog_uri: https://github.com/ksss/rubocop-on-rbs
|
142
|
+
default_lint_roller_plugin: RuboCop::RBS::Plugin
|
122
143
|
rubygems_mfa_required: 'true'
|
123
144
|
rdoc_options: []
|
124
145
|
require_paths:
|
@@ -127,14 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
148
|
requirements:
|
128
149
|
- - ">="
|
129
150
|
- !ruby/object:Gem::Version
|
130
|
-
version: 3.
|
151
|
+
version: 3.2.0
|
131
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
153
|
requirements:
|
133
154
|
- - ">="
|
134
155
|
- !ruby/object:Gem::Version
|
135
156
|
version: '0'
|
136
157
|
requirements: []
|
137
|
-
rubygems_version: 3.6.
|
158
|
+
rubygems_version: 3.6.6
|
138
159
|
specification_version: 4
|
139
160
|
summary: RuboCop extension for RBS file.
|
140
161
|
test_files: []
|
data/lib/rubocop/rbs/inject.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
-
# See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
|
-
module RuboCop
|
6
|
-
module RBS
|
7
|
-
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
-
# bit of our configuration.
|
9
|
-
module Inject
|
10
|
-
def self.defaults!
|
11
|
-
path = CONFIG_DEFAULT.to_s
|
12
|
-
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
13
|
-
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
-
puts "configuration from #{path}" if ConfigLoader.debug?
|
15
|
-
config = ConfigLoader.merge_with_default(config, path)
|
16
|
-
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|