Skip to content

Commit c5ee2dd

Browse files
committed
Fix bug if tag name includes none alphabet
Fix #18
1 parent efd208b commit c5ee2dd

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

lib/rubocop/cop/yard/mismatch_name.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def find_by_tag(preceding_lines, tag, i)
149149
end
150150

151151
def add_offense_to_tag(node, comment, tag)
152-
tag_name_regexp = Regexp.new("\\b#{Regexp.escape(tag.name)}\\b")
153-
start_column = comment.source.index(tag_name_regexp)
152+
tag_name_regexp = Regexp.new("\\s#{Regexp.escape(tag.name)}\\s")
153+
start_column = comment.source.index(tag_name_regexp) or return
154154
offense_start = comment.location.column + start_column
155155
offense_end = offense_start + tag.name.length - 1
156156
range = source_range(processed_source.buffer, comment.location.line, offense_start..offense_end)

sig/rubocop/yard.rbs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module RuboCop
55
end
66
module Cop
77
module YARD
8+
type tag = ::YARD::Tags::Tag | ::YARD::Tags::OverloadTag | ::YARD::Tags::OptionTag
89
type tag_types = YARD::Tags::TypesExplainer::Type
910
| ::YARD::Tags::TypesExplainer::CollectionType
1011
| ::YARD::Tags::TypesExplainer::FixedCollectionType
@@ -14,7 +15,7 @@ module RuboCop
1415
end
1516

1617
module Helper
17-
def extract_tag_types: (::YARD::Tags::OptionTag | ::YARD::Tags::Tag tag) -> Array[String]?
18+
def extract_tag_types: (tag tag) -> Array[String]?
1819
end
1920

2021
class TagTypeSyntax < ::RuboCop::Cop::Base
@@ -31,6 +32,9 @@ module RuboCop
3132

3233
class MismatchName < ::RuboCop::Cop::Base
3334
include YARD::Helper
35+
36+
def add_offense_to_tag: (untyped node, ::Parser::Source::Comment comment, ::YARD::Tags::Tag tag) -> void
37+
def cop_config_prototype_name: () -> ("before" | "after")
3438
end
3539
end
3640
end

smoke/generated/mismatch_name.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
"correctable": false,
6767
"location": {
6868
"start_line": 6,
69-
"start_column": 13,
69+
"start_column": 12,
7070
"last_line": 6,
71-
"last_column": 15,
71+
"last_column": 14,
7272
"length": 3,
7373
"line": 6,
74-
"column": 13
74+
"column": 12
7575
}
7676
},
7777
{
@@ -121,12 +121,28 @@
121121
"line": 17,
122122
"column": 3
123123
}
124+
},
125+
{
126+
"severity": "convention",
127+
"message": "`context,` is not found in method arguments of [context]",
128+
"cop_name": "YARD/MismatchName",
129+
"corrected": false,
130+
"correctable": false,
131+
"location": {
132+
"start_line": 47,
133+
"start_column": 18,
134+
"last_line": 47,
135+
"last_column": 25,
136+
"length": 8,
137+
"line": 47,
138+
"column": 18
139+
}
124140
}
125141
]
126142
}
127143
],
128144
"summary": {
129-
"offense_count": 7,
145+
"offense_count": 8,
130146
"target_file_count": 1,
131147
"inspected_file_count": 1
132148
}

smoke/generated/mismatch_name_correct.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ def delegate(arg, ...)
4545
def empty_doc(arg)
4646
end
4747
end
48+
49+
# https://github.com/ksss/rubocop-yard/issues/18
50+
class Test
51+
# @param [Hash] context, Extra colon at the end of param name.
52+
def test(context)
53+
end
54+
end

smoke/mismatch_name.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ def delegate(arg, ...)
4141
def empty_doc(arg)
4242
end
4343
end
44+
45+
# https://github.com/ksss/rubocop-yard/issues/18
46+
class Test
47+
# @param [Hash] context, Extra colon at the end of param name.
48+
def test(context)
49+
end
50+
end

0 commit comments

Comments
 (0)