formula_auditor: new formulas should not define a revision

Logically new formulas should start at revision 0, but a
developer might use an existing formula as a template and
otherwise not realize they should remove this field.

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
This commit is contained in:
Josh Soref 2022-02-09 04:24:58 -05:00
parent 07867e372d
commit 37fd64b5a3
2 changed files with 30 additions and 11 deletions

View File

@ -674,6 +674,8 @@ module Homebrew
end end
def audit_revision_and_version_scheme def audit_revision_and_version_scheme
new_formula_problem("New formulae should not define a revision.") if @new_formula && !formula.revision.zero?
return unless @git return unless @git
return unless formula.tap # skip formula not from core or any taps return unless formula.tap # skip formula not from core or any taps
return unless formula.tap.git? # git log is required return unless formula.tap.git? # git log is required

View File

@ -854,18 +854,12 @@ module Homebrew
end end
describe "#audit_revision_and_version_scheme" do describe "#audit_revision_and_version_scheme" do
subject {
fa = described_class.new(Formulary.factory(formula_path), git: true)
fa.audit_revision_and_version_scheme
fa.problems.first&.fetch(:message)
}
let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" }
let(:foo_version) { Count.increment }
let(:formula_subpath) { "Formula/foo#{foo_version}.rb" }
let(:origin_formula_path) { origin_tap_path/formula_subpath }
let(:tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-bar" }
let(:formula_path) { tap_path/formula_subpath } let(:formula_path) { tap_path/formula_subpath }
let(:tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-bar" }
let(:origin_formula_path) { origin_tap_path/formula_subpath }
let(:formula_subpath) { "Formula/foo#{foo_version}.rb" }
let(:foo_version) { Count.increment }
let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" }
before do before do
origin_formula_path.dirname.mkpath origin_formula_path.dirname.mkpath
@ -891,6 +885,29 @@ module Homebrew
end end
end end
describe "new formulae should not have a revision" do
it "doesn't allow new formulae to have a revision" do
fa = formula_auditor "foo", <<~RUBY, new_formula: true
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
revision 1
end
RUBY
fa.audit_revision_and_version_scheme
expect(fa.new_formula_problems).to include(
a_hash_including(message: a_string_matching(/should not define a revision/)),
)
end
end
subject {
fa = described_class.new(Formulary.factory(formula_path), git: true)
fa.audit_revision_and_version_scheme
fa.problems.first&.fetch(:message)
}
def formula_gsub(before, after = "") def formula_gsub(before, after = "")
text = formula_path.read text = formula_path.read
text.gsub! before, after text.gsub! before, after