Repository: goreleaser/goreleaser
Pull request #2205 (2021-05-06 19:04:10)

fix: allow underscores in formula name
I was trying to create two formulas per release. One signifying the latest and
another with the version explicitly: formula.rb and formula@v0.0.0.rb

The filenames are fine but the formula name for the explicit version
was created as FormulaATv0.0.0 which isn't valid Ruby.

Looking at the function history I couldn't find why underscores were being replaced
since underscores are valid for Ruby identifiers. I opted to replace dots in a formula with
underscores

- https://github.com/goreleaser/goreleaser/commit/1399a396036ea246522a4cbae7aef376d6dbbda2
- https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#ident

<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Please fill the fields above:

-->

<!-- If applied, this commit will... -->

<!-- Why is this change being made? -->

<!-- # Provide links to any relevant tickets, URLs or other resources -->


vercel[bot]: @kreempuff is attempting to deploy a commit to the **Goreleaser** Team on [Vercel](https://vercel.com).

A member of the Team first needs to [authorize it](https://vercel.com/git/authorize?team=Goreleaser&type=github&job=%7B%22headInfo%22%3A%7B%22sha%22%3A%22e2d9f7afd631ec4de7c4706cf58fd061a48158aa%22%7D%2C%22id%22%3A%22QmdxnwoUCZjEZ9Kpd8RcjFgkAbGt56qME2aYAZ4MCUAJZr%22%2C%22org%22%3A%22goreleaser%22%2C%22prId%22%3A2205%2C%22repo%22%3A%22goreleaser%22%7D).


caarlos0: build will fail, as I'm pretty sure there are tests for this...
caarlos0: > Looking at the function history I couldn't find why underscores were being replaced
> since underscores are valid for Ruby identifiers. I opted to replace dots in a formula with
> underscores

don't recall as well...
kreempuff: > build will fail, as I'm pretty sure there are tests for this...

Makes sense, I'll update failing ones
kreempuff: I think underscores are removed to make the Formula name cleaner

I reverted the change, added what I wanted, and added a comment on the function

Patch:
diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go
index 69b17039..4ce25a8d 100644
--- a/internal/pipe/brew/brew.go
+++ b/internal/pipe/brew/brew.go
@@ -323,9 +323,14 @@ func split(s string) []string {
 	return strings
 }
 
+// formulaNameFor transforms the formula name into a form
+// that more resembles a valid Ruby class name
+// e.g. foo_bar@v6.0.0-rc is turned into FooBarATv6_0_0RC
+// The order of these replacements is important
 func formulaNameFor(name string) string {
 	name = strings.ReplaceAll(name, "-", " ")
 	name = strings.ReplaceAll(name, "_", " ")
+	name = strings.ReplaceAll(name, ".", "_")
 	name = strings.ReplaceAll(name, "@", "AT")
 	return strings.ReplaceAll(strings.Title(name), " ", "")
 }


Test patch:
diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go
index 3f7f46fc..af8df084 100644
--- a/internal/pipe/brew/brew_test.go
+++ b/internal/pipe/brew/brew_test.go
@@ -31,6 +31,10 @@ func TestNameWithUnderline(t *testing.T) {
 	require.Equal(t, formulaNameFor("some_binary"), "SomeBinary")
 }
 
+func TestNameWithDots(t *testing.T) {
+	require.Equal(t, formulaNameFor("binaryv0.0.0"), "Binaryv0_0_0")
+}
+
 func TestNameWithAT(t *testing.T) {
 	require.Equal(t, formulaNameFor("some_binary@1"), "SomeBinaryAT1")
 }