2017-03-02 20:26:29 +05:30
|
|
|
require_relative "./extend/formula_cop"
|
|
|
|
require_relative "../extend/string"
|
|
|
|
|
2017-03-02 01:10:36 +05:30
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module Homebrew
|
2017-03-02 20:26:29 +05:30
|
|
|
# This cop audits `desc` in Formulae
|
|
|
|
#
|
|
|
|
# - Checks for existence of `desc`
|
|
|
|
# - Checks if size of `desc` > 80
|
|
|
|
# - Checks if `desc` begins with an article
|
|
|
|
# - Checks for correct usage of `command-line` in `desc`
|
|
|
|
# - Checks if `desc` contains the formula name
|
|
|
|
class FormulaDesc < FormulaCop
|
2017-03-16 23:49:43 +05:30
|
|
|
def audit_formula(_node, _class_node, _parent_class_node, body)
|
|
|
|
desc_call = find_node_method_by_name(body, :desc)
|
2017-03-02 01:10:36 +05:30
|
|
|
|
2017-03-16 23:49:43 +05:30
|
|
|
if desc_call.nil?
|
|
|
|
problem "Formula should have a desc (Description)."
|
|
|
|
return
|
2017-03-02 01:10:36 +05:30
|
|
|
end
|
2017-03-12 02:55:21 +08:00
|
|
|
|
2017-03-16 23:49:43 +05:30
|
|
|
desc = parameters(desc_call).first
|
|
|
|
desc_length = "#{@formula_name}: #{string_content(desc)}".length
|
2017-03-12 02:55:21 +08:00
|
|
|
max_desc_length = 80
|
|
|
|
if desc_length > max_desc_length
|
2017-03-16 23:49:43 +05:30
|
|
|
problem <<-EOS.undent
|
2017-03-12 02:55:21 +08:00
|
|
|
Description is too long. "name: desc" should be less than #{max_desc_length} characters.
|
2017-03-16 23:49:43 +05:30
|
|
|
Length is calculated as #{@formula_name} + desc. (currently #{desc_length})
|
2017-03-12 02:55:21 +08:00
|
|
|
EOS
|
|
|
|
end
|
2017-03-16 23:49:43 +05:30
|
|
|
|
|
|
|
# Check if command-line is wrongly used in formula's desc
|
|
|
|
if match = regex_match_group(desc, /(command ?line)/i)
|
|
|
|
problem "Description should use \"command-line\" instead of \"#{match}\""
|
|
|
|
end
|
|
|
|
|
|
|
|
if match = regex_match_group(desc, /^(an?)\s/i)
|
|
|
|
problem "Description shouldn't start with an indefinite article (#{match})"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check if formula's name is used in formula's desc
|
|
|
|
problem "Description shouldn't include the formula name" if regex_match_group(desc, /^#{@formula_name}/i)
|
2017-03-12 02:55:21 +08:00
|
|
|
end
|
2017-03-02 01:10:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|