rubocop-rbs_inline 1.5.5 → 1.6.1
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 +16 -0
- data/CLAUDE.md +2 -1
- data/Rakefile +30 -14
- data/Steepfile +2 -2
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/rbs_inline_cops.rb +20 -20
- data/lib/rubocop/cop/style/rbs_inline/comment_parser.rb +5 -5
- data/lib/rubocop/cop/style/rbs_inline/data_class_comment_alignment.rb +2 -2
- data/lib/rubocop/cop/style/rbs_inline/data_define_with_block.rb +3 -3
- 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_data_class_annotation.rb +8 -8
- data/lib/rubocop/cop/style/rbs_inline/missing_type_annotation.rb +15 -15
- 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/unmatched_annotations.rb +13 -13
- data/lib/rubocop/cop/style/rbs_inline/untyped_instance_variable.rb +88 -19
- 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 +15 -11
- data/sig/rubocop/cop/style/rbs_inline/untyped_instance_variable.rbs +38 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd596a937ef29c9dd1053c9b874725aebde2e9fab387053243268810bb0a8103
|
|
4
|
+
data.tar.gz: '03865a85b9ef1783eb85816c386aee96370e48e7169994ea5cc96c1a323aacd9'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5c053242db495271ee4751bcba23bc67d876d8d668e0984634d1154452a87476ff82330ea9010c48cd0f285918124d2dc42145bb750a3a8d0f25368e8ee8e22
|
|
7
|
+
data.tar.gz: 0e78d76dc58a9ba77439f65013cf1aa46492ee84337a43c6630e81d18c02d5fba23b0fab88c42f7a73d35d3c3bf02c4cfc9bee50f9337fb4d0d2a5189ddfdbf1
|
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,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.1 (2026-07-10)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Fixed user's `Style/RbsInline: Exclude:` configuration being ignored (regression from 1.6.0).
|
|
8
|
+
|
|
9
|
+
## 1.6.0 (2026-07-05)
|
|
10
|
+
|
|
11
|
+
### Changes
|
|
12
|
+
|
|
13
|
+
- All cops now exclude `spec/**/*` and `test/**/*` by default. Override with `Exclude: []` per cop to lint annotations in test code.
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- **Style/RbsInline/UntypedInstanceVariable**: No longer reports a false positive for class instance variables (assigned inside `class << self` or `def self.foo`) that have a `# @rbs self.@name: Type` annotation.
|
|
18
|
+
|
|
3
19
|
## 1.5.5 (2026-05-19)
|
|
4
20
|
|
|
5
21
|
### Bug Fixes
|
data/CLAUDE.md
CHANGED
|
@@ -20,7 +20,8 @@ bundle exec rake rubocop:autocorrect # safe autocorrect
|
|
|
20
20
|
bundle exec rake rubocop:autocorrect_all # all autocorrect
|
|
21
21
|
|
|
22
22
|
# Type check
|
|
23
|
-
bundle exec rake
|
|
23
|
+
bundle exec rake steep # runs steep check
|
|
24
|
+
bundle exec rake rbs:validate # validates RBS signatures
|
|
24
25
|
|
|
25
26
|
# Default rake task (runs specs, rubocop, and type check)
|
|
26
27
|
bundle exec rake
|
data/Rakefile
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
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
|
|
|
8
|
-
task default:
|
|
8
|
+
task default: :ci
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
task ci: %i[rubocop spec steep rbs:validate]
|
|
11
|
+
|
|
12
|
+
require "rspec/core/rake_task"
|
|
11
13
|
|
|
12
14
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
13
|
-
spec.pattern = FileList[
|
|
15
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
desc
|
|
18
|
+
desc "Generate a new cop with a template"
|
|
17
19
|
task :new_cop, [:cop] do |_task, args|
|
|
18
|
-
require
|
|
20
|
+
require "rubocop"
|
|
19
21
|
|
|
20
22
|
cop_name = args.fetch(:cop) do
|
|
21
|
-
warn
|
|
23
|
+
warn "usage: bundle exec rake new_cop[Department/Name]"
|
|
22
24
|
exit!
|
|
23
25
|
end
|
|
24
26
|
|
|
@@ -26,16 +28,30 @@ task :new_cop, [:cop] do |_task, args|
|
|
|
26
28
|
|
|
27
29
|
generator.write_source
|
|
28
30
|
generator.write_spec
|
|
29
|
-
generator.inject_require(root_file_path:
|
|
30
|
-
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")
|
|
31
33
|
|
|
32
34
|
puts generator.todo
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
namespace :rbs do
|
|
36
|
-
desc
|
|
37
|
-
task :
|
|
38
|
-
sh
|
|
39
|
-
|
|
38
|
+
desc "Install RBS signatures"
|
|
39
|
+
task :install do
|
|
40
|
+
sh "bundle", "exec", "rbs", "collection", "install", "--frozen"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
desc "Generate RBS files"
|
|
44
|
+
task :generate do
|
|
45
|
+
sh "rbs-inline", "--opt-out", "--output=sig", "lib"
|
|
40
46
|
end
|
|
47
|
+
|
|
48
|
+
desc "Validate RBS files"
|
|
49
|
+
task validate: "rbs:install" do
|
|
50
|
+
sh "rbs", "-Isig", "validate"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
desc "Run Steep type checker"
|
|
55
|
+
task steep: "rbs:install" do
|
|
56
|
+
sh "bundle", "exec", "steep", "check"
|
|
41
57
|
end
|
data/Steepfile
CHANGED
data/config/default.yml
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
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_class_comment_alignment"
|
|
7
|
+
require_relative "style/rbs_inline/data_define_with_block"
|
|
8
|
+
require_relative "style/rbs_inline/embedded_rbs_spacing"
|
|
9
|
+
require_relative "style/rbs_inline/invalid_comment"
|
|
10
|
+
require_relative "style/rbs_inline/invalid_types"
|
|
11
|
+
require_relative "style/rbs_inline/keyword_separator"
|
|
12
|
+
require_relative "style/rbs_inline/method_comment_spacing"
|
|
13
|
+
require_relative "style/rbs_inline/missing_data_class_annotation"
|
|
14
|
+
require_relative "style/rbs_inline/missing_type_annotation"
|
|
15
|
+
require_relative "style/rbs_inline/parameters_separator"
|
|
16
|
+
require_relative "style/rbs_inline/redundant_annotation_with_skip"
|
|
17
|
+
require_relative "style/rbs_inline/redundant_instance_variable_annotation"
|
|
18
|
+
require_relative "style/rbs_inline/redundant_type_annotation"
|
|
19
|
+
require_relative "style/rbs_inline/require_rbs_inline_comment"
|
|
20
|
+
require_relative "style/rbs_inline/unmatched_annotations"
|
|
21
|
+
require_relative "style/rbs_inline/untyped_instance_variable"
|
|
22
|
+
require_relative "style/rbs_inline/variable_comment_spacing"
|
|
@@ -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|
|
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
|
31
31
|
include SourceCodeHelper
|
|
32
32
|
extend AutoCorrector
|
|
33
33
|
|
|
34
|
-
MSG =
|
|
34
|
+
MSG = "Misaligned inline type annotation for Data attribute."
|
|
35
35
|
|
|
36
36
|
# @rbs node: RuboCop::AST::SendNode
|
|
37
37
|
def on_send(node) #: void
|
|
@@ -125,7 +125,7 @@ module RuboCop
|
|
|
125
125
|
replace_start = line_begin + content_end_col
|
|
126
126
|
replace_end = line_begin + comment.location.column
|
|
127
127
|
|
|
128
|
-
corrector.replace(range_between(replace_start, replace_end),
|
|
128
|
+
corrector.replace(range_between(replace_start, replace_end), " " * padding)
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
end
|
|
@@ -28,9 +28,9 @@ module RuboCop
|
|
|
28
28
|
# end
|
|
29
29
|
#
|
|
30
30
|
class DataDefineWithBlock < Base
|
|
31
|
-
MSG =
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
MSG = "Do not use `Data.define` with a block. RBS::Inline does not parse block contents, " \
|
|
32
|
+
"so methods defined in the block will not be recognized. " \
|
|
33
|
+
"Use a separate class definition instead."
|
|
34
34
|
|
|
35
35
|
# @rbs node: RuboCop::AST::SendNode
|
|
36
36
|
def on_send(node) #: void
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
3
|
+
require_relative "source_code_helper"
|
|
4
|
+
require_relative "comment_parser"
|
|
5
5
|
|
|
6
6
|
module RuboCop
|
|
7
7
|
module Cop
|
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
|
30
30
|
include SourceCodeHelper
|
|
31
31
|
include CommentParser
|
|
32
32
|
|
|
33
|
-
MSG =
|
|
33
|
+
MSG = "`@rbs!` comment must be followed by a blank line."
|
|
34
34
|
|
|
35
35
|
def on_new_investigation #: void
|
|
36
36
|
check_embedded_rbs_spacing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "rbs/inline/annotation_parser/tokenizer"
|
|
4
4
|
|
|
5
5
|
module RuboCop
|
|
6
6
|
module Cop
|
|
@@ -22,11 +22,11 @@ module RuboCop
|
|
|
22
22
|
class InvalidComment < Base
|
|
23
23
|
extend AutoCorrector
|
|
24
24
|
|
|
25
|
-
MSG =
|
|
25
|
+
MSG = "Invalid RBS annotation comment found."
|
|
26
26
|
|
|
27
27
|
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
|
28
28
|
RBS_INLINE_KEYWORDS = %w[inherits override use module-self generic skip module class].freeze #: Array[String]
|
|
29
|
-
RBS_INLINE_KEYWORD_PATTERN = RBS_INLINE_KEYWORDS.join(
|
|
29
|
+
RBS_INLINE_KEYWORD_PATTERN = RBS_INLINE_KEYWORDS.join("|") #: String
|
|
30
30
|
|
|
31
31
|
SIGNATURE_PATTERN = '\(.*\)\s*(\??\s*{.*?}\s*)?->\s*.*'
|
|
32
32
|
|
|
@@ -56,10 +56,10 @@ module RuboCop
|
|
|
56
56
|
# @rbs text: String
|
|
57
57
|
def corrected_text(text) #: String?
|
|
58
58
|
case text
|
|
59
|
-
when MISSING_HASH_COLON then text.sub(/\A#\s+/,
|
|
60
|
-
when SPACE_BEFORE_COLON then text.sub(/\A#\s+:\s*/,
|
|
61
|
-
when MIXED_ANNOTATION then text.sub(/\A#:\s+/,
|
|
62
|
-
when MISSING_AT_SIGN then text.sub(/\A#\s*rbs\s+/,
|
|
59
|
+
when MISSING_HASH_COLON then text.sub(/\A#\s+/, "#: ")
|
|
60
|
+
when SPACE_BEFORE_COLON then text.sub(/\A#\s+:\s*/, "#: ")
|
|
61
|
+
when MIXED_ANNOTATION then text.sub(/\A#:\s+/, "# ")
|
|
62
|
+
when MISSING_AT_SIGN then text.sub(/\A#\s*rbs\s+/, "# @rbs ")
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "rbs/inline"
|
|
4
4
|
|
|
5
5
|
module RuboCop
|
|
6
6
|
module Cop
|
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
|
27
27
|
include RBS::Inline::AST::Annotations
|
|
28
28
|
include RBS::Inline::AST::Members
|
|
29
29
|
|
|
30
|
-
MSG =
|
|
30
|
+
MSG = "Invalid annotation found."
|
|
31
31
|
|
|
32
32
|
def on_new_investigation #: void
|
|
33
33
|
parse_comments.each do |result|
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
|
19
19
|
include CommentParser
|
|
20
20
|
include RangeHelp
|
|
21
21
|
|
|
22
|
-
MSG =
|
|
22
|
+
MSG = "Do not use `:` after the keyword."
|
|
23
23
|
|
|
24
24
|
# refs: https://github.com/soutaro/rbs-inline/blob/main/lib/rbs/inline/annotation_parser/tokenizer.rb
|
|
25
25
|
RBS_INLINE_KEYWORDS = %w[inherits override use module-self generic skip module class].freeze #: Array[String]
|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
|
49
49
|
|
|
50
50
|
def on_investigation_end #: void
|
|
51
51
|
processed_source.comments.each do |comment|
|
|
52
|
-
matched = comment.text.match(/\A#\s+@rbs\s+(#{RBS_INLINE_KEYWORDS.join(
|
|
52
|
+
matched = comment.text.match(/\A#\s+@rbs\s+(#{RBS_INLINE_KEYWORDS.join("|")}):/)
|
|
53
53
|
next unless matched
|
|
54
54
|
next if valid_method_annotation?(comment)
|
|
55
55
|
|
|
@@ -86,7 +86,7 @@ module RuboCop
|
|
|
86
86
|
# followed by `:` but no type.
|
|
87
87
|
# @rbs comment: Parser::Source::Comment
|
|
88
88
|
def no_argument_keyword_without_type?(comment) #: bool
|
|
89
|
-
comment.text.match?(/\A#\s+@rbs\s+(#{NO_ARGUMENT_KEYWORDS.join(
|
|
89
|
+
comment.text.match?(/\A#\s+@rbs\s+(#{NO_ARGUMENT_KEYWORDS.join("|")}):\s*\z/)
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
# @rbs comment: Parser::Source::Comment
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
3
|
+
require_relative "source_code_helper"
|
|
4
|
+
require_relative "comment_parser"
|
|
5
5
|
|
|
6
6
|
module RuboCop
|
|
7
7
|
module Cop
|
|
@@ -61,8 +61,8 @@ module RuboCop
|
|
|
61
61
|
include SourceCodeHelper
|
|
62
62
|
include CommentParser
|
|
63
63
|
|
|
64
|
-
MSG =
|
|
65
|
-
MSG_WITH_BLANK_LINE =
|
|
64
|
+
MSG = "Method-related `@rbs` annotation must be immediately before a method definition."
|
|
65
|
+
MSG_WITH_BLANK_LINE = "Remove blank line between method annotation and method definition."
|
|
66
66
|
METHOD_DEFINITION_PATTERN =
|
|
67
67
|
/\A(?:(?:private|protected|public|private_class_method|module_function)\s+)?def\s/ #: Regexp
|
|
68
68
|
|
|
@@ -115,7 +115,7 @@ module RuboCop
|
|
|
115
115
|
when RBS::Inline::AST::Annotations::VarType
|
|
116
116
|
# VarType includes both parameter types and variable types (@ivar, @@cvar)
|
|
117
117
|
# Only consider it method-related if it's a parameter annotation (name doesn't start with @)
|
|
118
|
-
return true unless annotation.name.start_with?(
|
|
118
|
+
return true unless annotation.name.start_with?("@")
|
|
119
119
|
when RBS::Inline::AST::Annotations::ReturnType,
|
|
120
120
|
RBS::Inline::AST::Annotations::BlockType,
|
|
121
121
|
RBS::Inline::AST::Annotations::Override,
|
|
@@ -166,7 +166,7 @@ module RuboCop
|
|
|
166
166
|
# @rbs comment: RBS::Inline::AnnotationParser::ParsingResult
|
|
167
167
|
def skip_only_annotation?(comment) #: bool
|
|
168
168
|
annotations = [] #: Array[RBS::Inline::AST::Annotations::t]
|
|
169
|
-
comment.each_annotation {
|
|
169
|
+
comment.each_annotation { annotations << _1 }
|
|
170
170
|
annotations.any? && annotations.all?(RBS::Inline::AST::Annotations::Skip)
|
|
171
171
|
end
|
|
172
172
|
|
|
@@ -20,13 +20,13 @@ module RuboCop
|
|
|
20
20
|
# :visibility #: Symbol
|
|
21
21
|
# )
|
|
22
22
|
#
|
|
23
|
-
class MissingDataClassAnnotation < Base
|
|
23
|
+
class MissingDataClassAnnotation < Base
|
|
24
24
|
include ASTUtils
|
|
25
25
|
include RangeHelp
|
|
26
26
|
include SourceCodeHelper
|
|
27
27
|
extend AutoCorrector
|
|
28
28
|
|
|
29
|
-
MSG =
|
|
29
|
+
MSG = "Missing inline type annotation for Data attribute (e.g., `#: Type`)."
|
|
30
30
|
|
|
31
31
|
# @rbs node: RuboCop::AST::SendNode
|
|
32
32
|
def on_send(node) #: void
|
|
@@ -99,7 +99,7 @@ module RuboCop
|
|
|
99
99
|
def longest_argname(node) #: String
|
|
100
100
|
last_index = node.arguments.size - 1
|
|
101
101
|
args = node.arguments.each_with_index.map { |a, i| i < last_index ? "#{a.source}," : a.source.to_s }
|
|
102
|
-
args.max_by(&:length) ||
|
|
102
|
+
args.max_by(&:length) || ""
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
# @rbs node: RuboCop::AST::SendNode
|
|
@@ -109,9 +109,9 @@ module RuboCop
|
|
|
109
109
|
longest = longest_argname(node)
|
|
110
110
|
|
|
111
111
|
args_source = node.arguments.each_with_index.map do |arg, i|
|
|
112
|
-
comma = i < last_index ?
|
|
112
|
+
comma = i < last_index ? "," : ""
|
|
113
113
|
prefix = "#{base_indent} #{arg.source}#{comma}"
|
|
114
|
-
padding =
|
|
114
|
+
padding = " " * (longest.length - source!(arg).length - comma.length + 2)
|
|
115
115
|
data_attribute?(arg) ? "#{prefix}#{padding}#: untyped" : prefix
|
|
116
116
|
end.join("\n")
|
|
117
117
|
|
|
@@ -123,7 +123,7 @@ module RuboCop
|
|
|
123
123
|
data_attributes(node).each do |arg|
|
|
124
124
|
next if inline_type_annotation?(arg.location.line)
|
|
125
125
|
|
|
126
|
-
add_offense(arg) {
|
|
126
|
+
add_offense(arg) { correct_multiline(_1, node, arg) }
|
|
127
127
|
end
|
|
128
128
|
end
|
|
129
129
|
|
|
@@ -134,7 +134,7 @@ module RuboCop
|
|
|
134
134
|
existing_comment = find_regular_comment(arg.location.line)
|
|
135
135
|
|
|
136
136
|
if existing_comment
|
|
137
|
-
comment_text = existing_comment.text.sub(/\A#\s*/,
|
|
137
|
+
comment_text = existing_comment.text.sub(/\A#\s*/, "")
|
|
138
138
|
corrector.replace(existing_comment.source_range, "#: untyped -- #{comment_text}")
|
|
139
139
|
else
|
|
140
140
|
insert_annotation(corrector, node, arg)
|
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
|
152
152
|
line_begin = processed_source.buffer.line_range(line).begin_pos
|
|
153
153
|
insert_pos = line_begin + content_end_col
|
|
154
154
|
|
|
155
|
-
corrector.insert_before(range_between(insert_pos, insert_pos), "#{
|
|
155
|
+
corrector.insert_before(range_between(insert_pos, insert_pos), "#{" " * padding}#: untyped")
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
# @rbs node: RuboCop::AST::SendNode
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "rbs/inline"
|
|
4
4
|
|
|
5
5
|
module RuboCop
|
|
6
6
|
module Cop
|
|
@@ -121,13 +121,13 @@ module RuboCop
|
|
|
121
121
|
include ConfigurableEnforcedStyle
|
|
122
122
|
include RangeHelp
|
|
123
123
|
|
|
124
|
-
METHOD_TYPE_SIGNATURE_MESSAGE =
|
|
124
|
+
METHOD_TYPE_SIGNATURE_MESSAGE = "Missing annotation comment (e.g., `#: (Type) -> ReturnType`)."
|
|
125
125
|
METHOD_TYPE_SIGNATURE_OR_RETURN_ANNOTATION_MESSAGE =
|
|
126
|
-
|
|
127
|
-
DOC_STYLE_PARAM_MESSAGE =
|
|
128
|
-
DOC_STYLE_RETURN_MESSAGE =
|
|
129
|
-
DOC_STYLE_TRAILING_RETURN_MESSAGE =
|
|
130
|
-
ATTRIBUTE_METHOD_MESSAGE =
|
|
126
|
+
"Missing type annotation (e.g., `#: -> ReturnType` or trailing `#: ReturnType`)."
|
|
127
|
+
DOC_STYLE_PARAM_MESSAGE = "Missing `@rbs %<name>s:` annotation."
|
|
128
|
+
DOC_STYLE_RETURN_MESSAGE = "Missing `@rbs return:` annotation."
|
|
129
|
+
DOC_STYLE_TRAILING_RETURN_MESSAGE = "Missing trailing return type annotation (e.g., `#: void`)."
|
|
130
|
+
ATTRIBUTE_METHOD_MESSAGE = "Missing inline type annotation (e.g., `#: Type`)."
|
|
131
131
|
|
|
132
132
|
ATTR_METHODS = %i[attr_reader attr_writer attr_accessor].freeze
|
|
133
133
|
VISIBILITY_MODIFIERS = %i[public protected private].freeze
|
|
@@ -238,7 +238,7 @@ module RuboCop
|
|
|
238
238
|
|
|
239
239
|
# @rbs visibility: visibility
|
|
240
240
|
def target_node?(visibility) #: bool
|
|
241
|
-
return true if cop_config[
|
|
241
|
+
return true if cop_config["Visibility"] == "all"
|
|
242
242
|
|
|
243
243
|
visibility == :public
|
|
244
244
|
end
|
|
@@ -316,7 +316,7 @@ module RuboCop
|
|
|
316
316
|
|
|
317
317
|
args_node_for(node).children.each do |argument|
|
|
318
318
|
name = argument.children[0]&.to_s
|
|
319
|
-
next if name.nil? || name.start_with?(
|
|
319
|
+
next if name.nil? || name.start_with?("_")
|
|
320
320
|
|
|
321
321
|
candidates = param_candidate_names(argument, name)
|
|
322
322
|
next unless candidates
|
|
@@ -379,9 +379,9 @@ module RuboCop
|
|
|
379
379
|
when RBS::Inline::AST::Annotations::BlockType
|
|
380
380
|
"&#{annotation.name}"
|
|
381
381
|
when RBS::Inline::AST::Annotations::SplatParamType
|
|
382
|
-
annotation.name ? "*#{annotation.name}" :
|
|
382
|
+
annotation.name ? "*#{annotation.name}" : "*"
|
|
383
383
|
when RBS::Inline::AST::Annotations::DoubleSplatParamType
|
|
384
|
-
annotation.name ? "**#{annotation.name}" :
|
|
384
|
+
annotation.name ? "**#{annotation.name}" : "**"
|
|
385
385
|
else
|
|
386
386
|
annotation.name.to_s
|
|
387
387
|
end
|
|
@@ -392,7 +392,7 @@ module RuboCop
|
|
|
392
392
|
annotation = find_leading_annotation(line)
|
|
393
393
|
return false unless annotation
|
|
394
394
|
|
|
395
|
-
annotation.comments.any? {
|
|
395
|
+
annotation.comments.any? { _1.location.slice.match?(/\A#\s+@rbs\s+(skip|override)\b/) }
|
|
396
396
|
end
|
|
397
397
|
|
|
398
398
|
# @rbs line: Integer
|
|
@@ -409,9 +409,9 @@ module RuboCop
|
|
|
409
409
|
def param_candidate_names(argument, name) #: Array[String]?
|
|
410
410
|
case argument.type
|
|
411
411
|
when :arg, :optarg, :kwarg, :kwoptarg then [name]
|
|
412
|
-
when :restarg then ["*#{name}",
|
|
413
|
-
when :kwrestarg then ["**#{name}",
|
|
414
|
-
when :blockarg then [
|
|
412
|
+
when :restarg then ["*#{name}", "*"]
|
|
413
|
+
when :kwrestarg then ["**#{name}", "**"]
|
|
414
|
+
when :blockarg then ["&", "&#{name}"]
|
|
415
415
|
end
|
|
416
416
|
end
|
|
417
417
|
|