mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
style: autocorrect readthedocs and GitHub .git homepages
This commit is contained in:
parent
468e96734f
commit
1c5e73a578
@ -58,6 +58,14 @@ module RuboCop
|
|||||||
when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)}
|
when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)}
|
||||||
problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`"
|
problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`"
|
||||||
|
|
||||||
|
when /readthedocs\.org/
|
||||||
|
offending_node(parameters(homepage_node).first)
|
||||||
|
problem "#{homepage} should be `#{homepage.sub("readthedocs.org", "readthedocs.io")}`"
|
||||||
|
|
||||||
|
when %r{^https://github.com.*\.git}
|
||||||
|
offending_node(parameters(homepage_node).first)
|
||||||
|
problem "GitHub URLs (`#{homepage}`) should not end with .git"
|
||||||
|
|
||||||
# There's an auto-redirect here, but this mistake is incredibly common too.
|
# 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.
|
# Only applies to the homepage and subdomains for now, not the FTP URLs.
|
||||||
when %r{^http://((?:build|cloud|developer|download|extensions|git|
|
when %r{^http://((?:build|cloud|developer|download|extensions|git|
|
||||||
@ -80,6 +88,17 @@ module RuboCop
|
|||||||
problem "Please use https:// for #{homepage}"
|
problem "Please use https:// for #{homepage}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autocorrect(node)
|
||||||
|
lambda do |corrector|
|
||||||
|
return if node.nil?
|
||||||
|
|
||||||
|
homepage = string_content(node)
|
||||||
|
homepage.sub!("readthedocs.org", "readthedocs.io")
|
||||||
|
homepage.delete_suffix!(".git") if homepage.start_with?("https://github.com")
|
||||||
|
corrector.replace(node.source_range, "\"#{homepage}\"")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -62,6 +62,8 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
|
|||||||
"sf3" => "http://foo.sf.net/",
|
"sf3" => "http://foo.sf.net/",
|
||||||
"sf4" => "http://foo.sourceforge.io/",
|
"sf4" => "http://foo.sourceforge.io/",
|
||||||
"waldo" => "http://www.gnu.org/waldo",
|
"waldo" => "http://www.gnu.org/waldo",
|
||||||
|
"dotgit" => "https://github.com/foo/bar.git",
|
||||||
|
"rtd" => "https://foo.readthedocs.org",
|
||||||
}
|
}
|
||||||
|
|
||||||
formula_homepages.each do |name, homepage|
|
formula_homepages.each do |name, homepage|
|
||||||
@ -101,6 +103,18 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
|
|||||||
line: 2,
|
line: 2,
|
||||||
column: 2,
|
column: 2,
|
||||||
source: source }]
|
source: source }]
|
||||||
|
elsif homepage.match?("https://github.com/foo/bar.git")
|
||||||
|
expected_offenses = [{ message: "GitHub URLs (`#{homepage}`) should not end with .git",
|
||||||
|
severity: :convention,
|
||||||
|
line: 2,
|
||||||
|
column: 11,
|
||||||
|
source: source }]
|
||||||
|
elsif homepage.match?("https://foo.readthedocs.org")
|
||||||
|
expected_offenses = [{ message: "#{homepage} should be `https://foo.readthedocs.io`",
|
||||||
|
severity: :convention,
|
||||||
|
line: 2,
|
||||||
|
column: 11,
|
||||||
|
source: source }]
|
||||||
else
|
else
|
||||||
expected_offenses = [{ message: "Please use https:// for #{homepage}",
|
expected_offenses = [{ message: "Please use https:// for #{homepage}",
|
||||||
severity: :convention,
|
severity: :convention,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user