Make versioned formulae regex more consistent.

Share the regex where possible and otherwise ensure they are identical.
This commit is contained in:
Mike McQuaid 2018-06-18 14:36:51 +01:00
parent 22d88821c3
commit 5e6c40e28f
5 changed files with 19 additions and 4 deletions

View File

@ -284,8 +284,13 @@ module Homebrew
end end
ignores = [] ignores = []
if f.deps.any? { |dep| dep.name =~ /^go(@[\d\.]+)?$/ } any_go_deps = f.deps.any? do |dep|
ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/go(@[\d\.]+)?/[\d\.]+/libexec} dep.name =~ Version.formula_optionally_versioned_regex(:go)
end
if any_go_deps
go_regex =
Version.formula_optionally_versioned_regex(:go, full: false)
ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d\.]+/libexec}
end end
relocatable = true relocatable = true

View File

@ -7,7 +7,7 @@ module FormulaCellarChecks
formula.name.start_with?(formula_name) formula.name.start_with?(formula_name)
end end
return if formula.name =~ /^php(@?\d+\.?\d*?)?$/ return if formula.name =~ Version.formula_optionally_versioned_regex(:php)
return if MacOS.version < :mavericks && formula.name.start_with?("postgresql") return if MacOS.version < :mavericks && formula.name.start_with?("postgresql")
return if MacOS.version < :yosemite && formula.name.start_with?("memcached") return if MacOS.version < :yosemite && formula.name.start_with?("memcached")

View File

@ -290,7 +290,7 @@ module RuboCop
find_every_method_call_by_name(body_node, :system).each do |method_node| find_every_method_call_by_name(body_node, :system).each do |method_node|
# Skip Kibana: npm cache edge (see formula for more details) # Skip Kibana: npm cache edge (see formula for more details)
next if @formula_name =~ /^kibana(\@\d+(\.\d+)?)?$/i next if @formula_name =~ /^kibana(@\d[\d.]*)?$/
first_param, second_param = parameters(method_node) first_param, second_param = parameters(method_node)
next if !node_equals?(first_param, "npm") || next if !node_equals?(first_param, "npm") ||
!node_equals?(second_param, "install") !node_equals?(second_param, "install")

View File

@ -1,5 +1,11 @@
require "version" require "version"
describe Version do
specify ".formula_optionally_versioned_regex" do
expect(described_class.formula_optionally_versioned_regex("foo")).to match("foo@1.2")
end
end
describe Version::Token do describe Version::Token do
specify "#inspect" do specify "#inspect" do
expect(described_class.new("foo").inspect).to eq('#<Version::Token "foo">') expect(described_class.new("foo").inspect).to eq('#<Version::Token "foo">')

View File

@ -3,6 +3,10 @@ require "version/null"
class Version class Version
include Comparable include Comparable
def self.formula_optionally_versioned_regex(name, full: true)
/#{"^" if full}#{Regexp.escape(name)}(@\d[\d.]*)?#{"$" if full}/
end
class Token class Token
include Comparable include Comparable