From 73194b460d047bec3a4d6fb31cf969a2b9e7aa77 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Mon, 6 Aug 2018 18:43:26 +0100 Subject: [PATCH] formula_desc_cop: add unnecessary whitespace check --- Library/Homebrew/rubocops/formula_desc_cop.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Library/Homebrew/rubocops/formula_desc_cop.rb b/Library/Homebrew/rubocops/formula_desc_cop.rb index faffd42f6c..abdaf869fe 100644 --- a/Library/Homebrew/rubocops/formula_desc_cop.rb +++ b/Library/Homebrew/rubocops/formula_desc_cop.rb @@ -38,6 +38,7 @@ module RuboCop module FormulaAuditStrict # This cop audits `desc` in Formulae # + # - Checks for leading/trailing whitespace in `desc` # - Checks if `desc` begins with an article # - Checks for correct usage of `command-line` in `desc` # - Checks description starts with a capital letter @@ -62,6 +63,16 @@ module RuboCop desc = parameters(desc_call).first + # Check for leading whitespace. + if regex_match_group(desc, /^\s+/) + problem "Description shouldn't have a leading space" + end + + # Check for trailing whitespace. + if regex_match_group(desc, /\s+$/) + problem "Description shouldn't have a trailing space" + end + # Check if command-line is wrongly used in formula's desc if match = regex_match_group(desc, /(command ?line)/i) c = match.to_s.chars.first @@ -104,6 +115,8 @@ module RuboCop correction.gsub!(/^(['"]?)\s+/, "\\1") correction.gsub!(/\s+(['"]?)$/, "\\1") correction.gsub!(/\.(['"]?)$/, "\\1") + correction.gsub!(/^\s+/, "") + correction.gsub!(/\s+$/, "") corrector.insert_before(node.source_range, correction) corrector.remove(node.source_range) end