Skip to content

Commit 742293a

Browse files
authored
fix: disallow files containing .go or .yaml ext files when initializing a project
1 parent 9d93a04 commit 742293a

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

pkg/plugins/golang/v4/init.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,12 @@ func checkDir() error {
187187
if isCapitalized && info.Name() != "PROJECT" {
188188
return nil
189189
}
190-
// Allow files in the following list
191-
allowedFiles := []string{
192-
"go.mod", // user might run `go mod init` instead of providing the `--flag` at init
193-
"go.sum", // auto-generated file related to go.mod
194-
}
195-
for _, allowedFile := range allowedFiles {
196-
if info.Name() == allowedFile {
197-
return nil
198-
}
199-
}
200-
// Do not allow any other file
201-
return fmt.Errorf(
202-
"target directory is not empty (only %s, files and directories with the prefix \".\", "+
203-
"files with the suffix \".md\" or capitalized files name are allowed); "+
204-
"found existing file %q", strings.Join(allowedFiles, ", "), path)
190+
// Deny files with .go or .yaml extensions
191+
if strings.HasSuffix(info.Name(), ".go") || strings.HasSuffix(info.Name(), ".yaml") {
192+
return fmt.Errorf("target directory contains disallowed file %q", path)
193+
}
194+
195+
return nil
205196
})
206197
if err != nil {
207198
return err

0 commit comments

Comments
 (0)