Skip to content
Snippets Groups Projects
Unverified Commit 9b5a0767 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

rubocops/formula_desc: merge cops, slim whitelist.

parent 476a61f5
No related branches found
No related tags found
No related merge requests found
......@@ -10,37 +10,6 @@ module RuboCop
#
# - Checks for existence of `desc`
# - Checks if size of `desc` > 80
class DescLength < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, body_node)
desc_call = find_node_method_by_name(body_node, :desc)
# Check if a formula's desc is present
if desc_call.nil?
problem "Formula should have a desc (Description)."
return
end
# Check the formula's desc length. Should be >0 and <80 characters.
desc = parameters(desc_call).first
pure_desc_length = string_content(desc).length
if pure_desc_length.zero?
problem "The desc (description) should not be an empty string."
return
end
desc_length = "#{@formula_name}: #{string_content(desc)}".length
max_desc_length = 80
return if desc_length <= max_desc_length
problem "Description is too long. \"name: desc\" should be less than #{max_desc_length} characters. " \
"Length is calculated as #{@formula_name} + desc. (currently #{desc_length})"
end
end
end
module FormulaAudit
# 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`
......@@ -49,23 +18,27 @@ module RuboCop
# - Checks if `desc` ends with a full stop (apart from in the case of "etc.")
class Desc < FormulaCop
VALID_LOWERCASE_WORDS = %w[
ex
eXtensible
iOS
macOS
malloc
ooc
preexec
x86
xUnit
].freeze
def audit_formula(_node, _class_node, _parent_class_node, body_node)
desc_call = find_node_method_by_name(body_node, :desc)
return if desc_call.nil?
# Check if a formula's desc is present
if desc_call.nil?
problem "Formula should have a desc (Description)."
return
end
desc = parameters(desc_call).first
# Check the formula's desc length. Should be >0 and <80 characters.
pure_desc_length = string_content(desc).length
if pure_desc_length.zero?
problem "The desc (description) should not be an empty string."
return
end
# Check for leading whitespace.
problem "Description shouldn't have a leading space" if regex_match_group(desc, /^\s+/)
......@@ -96,9 +69,16 @@ module RuboCop
end
# Check if a full stop is used at the end of a formula's desc (apart from in the case of "etc.")
return unless regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
if regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
problem "Description shouldn't end with a full stop"
end
problem "Description shouldn't end with a full stop"
desc_length = "#{@formula_name}: #{string_content(desc)}".length
max_desc_length = 80
return if desc_length <= max_desc_length
problem "Description is too long. \"name: desc\" should be less than #{max_desc_length} characters. " \
"Length is calculated as #{@formula_name} + desc. (currently #{desc_length})"
end
def autocorrect(node)
......
......@@ -50,6 +50,7 @@ RSpec/FilePath:
- 'rubocops/patches_spec.rb'
- 'rubocops/text_spec.rb'
- 'rubocops/uses_from_macos_spec.rb'
- 'rubocops/formula_desc_spec.rb'
- 'search_spec.rb'
- 'string_spec.rb'
- 'system_command_result_spec.rb'
......
......@@ -2,7 +2,7 @@
require "rubocops/formula_desc"
describe RuboCop::Cop::FormulaAudit::DescLength do
describe RuboCop::Cop::FormulaAudit::Desc do
subject(:cop) { described_class.new }
context "When auditing formula desc" do
......@@ -46,10 +46,6 @@ describe RuboCop::Cop::FormulaAudit::DescLength do
RUBY
end
end
end
describe RuboCop::Cop::FormulaAudit::Desc do
subject(:cop) { described_class.new }
context "When auditing formula desc" do
it "When wrong \"command-line\" usage in desc" do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment