Класс: RuboCop::Cop::Cask::Url Частный
- Наследуется от:
- Base
- Object
- Base
- RuboCop::Cop::Cask::Url
- Расширен модулем:
- AutoCorrector
- Подключает:
- OnUrlStanza, UrlHelper
- Определён в:
- rubocops/cask/url.rb
Обзор
Этот класс является частью закрытого API. Этот класс можно использовать только в репозитории Homebrew/brew. Третьим сторонам следует по возможности избегать использования этого класса, поскольку он может быть удалён или изменён без предупреждения.
Это правило проверяет, правильно ли отформатирована секция url кэска.
Пример
# bad
url "https://example.com/download/foo.dmg",
verified: "https://example.com/download"
# good
url "https://example.com/download/foo.dmg",
verified: "example.com/download/"
Известные прямые подклассы
Краткое описание методов экземпляра свернуть
- #on_url_stanza(stanza) ⇒ void частный
Методы, подключённые из UrlHelper
Методы, подключённые из 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
Методы, подключённые из OnUrlStanza
Методы, подключённые из CaskHelp
#cask_tap, #inner_stanzas, #on_block, #on_cask, #on_cask_stanza_block, #on_system_methods
Подробное описание методов экземпляра
#on_url_stanza(stanza) ⇒ void
Этот метод является частью закрытого API. Этот метод можно использовать только в репозитории Homebrew/brew. Третьим сторонам следует по возможности избегать использования этого метода, поскольку он может быть удалён или изменён без предупреждения.
Этот метод возвращает неопределённое значение.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | # File 'rubocops/cask/url.rb', line 28 def on_url_stanza(stanza) if stanza.stanza_node.block_type? if cask_tap == "homebrew-cask" add_offense(stanza.stanza_node, message: 'Do not use `url "..." do` blocks in Homebrew/homebrew-cask.') end return end stanza_node = T.cast(stanza.stanza_node, RuboCop::AST::SendNode) url_stanza = stanza_node.first_argument hash_node = stanza_node.last_argument if url_stanza.nil? || url_stanza.hash_type? add_offense(stanza_node.source_range, message: "The `url` stanza requires a URL argument.") return end audit_url(:cask, [stanza_node], [], livecheck_urls: []) if cask_tap == "homebrew-cask" && !url_stanza.type?(:str, :dstr) add_offense(url_stanza.source_range, message: "Casks in homebrew/cask should use string literal URLs.") end # Check for http:// URLs in homebrew-cask (skip deprecated/disabled casks) # TODO: Remove the deprecated/disabled check after Homebrew/cask has no more # deprecated/disabled casks using http:// URLs deprecated_or_disabled = toplevel_stanzas.any? { |s| [:deprecate!, :disable!].include?(s.stanza_name) } if cask_tap == "homebrew-cask" && !deprecated_or_disabled && url_stanza.source.match?(%r{^"http://}) add_offense( stanza_node.source_range, message: "Casks in homebrew/cask should not use http:// URLs", ) do |corrector| corrector.replace(stanza_node.source_range, stanza_node.source.sub("http://", "https://")) end end return unless hash_node.hash_type? # TODO: also enforce that each keyword parameter after the first # starts on its own line (e.g. `verified:` and `header:` # should not share a line). if hash_node.first_line <= url_stanza.last_line || hash_node.loc.column <= stanza_node.loc.column add_offense( stanza_node.source_range, message: "Keyword URL parameter should be on a new indented line.", ) do |corrector| corrector.replace( range_between(url_stanza.source_range.end_pos, hash_node.source_range.begin_pos), ",\n#{"" * url_stanza.loc.column}", ) end end hash_node.each_pair do |key_node, value_node| next if key_node.source != "verified" next unless value_node.str_type? if value_node.source.start_with?(%r{^"https?://}) add_offense( value_node.source_range, message: "Verified URL parameter value should not contain a URL scheme.", ) do |corrector| corrector.replace(value_node.source_range, value_node.source.gsub(%r{^"https?://}, "\"")) end end # Skip if the URL and the verified value are the same. next if value_node.source == url_stanza.source.gsub(%r{^"https?://}, "\"") # Skip if the URL has two path components, e.g. `https://github.com/google/fonts.git`. next if url_stanza.source.gsub(%r{^"https?://}, "\"").count("/") == 2 # Skip if the verified value ends with a slash. next if value_node.str_content.end_with?("/") add_offense( value_node.source_range, message: "Verified URL parameter value should end with a /.", ) do |corrector| corrector.replace(value_node.source_range, value_node.source.gsub(/"$/, "/\"")) end end end |
© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/RuboCop/Cop/Cask/Url.html