Skip to content

Commit 4e37805

Browse files
committed
fix: disallow files containing unwanted extension files when initializing a project
1 parent 9d93a04 commit 4e37805

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

pkg/plugins/golang/v4/init.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,23 @@ 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
190+
// Deny files with .go or .yaml extensions
191+
disallowedExtensions := []string{
192+
".go",
193+
".yaml",
194+
".mod",
195+
".sum",
194196
}
195-
for _, allowedFile := range allowedFiles {
196-
if info.Name() == allowedFile {
197-
return nil
197+
for _, ext := range disallowedExtensions {
198+
if strings.HasSuffix(info.Name(), ext) {
199+
return fmt.Errorf(
200+
"target directory is not empty and contains a disallowed file %q \".\", "+
201+
"files with the following extensions [%s] are not allowed to avoid conflicts with the tooling.",
202+
path, strings.Join(disallowedExtensions, ", "))
198203
}
199204
}
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)
205+
206+
return nil
205207
})
206208
if err != nil {
207209
return err

0 commit comments

Comments
 (0)