Class: RuboCop::Cop::Style::MethodDocRange
- Inherits:
-
Object
- Object
- RuboCop::Cop::Style::MethodDocRange
- Defined in:
- lib/rubocop/cop/style/public_method_documentation.rb
Overview
method doc range checks parts of the comment for correctness
Constant Summary collapse
- DOC_PARM_REGEXP =
%r{^# \* <tt>:(\w+)</tt>}.freeze
- PARM_START =
'# * <tt>:'
- PARM_END =
'</tt>'
Instance Attribute Summary collapse
-
#end ⇒ Object
Returns the value of attribute end.
-
#start ⇒ Object
Returns the value of attribute start.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #before?(method_doc_range) ⇒ Boolean
- #empty_comm?(comment) ⇒ Boolean
- #end_comment ⇒ Object
- #ends_with_empty_comment? ⇒ Boolean
- #first_comment? ⇒ Boolean
- #first_comment_equal?(text) ⇒ Boolean
- #first_empty_comment? ⇒ Boolean
-
#initialize(comments, type) ⇒ MethodDocRange
constructor
A new instance of MethodDocRange.
- #missing? ⇒ Boolean
- #parm_names ⇒ Object
- #range_body ⇒ Object
- #returns? ⇒ Boolean
- #start_comment ⇒ Object
- #starts_with_empty_comment? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(comments, type) ⇒ MethodDocRange
Returns a new instance of MethodDocRange.
301 302 303 304 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 301 def initialize(comments, type) @comments = comments @type = type end |
Instance Attribute Details
#end ⇒ Object
Returns the value of attribute end.
295 296 297 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 295 def end @end end |
#start ⇒ Object
Returns the value of attribute start.
295 296 297 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 295 def start @start end |
#type ⇒ Object
Returns the value of attribute type.
295 296 297 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 295 def type @type end |
Instance Method Details
#before?(method_doc_range) ⇒ Boolean
306 307 308 309 310 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 306 def before?(method_doc_range) return true if missing? || method_doc_range.missing? @start < method_doc_range.start end |
#empty_comm?(comment) ⇒ Boolean
312 313 314 315 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 312 def empty_comm?(comment) txt = comment.text txt.size <= 2 end |
#end_comment ⇒ Object
317 318 319 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 317 def end_comment @comments[@end] end |
#ends_with_empty_comment? ⇒ Boolean
321 322 323 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 321 def ends_with_empty_comment? missing? || empty_comm?(end_comment) end |
#first_comment? ⇒ Boolean
325 326 327 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 325 def first_comment? @start == 0 end |
#first_comment_equal?(text) ⇒ Boolean
333 334 335 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 333 def first_comment_equal?(text) !missing? && start_comment.text == text end |
#first_empty_comment? ⇒ Boolean
329 330 331 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 329 def first_empty_comment? missing? || empty_comm?(@comments[@start + 1]) end |
#missing? ⇒ Boolean
337 338 339 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 337 def missing? @start.nil? end |
#parm_names ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 341 def parm_names names = [] range_body.each do |parm_line| # puts "parm_line.text=#{parm_line}" # puts "match=#{DOC_PARM_REGEXP.match(parm_line.text).to_s}" DOC_PARM_REGEXP.match(parm_line.text) do |m| parm_name = m.to_s[PARM_START.size...m.to_s.index(PARM_END)] names.push([parm_line, parm_name]) # puts "parm_name=#{parm_name}" end end # puts "names=#{names}" names end |
#range_body ⇒ Object
356 357 358 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 356 def range_body @comments[@start + (first_empty_comment? ? 2 : 1)...@end + (ends_with_empty_comment? ? 0 : 1)] end |
#returns? ⇒ Boolean
360 361 362 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 360 def returns? @type == 'Return' end |
#start_comment ⇒ Object
364 365 366 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 364 def start_comment @comments[@start] end |
#starts_with_empty_comment? ⇒ Boolean
368 369 370 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 368 def starts_with_empty_comment? empty_comm?(@comments[@start]) end |
#to_s ⇒ Object
372 373 374 |
# File 'lib/rubocop/cop/style/public_method_documentation.rb', line 372 def to_s [missing? ? nil : start_comment, @start, @end] end |