From 1cd90c7d0c79665a041051ec1e70da4310a26c1b Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Wed, 31 Mar 2021 21:30:06 -0400 Subject: [PATCH] Remove (almost) redundant setting. Note that 'instance_methods' is not a valid category. --- .rubocop.yml | 13 ------------- lib/rubocop/cop/style/commented_keyword.rb | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5501680d59c..f84cdd23f6e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -46,19 +46,6 @@ Layout/EndOfLine: Layout/ClassStructure: Enabled: true - Categories: - module_inclusion: - - include - - prepend - - extend - ExpectedOrder: - - module_inclusion - - constants - - public_class_methods - - initializer - - instance_methods - - protected_methods - - private_methods Layout/TrailingWhitespace: AllowInHeredoc: false diff --git a/lib/rubocop/cop/style/commented_keyword.rb b/lib/rubocop/cop/style/commented_keyword.rb index 983f17e60a4..3da7d40b8bf 100644 --- a/lib/rubocop/cop/style/commented_keyword.rb +++ b/lib/rubocop/cop/style/commented_keyword.rb @@ -43,16 +43,6 @@ class CommentedKeyword < Base MSG = 'Do not place comments on the same line as the ' \ '`%s` keyword.' - def on_new_investigation - processed_source.comments.each do |comment| - next unless (match = line(comment).match(/(?\S+).*#/)) && offensive?(comment) - - register_offense(comment, match[:keyword]) - end - end - - private - KEYWORDS = %w[begin class def end module].freeze KEYWORD_REGEXES = KEYWORDS.map { |w| /^\s*#{w}\s/ }.freeze @@ -64,6 +54,16 @@ def on_new_investigation ].freeze ALLOWED_COMMENT_REGEXES = ALLOWED_COMMENTS.map { |c| /#\s*#{c}/ }.freeze + def on_new_investigation + processed_source.comments.each do |comment| + next unless (match = line(comment).match(/(?\S+).*#/)) && offensive?(comment) + + register_offense(comment, match[:keyword]) + end + end + + private + def register_offense(comment, matched_keyword) add_offense(comment, message: format(MSG, keyword: matched_keyword)) do |corrector| range = range_with_surrounding_space(range: comment.loc.expression, newlines: false)