Don't take name into account when calculating description length.
This commit is contained in:
parent
7d78949479
commit
750e299d49
@ -8,6 +8,8 @@ module RuboCop
|
|||||||
module DescHelper
|
module DescHelper
|
||||||
include HelperFunctions
|
include HelperFunctions
|
||||||
|
|
||||||
|
MAX_DESC_LENGTH = 80
|
||||||
|
|
||||||
VALID_LOWERCASE_WORDS = %w[
|
VALID_LOWERCASE_WORDS = %w[
|
||||||
iOS
|
iOS
|
||||||
iPhone
|
iPhone
|
||||||
@ -27,8 +29,8 @@ module RuboCop
|
|||||||
desc = desc_call.first_argument
|
desc = desc_call.first_argument
|
||||||
|
|
||||||
# Check if the desc is empty.
|
# Check if the desc is empty.
|
||||||
pure_desc_length = string_content(desc).length
|
desc_length = string_content(desc).length
|
||||||
if pure_desc_length.zero?
|
if 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
|
||||||
@ -64,13 +66,11 @@ module RuboCop
|
|||||||
problem "Description shouldn't end with a full stop."
|
problem "Description shouldn't end with a full stop."
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if the desc length exceeds 80 characters.
|
# Check if the desc length exceeds maximum length.
|
||||||
desc_length = "#{name}: #{string_content(desc)}".length
|
return if desc_length <= MAX_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. " \
|
problem "Description is too long. It should be less than #{MAX_DESC_LENGTH} characters. " \
|
||||||
"The current combined length is #{desc_length}."
|
"The current length is #{desc_length}."
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocorrect_desc(node, name)
|
def autocorrect_desc(node, name)
|
||||||
|
@ -30,7 +30,7 @@ describe RuboCop::Cop::FormulaAudit::Desc do
|
|||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
url 'https://brew.sh/foo-1.0.tgz'
|
url 'https://brew.sh/foo-1.0.tgz'
|
||||||
desc 'Bar#{"bar" * 29}'
|
desc 'Bar#{"bar" * 29}'
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. The current combined length is 95.
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. It should be less than 80 characters. The current length is 90.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
@ -41,7 +41,7 @@ describe RuboCop::Cop::FormulaAudit::Desc do
|
|||||||
url 'https://brew.sh/foo-1.0.tgz'
|
url 'https://brew.sh/foo-1.0.tgz'
|
||||||
desc 'Bar#{"bar" * 9}'\
|
desc 'Bar#{"bar" * 9}'\
|
||||||
'#{"foo" * 21}'
|
'#{"foo" * 21}'
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. The current combined length is 98.
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. It should be less than 80 characters. The current length is 93.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user