Модуль: RuboCop::Cop::HomepageHelper Приватный
- Подключает:
- HelperFunctions
- Включён в:
- Cask::HomepageUrlStyling, FormulaAudit::Homepage
- Определён в:
- rubocops/shared/homepage_helper.rb
Обзор
Этот модуль является частью приватного API. Этот модуль можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности не следует использовать этот модуль, поскольку он может быть удалён или изменён без предупреждения.
Этот модуль выполняет общие проверки поля homepage в формулах и cask.
Краткое описание методов экземпляра свернуть
Методы, подключённые из 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_homepage(type, content, homepage_node, homepage_parameter_node) ⇒ void
Этот метод является частью приватного API. Этот метод можно использовать только в репозитории Homebrew/brew. Сторонним разработчикам по возможности не следует использовать этот метод, поскольку он может быть удалён или изменён без предупреждения.
Этот метод возвращает неопределённое значение.
19 20 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 86 87 88 89 90 91 92 93 94 95 96 97 98 | # File 'rubocops/shared/homepage_helper.rb', line 19 def audit_homepage(type, content, homepage_node, homepage_parameter_node) @offensive_node = T.let(homepage_node, T.nilable(RuboCop::AST::Node)) problem "#{type.to_s.capitalize} should have a `homepage`." if content.empty? @offensive_node = homepage_parameter_node problem "The `homepage` should start with http or https." unless content.match?(%r{^https?://}) case content # Freedesktop is complicated to handle - It has SSL/TLS, but only on certain subdomains. # To enable https Freedesktop change the URL from http://project.freedesktop.org/wiki to # https://wiki.freedesktop.org/project_name. # "Software" is redirected to https://wiki.freedesktop.org/www/Software/project_name when %r{^http://((?:www|nice|libopenraw|liboil|telepathy|xorg)\.)?freedesktop\.org/(?:wiki/)?} if content.include?("Software") problem "Freedesktop homepages should be styled: https://wiki.freedesktop.org/www/Software/project_name" else problem "Freedesktop homepages should be styled: https://wiki.freedesktop.org/project_name" end # Google Code homepages should end in a slash when %r{^https?://code\.google\.com/p/[^/]+[^/]$} problem "Google Code homepages should end with a slash" do |corrector| corrector.replace(homepage_parameter_node.source_range, "\"#{content}/\"") end when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)} fixed = "https://#{Regexp.last_match(1)}.sourceforge.io/" problem "SourceForge homepages should be: #{fixed}" do |corrector| corrector.replace(homepage_parameter_node.source_range, "\"#{fixed}\"") end when /readthedocs\.org/ fixed = content.sub("readthedocs.org", "readthedocs.io") problem "Readthedocs homepages should be: #{fixed}" do |corrector| corrector.replace(homepage_parameter_node.source_range, "\"#{fixed}\"") end when %r{^https://github.com.*\.git$} problem "GitHub homepages should not end with .git" do |corrector| corrector.replace(homepage_parameter_node.source_range, "\"#{content.delete_suffix(".git")}\"") end # People will run into mixed content sometimes, but we should enforce and then add # exemptions as they are discovered. Treat mixed content on homepages as a bug. # Justify each exemptions with a code comment so we can keep track here. # # Compact the above into this list as we're able to remove detailed notations, etc over time. when # Check for `http://` GitHub homepage URLs, `https://` is preferred. # NOTE: Only check homepages that are repository pages, not `*.github.com` hosts. %r{^http://github\.com/}, %r{^http://[^/]*\.github\.io/}, # Savannah has full SSL/TLS support but no auto-redirect. # Doesn't apply to the download URLs, only the homepage. %r{^http://savannah\.nongnu\.org/}, %r{^http://[^/]*\.sourceforge\.io/}, # There's an auto-redirect here, but this mistake is incredibly common too. # Only applies to the homepage and subdomains for now, not the FTP URLs. %r{^http://((?:build|cloud|developer|download|extensions|git| glade|help|library|live|nagios|news|people| projects|rt|static|wiki|www)\.)?gnome\.org}x, %r{^http://[^/]*\.apache\.org}, %r{^http://packages\.debian\.org}, %r{^http://wiki\.freedesktop\.org/}, %r{^http://((?:www)\.)?gnupg\.org/}, %r{^http://ietf\.org}, %r{^http://[^/.]+\.ietf\.org}, %r{^http://[^/.]+\.tools\.ietf\.org}, %r{^http://www\.gnu\.org/}, %r{^http://code\.google\.com/}, %r{^http://bitbucket\.org/}, %r{^http://(?:[^/]*\.)?archive\.org} problem "Please use https:// for #{content}" do |corrector| corrector.replace(homepage_parameter_node.source_range, "\"#{content.sub("http", "https")}\"") end end end |
© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/RuboCop/Cop/HomepageHelper.html