Skip to content

Commit

Permalink
Fixed build errors, addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vogJust committed Aug 7, 2024
1 parent e12c0ba commit 612e960
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions cmd/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,35 @@ func getFlags() (validatorConfig, error) {
return validatorConfig{}, err
}
uncheckedType := strings.Split(pair, ":")
fileName, fileType := uncheckedType[0], uncheckedType[1]
fileName, typeName := uncheckedType[0], uncheckedType[1]
isFoundType := false
for _, fileType := range filetype.FileTypes {
if fileType.Name == fileType {
if fileType.Name == typeName {
isFoundType = true
break
}
}
if !isFoundType {
err := fmt.Errorf("Invalid file type for unchecked file: %s. Only supported formats accepted", pair)
fmt.Println(errorMsg)
errMsg := fmt.Errorf("Invalid file type for unchecked file: %s. Only supported formats accepted", pair)
fmt.Println(errMsg)
flag.Usage()
return validatorConfig{}, errors.New(errorMsg)
return validatorConfig{}, errMsg
}

info, err := os.Stat(fileName)

if err != nil {
errorMsg := "File not found for unchecked file: " + fileName + ". Must add existing file path"
fmt.Println(errorMsg)
errMsg := fmt.Errorf("File not found for unchecked file: %s. Must add existing file path", fileName)
fmt.Println(errMsg)
flag.Usage()
return validatorConfig{}, errors.New(errorMsg)
return validatorConfig{}, errMsg
}

if info.IsDir() {
errorMsg := "File path for " + pair + " leads to a directory, not a valid file."
fmt.Println(errorMsg)
errMsg := fmt.Errorf("File path for %s leads to a directory, not a valid file.", pair)
fmt.Println(errMsg)
flag.Usage()
return validatorConfig{}, errors.New(errorMsg)
return validatorConfig{}, errMsg
}
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func mainInit() int {
finder.WithPathRoots(validatorConfig.searchPaths...),
finder.WithExcludeDirs(excludeDirs),
finder.WithExcludeFileTypes(excludeFileTypes),
finder.AddFiles(uncheckedFiles),
finder.AddFiles(uncheckedFiles, isFlagSet("unchecked-files")),
finder.StoreConfig(*validatorConfig.configFile),
}
quiet := *validatorConfig.quiet
Expand Down
14 changes: 7 additions & 7 deletions pkg/finder/fsfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ func WithDepth(depthVal int) FSFinderOptions {
}

// AddFiles adds unchecked files with specified formats to FSFinder (adds support for extensionless files)
func AddFiles(files []string) FSFinderOptions {
func AddFiles(files []string, filesPresent bool) FSFinderOptions {
return func(fsf *FileSystemFinder) {
if len(files) == 0 {
if !filesPresent {
return
}
fsf.UncheckedFiles= make(map[string]string)
for i := range files {
kv := strings.Split(files[i], ":")
// Creating <file name/dir>:<file type> mapping to link extensionless files with their actual format
path, format := kv[0], kv[1]
fsf.UncheckedFiles[filepath.Clean(path)] = kv[format]
fsf.UncheckedFiles[filepath.Clean(path)] = format
}
}
}
Expand Down Expand Up @@ -107,10 +107,10 @@ func ReadConfig(file string, fsf FileSystemFinder) (map[string]string, error) {
for key, value := range data {
for _, val := range value {
strVal, ok := val.(string)
if !ok {
continue
}
fsf.UncheckedFiles.Add(strVal, key)
if !ok {
continue
}
fsf.UncheckedFiles[filepath.Clean(strVal)] = key
}
}
return fsf.UncheckedFiles, nil
Expand Down

0 comments on commit 612e960

Please sign in to comment.