Skip to content

Commit d2968d1

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

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pkg/plugins/golang/v4/init.go

+11-9
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+
disallowedExtensions := []string{
191+
".go",
192+
".yaml",
193+
".mod",
194+
".sum",
194195
}
195-
for _, allowedFile := range allowedFiles {
196-
if info.Name() == allowedFile {
196+
// Deny files with .go or .yaml or .mod or .sum extensions
197+
for _, ext := range disallowedExtensions {
198+
if strings.HasSuffix(info.Name(), ext) {
197199
return nil
198200
}
199201
}
200202
// Do not allow any other file
201203
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)
204+
"target directory is not empty and contains a disallowed file %q. "+
205+
"files with the following extensions [%s] are not allowed to avoid conflicts with the tooling.",
206+
path, strings.Join(disallowedExtensions, ", "))
205207
})
206208
if err != nil {
207209
return err

0 commit comments

Comments
 (0)