Skip to content

Commit

Permalink
Make Layout/LeadingCommentSpace aware of #:nodoc
Browse files Browse the repository at this point in the history
This PR makes `Layout/LeadingCommentSpace` aware of `#:nodoc`.

The following mention is the trigger.
https://twitter.com/kamipo/status/1421031611588485121

It seems that there was no definitive comment on whether to allow `#:nodoc:`.

- #277
- db79146

I've look RDoc doc's example of Ruby 3.0 and it looks to include leading comment space.

```ruby
module MyModule # :nodoc:
  class Input
  end
end

module OtherModule # :nodoc: all
  class Output
  end
end
```

https://docs.ruby-lang.org/en/3.0.0/RDoc/Markup.html#class-RDoc::Markup-label-Controlling+what+is+documented

I also considered making it an option for the presence or absence of
leading comment space in `#:nodoc:`, but I think it would be better to
consistent it that space is included when possible as the role of cop.
  • Loading branch information
koic authored and bbatsov committed Aug 3, 2021
1 parent b4675b4 commit 9498fee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
@@ -0,0 +1 @@
* [#9964](https://github.com/rubocop/rubocop/pull/9964): Make `Layout/LeadingCommentSpace` aware of `#:nodoc`. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/leading_comment_space.rb
Expand Up @@ -57,7 +57,7 @@ class LeadingCommentSpace < Base

def on_new_investigation
processed_source.comments.each do |comment|
next unless /\A#+[^#\s=:+-]/.match?(comment.text)
next unless /\A#+[^#\s=+-]/.match?(comment.text)
next if comment.loc.line == 1 && allowed_on_first_line?(comment)
next if doxygen_comment_style?(comment)
next if gemfile_ruby_comment?(comment)
Expand Down
20 changes: 14 additions & 6 deletions spec/rubocop/cop/layout/leading_comment_space_spec.rb
Expand Up @@ -135,12 +135,20 @@
end
end

it 'accepts rdoc syntax' do
expect_no_offenses(<<~RUBY)
#++
#--
#:nodoc:
RUBY
describe 'RDoc syntax' do
it 'does not register an offense when using `#++` or `#--`' do
expect_no_offenses(<<~RUBY)
#++
#--
RUBY
end

it 'registers an offense when starting `:`' do
expect_offense(<<~RUBY)
#:nodoc:
^^^^^^^^ Missing space after `#`.
RUBY
end
end

it 'accepts sprockets directives' do
Expand Down

0 comments on commit 9498fee

Please sign in to comment.