From 23fbd3fb827b99516fc367d2d51e79c48d348005 Mon Sep 17 00:00:00 2001 From: packet-mover Date: Sun, 5 Apr 2026 23:07:34 +0200 Subject: [PATCH] feat: add Has LICENSE rule Check for LICENSE or LICENSE.md in the repo root. Co-Authored-By: Claude Opus 4.6 (1M context) --- rules.go | 9 +++++++++ rules_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/rules.go b/rules.go index 61347d5..bdbf895 100644 --- a/rules.go +++ b/rules.go @@ -20,6 +20,7 @@ func AllRules() []Rule { HasRepoDescription{}, HasGitignore{}, HasSubstantialReadme{}, + HasLicense{}, } } @@ -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 { diff --git a/rules_test.go b/rules_test.go index 0f27679..52c5f75 100644 --- a/rules_test.go +++ b/rules_test.go @@ -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") + } +}