rubocops/formula_desc: merge cops, slim whitelist.
This commit is contained in:
parent
476a61f51c
commit
9b5a0767cb
@ -10,7 +10,17 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# - Checks for existence of `desc`
|
# - Checks for existence of `desc`
|
||||||
# - Checks if size of `desc` > 80
|
# - Checks if size of `desc` > 80
|
||||||
class DescLength < FormulaCop
|
# - 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
|
||||||
|
# - Checks if `desc` contains the formula name
|
||||||
|
# - Checks if `desc` ends with a full stop (apart from in the case of "etc.")
|
||||||
|
class Desc < FormulaCop
|
||||||
|
VALID_LOWERCASE_WORDS = %w[
|
||||||
|
macOS
|
||||||
|
].freeze
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
desc_call = find_node_method_by_name(body_node, :desc)
|
desc_call = find_node_method_by_name(body_node, :desc)
|
||||||
|
|
||||||
@ -20,52 +30,15 @@ module RuboCop
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check the formula's desc length. Should be >0 and <80 characters.
|
|
||||||
desc = parameters(desc_call).first
|
desc = parameters(desc_call).first
|
||||||
|
|
||||||
|
# Check the formula's desc length. Should be >0 and <80 characters.
|
||||||
pure_desc_length = string_content(desc).length
|
pure_desc_length = string_content(desc).length
|
||||||
if pure_desc_length.zero?
|
if pure_desc_length.zero?
|
||||||
problem "The desc (description) should not be an empty string."
|
problem "The desc (description) should not be an empty string."
|
||||||
return
|
return
|
||||||
end
|
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`
|
|
||||||
# - Checks description starts with a capital letter
|
|
||||||
# - Checks if `desc` contains the formula name
|
|
||||||
# - 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?
|
|
||||||
|
|
||||||
desc = parameters(desc_call).first
|
|
||||||
|
|
||||||
# Check for leading whitespace.
|
# Check for leading whitespace.
|
||||||
problem "Description shouldn't have a leading space" if regex_match_group(desc, /^\s+/)
|
problem "Description shouldn't have a leading space" if regex_match_group(desc, /^\s+/)
|
||||||
|
|
||||||
@ -96,11 +69,18 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Check if a full stop is used at the end of a formula's desc (apart from in the case of "etc.")
|
# 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"
|
problem "Description shouldn't end with a full stop"
|
||||||
end
|
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
|
||||||
|
|
||||||
def autocorrect(node)
|
def autocorrect(node)
|
||||||
lambda do |corrector|
|
lambda do |corrector|
|
||||||
correction = node.source
|
correction = node.source
|
||||||
|
|||||||
@ -50,6 +50,7 @@ RSpec/FilePath:
|
|||||||
- 'rubocops/patches_spec.rb'
|
- 'rubocops/patches_spec.rb'
|
||||||
- 'rubocops/text_spec.rb'
|
- 'rubocops/text_spec.rb'
|
||||||
- 'rubocops/uses_from_macos_spec.rb'
|
- 'rubocops/uses_from_macos_spec.rb'
|
||||||
|
- 'rubocops/formula_desc_spec.rb'
|
||||||
- 'search_spec.rb'
|
- 'search_spec.rb'
|
||||||
- 'string_spec.rb'
|
- 'string_spec.rb'
|
||||||
- 'system_command_result_spec.rb'
|
- 'system_command_result_spec.rb'
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require "rubocops/formula_desc"
|
require "rubocops/formula_desc"
|
||||||
|
|
||||||
describe RuboCop::Cop::FormulaAudit::DescLength do
|
describe RuboCop::Cop::FormulaAudit::Desc do
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
context "When auditing formula desc" do
|
context "When auditing formula desc" do
|
||||||
@ -46,10 +46,6 @@ describe RuboCop::Cop::FormulaAudit::DescLength do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe RuboCop::Cop::FormulaAudit::Desc do
|
|
||||||
subject(:cop) { described_class.new }
|
|
||||||
|
|
||||||
context "When auditing formula desc" do
|
context "When auditing formula desc" do
|
||||||
it "When wrong \"command-line\" usage in desc" do
|
it "When wrong \"command-line\" usage in desc" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user