Spec-Zone.ru › Homebrew

Модуль: RuboCop::Cop::DescHelper Приватный

Подключает:
HelperFunctions
Подключён в:
Cask::Desc, FormulaAudit::Desc
Определён в:
rubocops/shared/desc_helper.rb,
rubocops/shared/desc_helper.rbi

Этот модуль является частью приватного API. Этот модуль можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности следует избегать использования этого модуля, поскольку он может быть удалён или изменён без предупреждения.

Краткое описание констант свернуть

MAX_DESC_LENGTH =

Эта константа является частью приватного API. Эту константу можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности следует избегать использования этой константы, поскольку она может быть удалена или изменена без предупреждения.

80
VALID_LOWERCASE_WORDS =

Эта константа является частью приватного API. Эту константу можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности следует избегать использования этой константы, поскольку она может быть удалена или изменена без предупреждения.

%w[iOSiPhonemacOS].freeze

Краткое описание методов экземпляра свернуть

  • #audit_desc(type, name, desc_call) ⇒ void приватный
  • #desc_problem(message) ⇒ void приватный

    Автоматически исправляет проблемы с описанием.

Методы, подключённые из HelperFunctions

#block_method_called_in_block?, #check_precedence, #class_name, #component_precedes?, #end_column, #expression_negated?, #find_all_blocks, #find_block, #find_blocks, #find_const, #find_every_func_call_by_name, #find_every_method_call_by_name, #find_instance_call, #find_instance_method_call, #find_method_calls_by_name, #find_method_def, #find_method_with_args, #find_node_method_by_name, #find_strings, #format_component, #line_number, #line_start_column, #method_called?, #method_called_ever?, #method_name, #node_equals?, #offending_node, #parameters, #parameters_passed?, #problem, #regex_match_group, #source_buffer, #start_column, #string_content

Подробное описание методов экземпляра

#audit_desc(type, name, desc_call) ⇒ void

Этот метод является частью приватного API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности следует избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Этот метод возвращает неопределённое значение.

Параметры:

  • type (Symbol)
  • name (String, nil)
  • desc_call (RuboCop::AST::Node, nil)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'rubocops/shared/desc_helper.rb', line 21

def audit_desc(type, name, desc_call)
  # Check if a desc is present.
  if desc_call.nil?
    problem "#{type.to_s.capitalize} should have a `desc` (description)."
    return
  end

  @offensive_node = T.let(desc_call, T.nilable(RuboCop::AST::Node))
  @name = T.let(name, T.nilable(String))

  desc = T.cast(desc_call, RuboCop::AST::SendNode).first_argument

  # Check if the desc is empty.
  desc_length = string_content(desc).length
  if desc_length.zero?
    problem "The `desc` (description) should not be an empty string."
    return
  end

  # Check the desc for leading whitespace.
  desc_problem "Description shouldn't have leading spaces." if regex_match_group(desc, /^\s+/)

  # Check the desc for trailing whitespace.
  desc_problem "Description shouldn't have trailing spaces." if regex_match_group(desc, /\s+$/)

  # Check if "command-line" is spelled incorrectly in the desc.
  if (match = regex_match_group(desc, /(command ?line)/i))
    c = match.to_s[0]
    desc_problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"."
  end

  # Check if the desc starts with an article.
  desc_problem "Description shouldn't start with an article." if regex_match_group(desc, /^(the|an?)(?=\s)/i)

  # Check if invalid lowercase words are at the start of a desc.
  if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) && regex_match_group(desc, /^[a-z]/)
    desc_problem "Description should start with a capital letter."
  end

  # Check if the desc starts with the formula's or cask's name.
  name_regex = T.must(name).delete("-").chars.join('[\s\-]?')
  if regex_match_group(desc, /^#{name_regex}\b/i)
    desc_problem "Description shouldn't start with the #{type} name."
  end

  if type == :cask &&
     (match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)(?! virtual machines?)\b/i)) &&
     match[1] != "MAC"
    add_offense(@offensive_source_range, message: "Description shouldn't contain the platform.")
  end

  # Check if a full stop is used at the end of a desc (apart from in the case of "etc.").
  if regex_match_group(desc, /\.$/) && !string_content(desc).end_with?("etc.")
    desc_problem "Description shouldn't end with a full stop."
  end

  # Check if the desc contains Unicode emojis or symbols (Unicode Other Symbols category).
  desc_problem "Description shouldn't contain Unicode emojis or symbols." if regex_match_group(desc, /\p{So}/)

  # Check if the desc length exceeds maximum length.
  return if desc_length <= MAX_DESC_LENGTH

  problem "Description is too long. It should be less than #{MAX_DESC_LENGTH} characters. " \
          "The current length is #{desc_length}."
end

#desc_problem(message) ⇒ void

Этот метод является частью приватного API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности следует избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.

Этот метод возвращает неопределённое значение.

Автоматически исправляет проблемы с описанием. regex_match_group необходимо вызвать до этого метода, чтобы заполнить @offense_source_range.

Параметры:

  • message (String)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'rubocops/shared/desc_helper.rb', line 89

def desc_problem(message)
  add_offense(@offensive_source_range, message:) do |corrector|
    match_data = T.must(@offensive_node).source.match(/\A(?<quote>["'])(?<correction>.*)(?:\k<quote>)\Z/)
    correction = match_data[:correction]
    quote = match_data[:quote]

    next if correction.nil?

    correction.gsub!(/^\s+/, "")
    correction.gsub!(/\s+$/, "")

    correction.sub!(/^(the|an?)\s+/i, "")

    first_word = correction.split.first
    unless VALID_LOWERCASE_WORDS.include?(first_word)
      first_char = first_word.to_s[0]
      correction[0] = first_char.upcase if first_char
    end

    correction.gsub!(/(ommand ?line)/i, "ommand-line")
    correction.gsub!(/(^|[^a-z])#{@name}([^a-z]|$)/i, "\\1\\2")
    correction.gsub!(/\s?\p{So}/, "")
    correction.gsub!(/^\s+/, "")
    correction.gsub!(/\s+$/, "")
    correction.gsub!(/\.$/, "")

    next if correction == match_data[:correction]

    corrector.replace(@offensive_node&.source_range, "#{quote}#{correction}#{quote}")
  end
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/RuboCop/Cop/DescHelper.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API