Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific filter for normalization (composer autoload) #26

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"unicode/utf8"

Expand All @@ -21,6 +22,10 @@ func isCmsRoot(root string) bool {
return false
}

var normalizeRx = []*regexp.Regexp{
regexp.MustCompile(`'reference' => '[a-f0-9]{40}',`),
}

func normalizeLine(b []byte) []byte {
// Also strip slashes comments etc
b = bytes.TrimSpace(b)
Expand All @@ -29,6 +34,10 @@ func normalizeLine(b []byte) []byte {
return []byte{}
}
}

for _, rx := range normalizeRx {
b = rx.ReplaceAllLiteral(b, nil)
}
return b
}

Expand Down
22 changes: 21 additions & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package main

import "testing"
import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_pathIsExcluded(t *testing.T) {
tests := []struct {
Expand All @@ -20,3 +24,19 @@ func Test_pathIsExcluded(t *testing.T) {
})
}
}

func Test_normalizeLine(t *testing.T) {
tests := []struct {
arg string
want string
}{
{"\t'reference' => '836ce4bde75ef67a1b4b2230ea725773adca2de7',\n", ""},
{"reference\n", "reference"},
{"reference' => '1234567890',", "reference' => '1234567890',"},
}
for _, tt := range tests {
t.Run(string(tt.arg), func(t *testing.T) {
assert.Equal(t, tt.want, string(normalizeLine([]byte(tt.arg))))
})
}
}
Loading