From 500215c177d82efd4a7af9730f9c2838f4607bc1 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Tue, 5 Feb 2019 22:04:25 +0100 Subject: [PATCH] [Fix #6708] Style/CommentedKeyword knows :yields: The `Style/CommentedKeyword` cop would not allow the `:yields:` RDoc directive as a trailing comment (to `def`). The documentation https://docs.ruby-lang.org/ en/2.1.0/RDoc/Markup.html#class-RDoc::Markup-label-Directives lists many, many directives, but only `:nodoc:` and `:yields:` are shown as trailing comments. --- CHANGELOG.md | 1 + lib/rubocop/cop/style/commented_keyword.rb | 6 +++--- manual/cops_style.md | 4 ++-- spec/rubocop/cop/style/commented_keyword_spec.rb | 7 +++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3759b88d365..7264bd8f7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * [#6597](https://github.com/rubocop-hq/rubocop/issues/6597): `Style/LineEndConcatenation` is now known to be unsafe for auto-correct. ([@jaredbeck][]) * [#6725](https://github.com/rubocop-hq/rubocop/issues/6725): Mark `Style/SymbolProc` as unsafe for auto-correct. ([@drenmi][]) +* [#6708](https://github.com/rubocop-hq/rubocop/issues/6708): Make `Style/CommentedKeyword` allow the `:yields:` RDoc comment. ([@bquorning][]) ## 0.63.1 (2019-01-22) diff --git a/lib/rubocop/cop/style/commented_keyword.rb b/lib/rubocop/cop/style/commented_keyword.rb index 5bcc0af1cb6..90e54cc57e1 100644 --- a/lib/rubocop/cop/style/commented_keyword.rb +++ b/lib/rubocop/cop/style/commented_keyword.rb @@ -6,8 +6,8 @@ module Style # This cop checks for comments put on the same line as some keywords. # These keywords are: `begin`, `class`, `def`, `end`, `module`. # - # Note that some comments (such as `:nodoc:` and `rubocop:disable`) are - # allowed. + # Note that some comments (`:nodoc:`, `:yields:, and `rubocop:disable`) + # are allowed. # # @example # # bad @@ -59,7 +59,7 @@ def investigate(processed_source) private KEYWORDS = %w[begin class def end module].freeze - ALLOWED_COMMENTS = %w[:nodoc: rubocop:disable].freeze + ALLOWED_COMMENTS = %w[:nodoc: :yields: rubocop:disable].freeze def offensive?(line) line = line.lstrip diff --git a/manual/cops_style.md b/manual/cops_style.md index c097ca8624a..bf89ddc4048 100644 --- a/manual/cops_style.md +++ b/manual/cops_style.md @@ -978,8 +978,8 @@ Enabled | Yes | No | 0.51 | - This cop checks for comments put on the same line as some keywords. These keywords are: `begin`, `class`, `def`, `end`, `module`. -Note that some comments (such as `:nodoc:` and `rubocop:disable`) are -allowed. +Note that some comments (`:nodoc:`, `:yields:, and `rubocop:disable`) +are allowed. ### Examples diff --git a/spec/rubocop/cop/style/commented_keyword_spec.rb b/spec/rubocop/cop/style/commented_keyword_spec.rb index 6190fe4d9a4..32b4d122b2a 100644 --- a/spec/rubocop/cop/style/commented_keyword_spec.rb +++ b/spec/rubocop/cop/style/commented_keyword_spec.rb @@ -122,6 +122,13 @@ class X # :nodoc: y end RUBY + expect_no_offenses(<<-RUBY.strip_indent) + class X + def y # :yields: + yield + end + end + RUBY expect_no_offenses(<<-RUBY.strip_indent) def x # rubocop:disable Metrics/MethodLength y