Skip to content

analysis: remove default testdata exclude #10

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

Merged
merged 1 commit into from
Apr 20, 2025
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
16 changes: 3 additions & 13 deletions analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ const (
DefaultCopyrightHeaderMatcher = "(?i)copyright"
)

var (
// DefaultMaxConcurrent is the default maximum concurrency to use when
// analyzing files.
DefaultMaxConcurrent = runtime.GOMAXPROCS(0) * 2

// DefaultExcludes are the default files to exclude when analyzing.
DefaultExcludes = []string{
"**/testdata/**", // Exclude testdata directories
}
)
// DefaultMaxConcurrent is the default maximum concurrency to use when
// analyzing files.
var DefaultMaxConcurrent = runtime.GOMAXPROCS(0) * 2

// Config is the golicenser configuration.
type Config struct {
Expand Down Expand Up @@ -96,9 +89,6 @@ func newAnalyzer(cfg Config) (*analyzer, error) {
if cfg.CopyrightHeaderMatcher == "" {
cfg.CopyrightHeaderMatcher = DefaultCopyrightHeaderMatcher
}
if cfg.Exclude == nil {
cfg.Exclude = DefaultExcludes
}

a := &analyzer{cfg: cfg}

Expand Down
28 changes: 9 additions & 19 deletions analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package golicenser

import (
"path/filepath"
"reflect"
"testing"
"time"

Expand All @@ -47,7 +46,6 @@ func TestAnalyzer(t *testing.T) {
Author: "Test",
YearMode: YearModeThisYear,
},
Exclude: []string{},
}
a, err := NewAnalyzer(cfg)
if err != nil {
Expand Down Expand Up @@ -97,7 +95,6 @@ func TestAnalyzer(t *testing.T) {
Matcher: "Copyright \\(c\\) {{.year}} Joshua",
YearMode: YearModeThisYear,
},
Exclude: []string{},
}
a, err := NewAnalyzer(cfg)
if err != nil {
Expand Down Expand Up @@ -169,9 +166,6 @@ func TestNewAnalyzer(t *testing.T) {
t.Errorf("CopyrightHeaderMatcher = %v, want %v",
a.cfg.CopyrightHeaderMatcher, DefaultCopyrightHeaderMatcher)
}
if !reflect.DeepEqual(a.cfg.Exclude, DefaultExcludes) {
t.Errorf("Exclude = %v, want %v", a.cfg.Exclude, DefaultExcludes)
}
},
},
{
Expand All @@ -188,27 +182,23 @@ func TestNewAnalyzer(t *testing.T) {
Header: header,
Exclude: []string{
"/abc/*",
"**/testdata/**",
"", // empty strings should be ignored
"/test/**",
},
},
check: func(t *testing.T, a *analyzer) {
t.Helper()

if l := len(a.excludes); l != 3 {
t.Errorf("excludes len = %d, want 3", l)
if l := len(a.excludes); l != 2 {
t.Errorf("excludes len = %d, want 2", l)
}
tests := map[string]bool{
"afile.go": false,
"/subdir/test": false,
"/abc/": true,
"/abc/test": true,
"/testdata/": true,
"/testdata/abc": true,
"/subdir/testdata/test": true,
"/test/somefile": true,
"/test/": true,
"afile.go": false,
"/subdir/test": false,
"/abc/": true,
"/abc/test": true,
"/test/somefile": true,
"/test/": true,
}
for path, want := range tests {
var excluded bool
Expand Down Expand Up @@ -279,7 +269,7 @@ func TestNewAnalyzer(t *testing.T) {
Header: header,
Exclude: []string{
"/abc/*",
"**/testdata/*{*",
"**/test/*{*",
},
},
wantErr: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/golicenser/golicenser.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func init() {
"Year formatting mode (preserve, preserve-this-year-range, preserve-modified-range, this-year, last-modified, git-range, git-modified-years)")
flagSet.StringVar(&commentStyleStr, "comment-style", golicenser.CommentStyle(0).String(),
"Comment style (line, block)")
flagSet.StringVar(&exclude, "exclude", strings.Join(golicenser.DefaultExcludes, ","),
flagSet.StringVar(&exclude, "exclude", "",
"Paths to exclude (doublestar or r!-prefixed regexp, comma-separated)")
flagSet.IntVar(&maxConcurrent, "max-concurrent", golicenser.DefaultMaxConcurrent,
"Maximum concurrent processes to use when processing files")
Expand Down