Skip to content
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 rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func AllRules() []Rule {
HasRepoDescription{},
HasGitignore{},
HasSubstantialReadme{},
HasLicense{},
}
}

Expand Down Expand Up @@ -48,6 +49,14 @@ func (r HasSubstantialReadme) Check(repo Repo) bool {
return ok && f.Size > 2048
}

// HasLicense checks that a LICENSE or LICENSE.md file exists in the repo root.
type HasLicense struct{}

func (r HasLicense) Name() string { return "Has LICENSE" }
func (r HasLicense) Check(repo Repo) bool {
return hasFile(repo.Files, "LICENSE") || hasFile(repo.Files, "LICENSE.md")
}

func findFile(files []FileEntry, name string) (FileEntry, bool) {
for _, f := range files {
if f.Name == name {
Expand Down
24 changes: 24 additions & 0 deletions rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,27 @@ func TestHasSubstantialReadme_Fail_Missing(t *testing.T) {
t.Error("expected fail when README.md is missing")
}
}

func TestHasLicense_Pass_LICENSE(t *testing.T) {
rule := HasLicense{}

if !rule.Check(Repo{Files: []FileEntry{{Name: "LICENSE"}}}) {
t.Error("expected pass when LICENSE exists")
}
}

func TestHasLicense_Pass_LICENSEmd(t *testing.T) {
rule := HasLicense{}

if !rule.Check(Repo{Files: []FileEntry{{Name: "LICENSE.md"}}}) {
t.Error("expected pass when LICENSE.md exists")
}
}

func TestHasLicense_Fail(t *testing.T) {
rule := HasLicense{}

if rule.Check(Repo{Files: []FileEntry{{Name: "README.md"}}}) {
t.Error("expected fail when no LICENSE file exists")
}
}
Loading