rubocop-rbs_inline 1.6.0 → 1.7.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/.rubocop.yml +48 -19
- data/CHANGELOG.md +14 -0
- data/README.md +70 -0
- data/Rakefile +19 -19
- data/Steepfile +2 -2
- data/config/default.yml +23 -51
- data/lib/rubocop/cop/rbs_inline_cops.rb +26 -20
- data/lib/rubocop/cop/style/rbs_inline/class_comment_alignment.rb +66 -0
- data/lib/rubocop/cop/style/rbs_inline/comment_parser.rb +5 -5
- data/lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb +6 -87
- data/lib/rubocop/cop/style/rbs_inline/data_define_with_block.rb +6 -7
- data/lib/rubocop/cop/style/rbs_inline/data_struct_helper.rb +97 -0
- data/lib/rubocop/cop/style/rbs_inline/embedded_rbs_spacing.rb +3 -3
- data/lib/rubocop/cop/style/rbs_inline/invalid_comment.rb +7 -7
- data/lib/rubocop/cop/style/rbs_inline/invalid_types.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/keyword_separator.rb +3 -3
- data/lib/rubocop/cop/style/rbs_inline/method_comment_spacing.rb +6 -6
- data/lib/rubocop/cop/style/rbs_inline/missing_class_annotation.rb +85 -0
- data/lib/rubocop/cop/style/rbs_inline/missing_data_class_annotation.rb +7 -137
- data/lib/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rb +56 -0
- data/lib/rubocop/cop/style/rbs_inline/missing_type_annotation.rb +16 -16
- data/lib/rubocop/cop/style/rbs_inline/parameters_separator.rb +5 -5
- data/lib/rubocop/cop/style/rbs_inline/redundant_annotation_with_skip.rb +11 -11
- data/lib/rubocop/cop/style/rbs_inline/redundant_instance_variable_annotation.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/redundant_type_annotation.rb +5 -5
- data/lib/rubocop/cop/style/rbs_inline/require_rbs_inline_comment.rb +3 -3
- data/lib/rubocop/cop/style/rbs_inline/source_code_helper.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/struct_class_comment_alignment.rb +58 -0
- data/lib/rubocop/cop/style/rbs_inline/struct_new_with_block.rb +54 -0
- data/lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb +13 -13
- data/lib/rubocop/cop/style/rbs_inline/untyped_instance_variable.rb +10 -10
- data/lib/rubocop/cop/style/rbs_inline/variable_comment_spacing.rb +4 -4
- data/lib/rubocop/rbs_inline/plugin.rb +7 -7
- data/lib/rubocop/rbs_inline/version.rb +1 -1
- data/lib/rubocop/rbs_inline.rb +1 -1
- data/lib/rubocop-rbs_inline.rb +5 -5
- data/rbs_collection.lock.yaml +19 -11
- data/sig/rubocop/cop/style/rbs_inline/class_comment_alignment.rbs +34 -0
- data/sig/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rbs +2 -30
- data/sig/rubocop/cop/style/rbs_inline/data_define_with_block.rbs +1 -1
- data/sig/rubocop/cop/style/rbs_inline/data_struct_helper.rbs +55 -0
- data/sig/rubocop/cop/style/rbs_inline/missing_class_annotation.rbs +41 -0
- data/sig/rubocop/cop/style/rbs_inline/missing_data_class_annotation.rbs +2 -46
- data/sig/rubocop/cop/style/rbs_inline/missing_struct_class_annotation.rbs +46 -0
- data/sig/rubocop/cop/style/rbs_inline/struct_class_comment_alignment.rbs +48 -0
- data/sig/rubocop/cop/style/rbs_inline/struct_new_with_block.rbs +40 -0
- metadata +14 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f1bf0f9d17e73042a1c33ae69ffe0cf079bedb1423119b36a524d085cfe6f6a
|
|
4
|
+
data.tar.gz: '0797210c998bb891bcd07b68f3d4cc9e779cf775ea051e6529c8b052ed58642a'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb484322f4605db7c86dddf047de1ad1dbe477faf11b7d736edaa544132b87c1b7c0481cd13a6154662a0e318daeaf4880102882288cf02b84ba88eb8d3372f5
|
|
7
|
+
data.tar.gz: 141d659c28c9c9b2bef362b7f5b57bccf68aaec436b553e19785d97d162a0293c94d0d79ad7d29b7300f0b2583cce353c3152503ec965ab521eeff6fe3bb1127
|
data/.rubocop.yml
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
- rubocop-rake
|
|
3
|
-
- rubocop-rspec
|
|
4
|
-
- rubocop-rbs_inline
|
|
1
|
+
# NOTE: Rules are sorted in ASCII order.
|
|
5
2
|
|
|
6
3
|
AllCops:
|
|
7
4
|
NewCops: enable
|
|
@@ -10,43 +7,56 @@ AllCops:
|
|
|
10
7
|
- bin/**/*
|
|
11
8
|
- vendor/**/*
|
|
12
9
|
|
|
10
|
+
plugins:
|
|
11
|
+
- rubocop-numbered-params
|
|
12
|
+
- rubocop-rake
|
|
13
|
+
- rubocop-rbs_inline
|
|
14
|
+
- rubocop-rspec
|
|
15
|
+
|
|
16
|
+
# Layout
|
|
17
|
+
Layout/LeadingCommentSpace:
|
|
18
|
+
AllowRBSInlineAnnotation: true
|
|
19
|
+
AllowSteepAnnotation: true
|
|
20
|
+
|
|
13
21
|
Layout/LineLength:
|
|
14
22
|
Max: 120
|
|
15
23
|
|
|
24
|
+
# Metrics
|
|
16
25
|
Metrics/AbcSize:
|
|
17
26
|
Max: 20
|
|
18
27
|
|
|
19
28
|
Metrics/BlockLength:
|
|
20
29
|
Exclude:
|
|
21
|
-
- spec/**/*_spec.rb
|
|
30
|
+
- "spec/**/*_spec.rb"
|
|
31
|
+
|
|
32
|
+
Metrics/ClassLength:
|
|
33
|
+
Max: 200
|
|
22
34
|
|
|
23
35
|
Metrics/MethodLength:
|
|
24
|
-
Max:
|
|
36
|
+
Max: 30
|
|
25
37
|
|
|
38
|
+
# Naming
|
|
26
39
|
Naming/FileName:
|
|
27
40
|
Exclude:
|
|
28
|
-
- lib/rubocop-rbs_inline.rb
|
|
41
|
+
- "lib/rubocop-rbs_inline.rb"
|
|
29
42
|
|
|
43
|
+
# RSpec
|
|
30
44
|
RSpec/ExampleLength:
|
|
31
|
-
Max: 20
|
|
32
|
-
|
|
33
|
-
RSpec/NestedGroups:
|
|
34
|
-
Max: 5
|
|
35
|
-
|
|
36
|
-
Style/Documentation:
|
|
37
45
|
Enabled: false
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
RSpec/MultipleMemoizedHelpers:
|
|
48
|
+
Max: 10
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
Layout/LeadingCommentSpace:
|
|
50
|
+
RSpec/MultipleExpectations:
|
|
44
51
|
Enabled: false
|
|
45
52
|
|
|
46
|
-
|
|
53
|
+
RSpec/NamedSubject:
|
|
47
54
|
Enabled: false
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
RSpec/NestedGroups:
|
|
57
|
+
Max: 5
|
|
58
|
+
|
|
59
|
+
# RbsInline
|
|
50
60
|
Style/RbsInline/MissingTypeAnnotation:
|
|
51
61
|
EnforcedStyle: doc_style_and_return_annotation
|
|
52
62
|
|
|
@@ -55,3 +65,22 @@ Style/RbsInline/RedundantTypeAnnotation:
|
|
|
55
65
|
|
|
56
66
|
Style/RbsInline/RequireRbsInlineComment:
|
|
57
67
|
EnforcedStyle: never
|
|
68
|
+
|
|
69
|
+
# Style
|
|
70
|
+
Style/AccessorGrouping:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
Style/CommentedKeyword:
|
|
74
|
+
Enabled: false
|
|
75
|
+
|
|
76
|
+
Style/Documentation:
|
|
77
|
+
Enabled: false
|
|
78
|
+
|
|
79
|
+
Style/HashSyntax:
|
|
80
|
+
EnforcedShorthandSyntax: always
|
|
81
|
+
|
|
82
|
+
Style/StringLiterals:
|
|
83
|
+
EnforcedStyle: double_quotes
|
|
84
|
+
|
|
85
|
+
Style/StringLiteralsInInterpolation:
|
|
86
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.7.0 (2026-07-20)
|
|
4
|
+
|
|
5
|
+
### New Features
|
|
6
|
+
|
|
7
|
+
- **Style/RbsInline/MissingStructClassAnnotation**: New cop that checks each attribute passed to `Struct.new` has a trailing `#:` inline type annotation. Supports autocorrect.
|
|
8
|
+
- **Style/RbsInline/StructClassCommentAlignment**: New cop that checks `#:` inline type annotations in a multiline `Struct.new` call are aligned. Supports autocorrect.
|
|
9
|
+
- **Style/RbsInline/StructNewWithBlock**: New cop that checks for `Struct.new` calls with a block, which RBS::Inline does not parse.
|
|
10
|
+
|
|
11
|
+
## 1.6.1 (2026-07-10)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- Fixed user's `Style/RbsInline: Exclude:` configuration being ignored (regression from 1.6.0).
|
|
16
|
+
|
|
3
17
|
## 1.6.0 (2026-07-05)
|
|
4
18
|
|
|
5
19
|
### Changes
|
data/README.md
CHANGED
|
@@ -198,6 +198,32 @@ MethodEntry = Data.define(
|
|
|
198
198
|
)
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
+
### Style/RbsInline/MissingStructClassAnnotation
|
|
202
|
+
|
|
203
|
+
Checks that each attribute passed to `Struct.new` has a trailing `#:` inline type annotation on the same line.
|
|
204
|
+
|
|
205
|
+
For folded `Struct.new` calls (where multiple attributes share a line), the cop will suggest rewriting as a multiline call so each attribute can be annotated individually. A leading string argument (the struct name) and the `keyword_init:` keyword argument are not attributes and are ignored.
|
|
206
|
+
|
|
207
|
+
Supports autocorrect.
|
|
208
|
+
|
|
209
|
+
**Examples:**
|
|
210
|
+
```ruby
|
|
211
|
+
# bad
|
|
212
|
+
Point = Struct.new(:x, :y)
|
|
213
|
+
|
|
214
|
+
# bad - missing annotation for :y
|
|
215
|
+
Point = Struct.new(
|
|
216
|
+
:x, #: Integer
|
|
217
|
+
:y
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# good
|
|
221
|
+
Point = Struct.new(
|
|
222
|
+
:x, #: Integer
|
|
223
|
+
:y #: Integer
|
|
224
|
+
)
|
|
225
|
+
```
|
|
226
|
+
|
|
201
227
|
### Style/RbsInline/MissingTypeAnnotation
|
|
202
228
|
|
|
203
229
|
Enforces that method definitions and `attr_*` declarations have RBS inline type annotations.
|
|
@@ -458,6 +484,50 @@ class Foo
|
|
|
458
484
|
end
|
|
459
485
|
```
|
|
460
486
|
|
|
487
|
+
### Style/RbsInline/StructClassCommentAlignment
|
|
488
|
+
|
|
489
|
+
Checks that `#:` inline type annotations in a multiline `Struct.new` call are aligned to the same column. The expected column is determined by the longest attribute name (plus its trailing comma). Folded `Struct.new` calls (where multiple attributes share a line) are excluded.
|
|
490
|
+
|
|
491
|
+
Supports autocorrect.
|
|
492
|
+
|
|
493
|
+
**Examples:**
|
|
494
|
+
```ruby
|
|
495
|
+
# bad
|
|
496
|
+
Point = Struct.new(
|
|
497
|
+
:x, #: Integer
|
|
498
|
+
:long_attr #: Integer
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
# good
|
|
502
|
+
Point = Struct.new(
|
|
503
|
+
:x, #: Integer
|
|
504
|
+
:long_attr #: Integer
|
|
505
|
+
)
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Style/RbsInline/StructNewWithBlock
|
|
509
|
+
|
|
510
|
+
Checks for `Struct.new` calls with a block. RBS::Inline does not parse block contents, so any methods defined inside the block will not be recognized for type checking. Instead, call `Struct.new` without a block and reopen the class separately to add methods.
|
|
511
|
+
|
|
512
|
+
**Examples:**
|
|
513
|
+
```ruby
|
|
514
|
+
# bad
|
|
515
|
+
User = Struct.new(:name, :role) do
|
|
516
|
+
def admin?
|
|
517
|
+
role == :admin
|
|
518
|
+
end
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
# good
|
|
522
|
+
User = Struct.new(:name, :role)
|
|
523
|
+
|
|
524
|
+
class User
|
|
525
|
+
def admin? #: bool
|
|
526
|
+
role == :admin
|
|
527
|
+
end
|
|
528
|
+
end
|
|
529
|
+
```
|
|
530
|
+
|
|
461
531
|
### Style/RbsInline/UnmatchedAnnotations
|
|
462
532
|
|
|
463
533
|
Verifies that annotation parameters match the actual method parameters.
|
data/Rakefile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rubocop/rake_task"
|
|
5
5
|
|
|
6
6
|
RuboCop::RakeTask.new
|
|
7
7
|
|
|
@@ -9,18 +9,18 @@ task default: :ci
|
|
|
9
9
|
|
|
10
10
|
task ci: %i[rubocop spec steep rbs:validate]
|
|
11
11
|
|
|
12
|
-
require
|
|
12
|
+
require "rspec/core/rake_task"
|
|
13
13
|
|
|
14
14
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
15
|
-
spec.pattern = FileList[
|
|
15
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
desc
|
|
18
|
+
desc "Generate a new cop with a template"
|
|
19
19
|
task :new_cop, [:cop] do |_task, args|
|
|
20
|
-
require
|
|
20
|
+
require "rubocop"
|
|
21
21
|
|
|
22
22
|
cop_name = args.fetch(:cop) do
|
|
23
|
-
warn
|
|
23
|
+
warn "usage: bundle exec rake new_cop[Department/Name]"
|
|
24
24
|
exit!
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -28,30 +28,30 @@ task :new_cop, [:cop] do |_task, args|
|
|
|
28
28
|
|
|
29
29
|
generator.write_source
|
|
30
30
|
generator.write_spec
|
|
31
|
-
generator.inject_require(root_file_path:
|
|
32
|
-
generator.inject_config(config_file_path:
|
|
31
|
+
generator.inject_require(root_file_path: "lib/rubocop/cop/rbs_inline_cops.rb")
|
|
32
|
+
generator.inject_config(config_file_path: "config/default.yml")
|
|
33
33
|
|
|
34
34
|
puts generator.todo
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
namespace :rbs do
|
|
38
|
-
desc
|
|
38
|
+
desc "Install RBS signatures"
|
|
39
39
|
task :install do
|
|
40
|
-
sh
|
|
40
|
+
sh "bundle", "exec", "rbs", "collection", "install", "--frozen"
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
desc
|
|
43
|
+
desc "Generate RBS files"
|
|
44
44
|
task :generate do
|
|
45
|
-
sh
|
|
45
|
+
sh "rbs-inline", "--opt-out", "--output=sig", "lib"
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
desc
|
|
49
|
-
task validate:
|
|
50
|
-
sh
|
|
48
|
+
desc "Validate RBS files"
|
|
49
|
+
task validate: "rbs:install" do
|
|
50
|
+
sh "rbs", "-Isig", "validate"
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
desc
|
|
55
|
-
task steep:
|
|
56
|
-
sh
|
|
54
|
+
desc "Run Steep type checker"
|
|
55
|
+
task steep: "rbs:install" do
|
|
56
|
+
sh "bundle", "exec", "steep", "check"
|
|
57
57
|
end
|
data/Steepfile
CHANGED
data/config/default.yml
CHANGED
|
@@ -1,66 +1,55 @@
|
|
|
1
|
+
Style/RbsInline:
|
|
2
|
+
inherit_mode:
|
|
3
|
+
merge:
|
|
4
|
+
- Exclude
|
|
5
|
+
Exclude:
|
|
6
|
+
- 'spec/**/*'
|
|
7
|
+
- 'test/**/*'
|
|
8
|
+
|
|
1
9
|
Style/RbsInline/DataClassCommentAlignment:
|
|
2
10
|
Description: "Checks that `#:` inline type annotations in `Data.define` blocks are aligned."
|
|
3
11
|
Enabled: true
|
|
4
12
|
VersionAdded: '1.5.0'
|
|
5
|
-
Exclude:
|
|
6
|
-
- 'spec/**/*'
|
|
7
|
-
- 'test/**/*'
|
|
8
13
|
|
|
9
14
|
Style/RbsInline/DataDefineWithBlock:
|
|
10
15
|
Description: "Checks for `Data.define` calls with a block, which RBS::Inline does not parse."
|
|
11
16
|
Enabled: true
|
|
12
17
|
VersionAdded: '1.5.0'
|
|
13
|
-
Exclude:
|
|
14
|
-
- 'spec/**/*'
|
|
15
|
-
- 'test/**/*'
|
|
16
18
|
|
|
17
19
|
Style/RbsInline/EmbeddedRbsSpacing:
|
|
18
20
|
Description: 'Checks that `@rbs!` comments (embedded RBS) are followed by a blank line.'
|
|
19
21
|
Enabled: true
|
|
20
22
|
VersionAdded: '1.5.0'
|
|
21
|
-
Exclude:
|
|
22
|
-
- 'spec/**/*'
|
|
23
|
-
- 'test/**/*'
|
|
24
23
|
|
|
25
24
|
Style/RbsInline/InvalidComment:
|
|
26
25
|
Description: "Checks the rbs-inline annotation comment is valid."
|
|
27
26
|
Enabled: true
|
|
28
27
|
VersionAdded: "1.0.0"
|
|
29
|
-
Exclude:
|
|
30
|
-
- 'spec/**/*'
|
|
31
|
-
- 'test/**/*'
|
|
32
28
|
|
|
33
29
|
Style/RbsInline/InvalidTypes:
|
|
34
30
|
Description: "Checks the rbs-inline annotation comment uses valid types."
|
|
35
31
|
Enabled: true
|
|
36
32
|
VersionAdded: "1.0.0"
|
|
37
|
-
Exclude:
|
|
38
|
-
- 'spec/**/*'
|
|
39
|
-
- 'test/**/*'
|
|
40
33
|
|
|
41
34
|
Style/RbsInline/KeywordSeparator:
|
|
42
35
|
Description: "Checks the rbs-inline annotation comment does not use a separator after the keywords."
|
|
43
36
|
Enabled: true
|
|
44
37
|
VersionAdded: "1.0.0"
|
|
45
|
-
Exclude:
|
|
46
|
-
- 'spec/**/*'
|
|
47
|
-
- 'test/**/*'
|
|
48
38
|
|
|
49
39
|
Style/RbsInline/MethodCommentSpacing:
|
|
50
40
|
Description: 'Checks that method-related `@rbs` annotations are placed immediately before method definitions.'
|
|
51
41
|
Enabled: true
|
|
52
42
|
VersionAdded: '1.5.0'
|
|
53
|
-
Exclude:
|
|
54
|
-
- 'spec/**/*'
|
|
55
|
-
- 'test/**/*'
|
|
56
43
|
|
|
57
44
|
Style/RbsInline/MissingDataClassAnnotation:
|
|
58
45
|
Description: "Checks that `Data.define` attributes have inline type annotations."
|
|
59
46
|
Enabled: true
|
|
60
47
|
VersionAdded: '1.5.0'
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
|
|
49
|
+
Style/RbsInline/MissingStructClassAnnotation:
|
|
50
|
+
Description: "Checks that `Struct.new` attributes have inline type annotations."
|
|
51
|
+
Enabled: true
|
|
52
|
+
VersionAdded: '1.7.0'
|
|
64
53
|
|
|
65
54
|
Style/RbsInline/MissingTypeAnnotation:
|
|
66
55
|
Description: "Checks that method definitions and attr_* declarations have RBS inline type annotations."
|
|
@@ -73,34 +62,22 @@ Style/RbsInline/MissingTypeAnnotation:
|
|
|
73
62
|
- method_type_signature
|
|
74
63
|
- method_type_signature_or_return_annotation
|
|
75
64
|
Visibility: all
|
|
76
|
-
Exclude:
|
|
77
|
-
- 'spec/**/*'
|
|
78
|
-
- 'test/**/*'
|
|
79
65
|
|
|
80
66
|
Style/RbsInline/ParametersSeparator:
|
|
81
67
|
Description: "Checks the rbs-inline annotation comment uses a separator to parameters"
|
|
82
68
|
Enabled: true
|
|
83
69
|
VersionAdded: "1.0.0"
|
|
84
|
-
Exclude:
|
|
85
|
-
- 'spec/**/*'
|
|
86
|
-
- 'test/**/*'
|
|
87
70
|
|
|
88
71
|
Style/RbsInline/RedundantAnnotationWithSkip:
|
|
89
72
|
Description: "Checks for redundant type annotations when `@rbs skip` or `@rbs override` is present."
|
|
90
73
|
Enabled: true
|
|
91
74
|
SafeAutoCorrect: false
|
|
92
75
|
VersionAdded: '1.5.0'
|
|
93
|
-
Exclude:
|
|
94
|
-
- 'spec/**/*'
|
|
95
|
-
- 'test/**/*'
|
|
96
76
|
|
|
97
77
|
Style/RbsInline/RedundantInstanceVariableAnnotation:
|
|
98
78
|
Description: "Checks for redundant `@rbs` instance variable type annotation when `attr_*` with an inline type annotation is already defined."
|
|
99
79
|
Enabled: true
|
|
100
80
|
VersionAdded: '1.5.0'
|
|
101
|
-
Exclude:
|
|
102
|
-
- 'spec/**/*'
|
|
103
|
-
- 'test/**/*'
|
|
104
81
|
|
|
105
82
|
Style/RbsInline/RedundantTypeAnnotation:
|
|
106
83
|
Description: "Checks for redundant type annotations when multiple type specifications exist for the same method definition."
|
|
@@ -112,9 +89,6 @@ Style/RbsInline/RedundantTypeAnnotation:
|
|
|
112
89
|
- method_type_signature
|
|
113
90
|
- doc_style
|
|
114
91
|
- doc_style_and_return_annotation
|
|
115
|
-
Exclude:
|
|
116
|
-
- 'spec/**/*'
|
|
117
|
-
- 'test/**/*'
|
|
118
92
|
|
|
119
93
|
Style/RbsInline/RequireRbsInlineComment:
|
|
120
94
|
Description: "Checks the presence or absence of `# rbs_inline: enabled` magic comment."
|
|
@@ -124,30 +98,28 @@ Style/RbsInline/RequireRbsInlineComment:
|
|
|
124
98
|
SupportedStyles:
|
|
125
99
|
- always
|
|
126
100
|
- never
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
101
|
+
|
|
102
|
+
Style/RbsInline/StructClassCommentAlignment:
|
|
103
|
+
Description: "Checks that `#:` inline type annotations in `Struct.new` blocks are aligned."
|
|
104
|
+
Enabled: true
|
|
105
|
+
VersionAdded: '1.7.0'
|
|
106
|
+
|
|
107
|
+
Style/RbsInline/StructNewWithBlock:
|
|
108
|
+
Description: "Checks for `Struct.new` calls with a block, which RBS::Inline does not parse."
|
|
109
|
+
Enabled: true
|
|
110
|
+
VersionAdded: '1.7.0'
|
|
130
111
|
|
|
131
112
|
Style/RbsInline/UnmatchedAnnotations:
|
|
132
113
|
Description: "Checks the rbs-inline annotation comment is surely matched."
|
|
133
114
|
Enabled: true
|
|
134
115
|
VersionAdded: "1.0.0"
|
|
135
|
-
Exclude:
|
|
136
|
-
- 'spec/**/*'
|
|
137
|
-
- 'test/**/*'
|
|
138
116
|
|
|
139
117
|
Style/RbsInline/UntypedInstanceVariable:
|
|
140
118
|
Description: "Checks that instance variables in classes/modules have RBS type annotations."
|
|
141
119
|
Enabled: true
|
|
142
120
|
VersionAdded: '1.5.0'
|
|
143
|
-
Exclude:
|
|
144
|
-
- 'spec/**/*'
|
|
145
|
-
- 'test/**/*'
|
|
146
121
|
|
|
147
122
|
Style/RbsInline/VariableCommentSpacing:
|
|
148
123
|
Description: 'Checks that `@rbs` variable comments are followed by a blank line.'
|
|
149
124
|
Enabled: true
|
|
150
125
|
VersionAdded: '1.5.0'
|
|
151
|
-
Exclude:
|
|
152
|
-
- 'spec/**/*'
|
|
153
|
-
- 'test/**/*'
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
9
|
-
require_relative
|
|
10
|
-
require_relative
|
|
11
|
-
require_relative
|
|
12
|
-
require_relative
|
|
13
|
-
require_relative
|
|
14
|
-
require_relative
|
|
15
|
-
require_relative
|
|
16
|
-
require_relative
|
|
17
|
-
require_relative
|
|
18
|
-
require_relative
|
|
19
|
-
require_relative
|
|
20
|
-
require_relative
|
|
21
|
-
require_relative
|
|
22
|
-
require_relative
|
|
3
|
+
require_relative "style/rbs_inline/ast_utils"
|
|
4
|
+
require_relative "style/rbs_inline/source_code_helper"
|
|
5
|
+
require_relative "style/rbs_inline/comment_parser"
|
|
6
|
+
require_relative "style/rbs_inline/data_struct_helper"
|
|
7
|
+
require_relative "style/rbs_inline/missing_class_annotation"
|
|
8
|
+
require_relative "style/rbs_inline/class_comment_alignment"
|
|
9
|
+
require_relative "style/rbs_inline/data_class_comment_alignment"
|
|
10
|
+
require_relative "style/rbs_inline/data_define_with_block"
|
|
11
|
+
require_relative "style/rbs_inline/embedded_rbs_spacing"
|
|
12
|
+
require_relative "style/rbs_inline/invalid_comment"
|
|
13
|
+
require_relative "style/rbs_inline/invalid_types"
|
|
14
|
+
require_relative "style/rbs_inline/keyword_separator"
|
|
15
|
+
require_relative "style/rbs_inline/method_comment_spacing"
|
|
16
|
+
require_relative "style/rbs_inline/missing_data_class_annotation"
|
|
17
|
+
require_relative "style/rbs_inline/missing_type_annotation"
|
|
18
|
+
require_relative "style/rbs_inline/parameters_separator"
|
|
19
|
+
require_relative "style/rbs_inline/redundant_annotation_with_skip"
|
|
20
|
+
require_relative "style/rbs_inline/redundant_instance_variable_annotation"
|
|
21
|
+
require_relative "style/rbs_inline/redundant_type_annotation"
|
|
22
|
+
require_relative "style/rbs_inline/require_rbs_inline_comment"
|
|
23
|
+
require_relative "style/rbs_inline/struct_class_comment_alignment"
|
|
24
|
+
require_relative "style/rbs_inline/struct_new_with_block"
|
|
25
|
+
require_relative "style/rbs_inline/missing_struct_class_annotation"
|
|
26
|
+
require_relative "style/rbs_inline/unmatched_annotations"
|
|
27
|
+
require_relative "style/rbs_inline/untyped_instance_variable"
|
|
28
|
+
require_relative "style/rbs_inline/variable_comment_spacing"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
module RbsInline
|
|
7
|
+
# Shared behavior for cops that ensure `#:` inline type annotations on
|
|
8
|
+
# struct-like class attributes (`Data.define` / `Struct.new`) are aligned.
|
|
9
|
+
#
|
|
10
|
+
# The including cop matches the definition node (e.g. via `struct_like_class?`)
|
|
11
|
+
# and calls {#check_comment_alignment}.
|
|
12
|
+
#
|
|
13
|
+
# @rbs module-self RuboCop::Cop::Base
|
|
14
|
+
module ClassCommentAlignment
|
|
15
|
+
include DataStructHelper
|
|
16
|
+
|
|
17
|
+
# @rbs node: RuboCop::AST::SendNode
|
|
18
|
+
def check_comment_alignment(node) #: void
|
|
19
|
+
return if folded?(node)
|
|
20
|
+
|
|
21
|
+
check_annotation_alignment(node)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# @rbs node: RuboCop::AST::SendNode
|
|
27
|
+
def check_annotation_alignment(node) #: void
|
|
28
|
+
annotated = attr_arguments(node).filter_map do |arg|
|
|
29
|
+
comment = inline_type_comment(arg.location.line)
|
|
30
|
+
[arg, comment] if comment #: [RuboCop::AST::Node, Parser::Source::Comment]
|
|
31
|
+
end
|
|
32
|
+
return if annotated.size < 2
|
|
33
|
+
|
|
34
|
+
expected_col = annotation_column(node)
|
|
35
|
+
annotated.each do |arg, comment|
|
|
36
|
+
actual_col = comment.location.column
|
|
37
|
+
next if actual_col == expected_col
|
|
38
|
+
|
|
39
|
+
add_offense(comment.source_range) do |corrector|
|
|
40
|
+
correct_alignment(corrector, arg, comment, expected_col)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @rbs corrector: RuboCop::Cop::Corrector
|
|
46
|
+
# @rbs arg: RuboCop::AST::Node
|
|
47
|
+
# @rbs comment: Parser::Source::Comment
|
|
48
|
+
# @rbs expected_col: Integer
|
|
49
|
+
def correct_alignment(corrector, arg, comment, expected_col) #: void # rubocop:disable Metrics/AbcSize
|
|
50
|
+
line = arg.location.line
|
|
51
|
+
line_source = source_code_at(line)
|
|
52
|
+
source = line_source[...comment.location.column] || raise
|
|
53
|
+
content_end_col = source.rstrip.length
|
|
54
|
+
padding = [expected_col - content_end_col, 1].max || raise
|
|
55
|
+
|
|
56
|
+
line_begin = processed_source.buffer.line_range(line).begin_pos
|
|
57
|
+
replace_start = line_begin + content_end_col
|
|
58
|
+
replace_end = line_begin + comment.location.column
|
|
59
|
+
|
|
60
|
+
corrector.replace(range_between(replace_start, replace_end), " " * padding)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "rbs/inline"
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
5
|
+
require_relative "source_code_helper"
|
|
6
6
|
|
|
7
7
|
module RuboCop
|
|
8
8
|
module Cop
|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
|
49
49
|
|
|
50
50
|
# Exclude trailing inline comments (e.g., `def method = value #: Type`)
|
|
51
51
|
# by verifying all comment lines contain only whitespace before '#'
|
|
52
|
-
r.comments.all? {
|
|
52
|
+
r.comments.all? { processed_source.buffer.source_line(_1.location.start_line).match?(/\A\s*#/) }
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
@@ -60,8 +60,8 @@ module RuboCop
|
|
|
60
60
|
return unless leading_annotation
|
|
61
61
|
|
|
62
62
|
annotation_lines = leading_annotation.comments
|
|
63
|
-
.select {
|
|
64
|
-
.map {
|
|
63
|
+
.select { _1.location.slice.start_with?("#:") }
|
|
64
|
+
.map { _1.location.start_line }
|
|
65
65
|
return if annotation_lines.empty?
|
|
66
66
|
|
|
67
67
|
comments = processed_source.comments.select do |c|
|