From c3c028f4d2ed8053dbf55b7d8295f193cd64630d Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 18 Jul 2019 22:09:15 -0700 Subject: [PATCH] Improve detection of double spaces after sentences Support sentences that end in a question mark Don't match on more than 2 spaces because there may be a reason for that (who knows :shrug:) Signed-off-by: Tim Smith --- lib/rubocop/cop/chef/comment_sentence_spacing.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rubocop/cop/chef/comment_sentence_spacing.rb b/lib/rubocop/cop/chef/comment_sentence_spacing.rb index d358ef028..e0d0160f0 100644 --- a/lib/rubocop/cop/chef/comment_sentence_spacing.rb +++ b/lib/rubocop/cop/chef/comment_sentence_spacing.rb @@ -26,14 +26,14 @@ class CommentSentenceSpacing < Cop def investigate(processed_source) return unless processed_source.ast processed_source.comments.each do |comment| - if comment.text.match?(/\. /) + if comment.text.match?(/(.|\?)\s{2}/) # https://rubular.com/r/8o3SiDrQMJSzuU add_offense(comment, location: comment.loc.expression, message: MSG, severity: :warning) end end end def autocorrect(comment) - ->(corrector) { corrector.replace(comment.loc.expression, comment.text.gsub('. ', '. ')) } + ->(corrector) { corrector.replace(comment.loc.expression, comment.text.gsub('. ', '. ').gsub('? ', '? ')) } end end end