Skip to content

Commit b91a441

Browse files
committed
Force all readme filenames to be exactly README.md (following @pellared comment)
Signed-off-by: Eliott Bouhana <[email protected]>
1 parent a11488c commit b91a441

File tree

1 file changed

+7
-22
lines changed
  • internal/tools/verifyreadmes

1 file changed

+7
-22
lines changed

internal/tools/verifyreadmes/main.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ var excludedDirs = []string{
2121
"/.",
2222
}
2323

24-
// readmeFiles is a list of possible README file names to check for in lowercase
25-
var readmeFiles = []string{
26-
"readme.md",
27-
"readme.rst",
28-
"readme.txt",
29-
"readme",
30-
}
24+
const readmeFilename = "README.md"
3125

3226
// verifyReadme is a [os.WalkFunc] that checks if a README.md exists in the same directory as the go.mod file.
3327
func verifyReadme(path string, info os.FileInfo, err error) error {
@@ -46,24 +40,15 @@ func verifyReadme(path string, info os.FileInfo, err error) error {
4640
}
4741
}
4842

49-
folder := filepath.Dir(path)
50-
entries, err := os.ReadDir(folder)
51-
if err != nil {
52-
return err
53-
}
5443

55-
for _, entry := range entries {
56-
if entry.IsDir() {
57-
continue
58-
}
59-
for _, readme := range readmeFiles {
60-
if strings.EqualFold(entry.Name(), readme) {
61-
return nil
62-
}
63-
}
44+
// Check that a README.md exists in the same directory as the go.mod file.
45+
readme := filepath.Join(filepath.Dir(path), readmeFilename)
46+
_, err = os.Stat(readme)
47+
if os.IsNotExist(err) {
48+
err = fmt.Errorf("couldn't find README.md for %q", filepath.Dir(path))
6449
}
6550

66-
return fmt.Errorf("couldn't find README.md for %q", folder)
51+
return err
6752
}
6853

6954
func main() {

0 commit comments

Comments
 (0)