Skip to content

Commit

Permalink
Improve detection of double spaces after sentences
Browse files Browse the repository at this point in the history
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 🤷)

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Jul 19, 2019
1 parent cae119d commit c3c028f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rubocop/cop/chef/comment_sentence_spacing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3c028f

Please sign in to comment.