Skip to content

Commit

Permalink
refactor: fix for lint
Browse files Browse the repository at this point in the history
Signed-off-by: 170210 <j170210@icloud.com>
  • Loading branch information
170210 committed Aug 1, 2023
1 parent 8d056a0 commit a640923
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
3 changes: 1 addition & 2 deletions tools/error_doc/const_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func getConst(line string) (string, string, error) {
i := strings.TrimSpace(parts[0])
val := strings.Trim(strings.TrimSpace(parts[1]), `"`)
return i, val, nil
} else {
return "", "", errors.New("failed to get the value in: " + line)
}
return "", "", errors.New("failed to get the value in: " + line)
}
13 changes: 4 additions & 9 deletions tools/error_doc/error_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ func (err errorInfo) toString(moduleName string) (string, error) {
if err.codeSpace == "ModuleName" {
if moduleName == "" {
return "", errors.New("failed to find moduleName")
} else {
return fmt.Sprintf(errorInfoTemplate, err.errorName, moduleName, err.code, err.description), nil
}
} else {
return fmt.Sprintf(errorInfoTemplate, err.errorName, err.codeSpace, err.code, err.description), nil
return fmt.Sprintf(errorInfoTemplate, err.errorName, moduleName, err.code, err.description), nil
}
return fmt.Sprintf(errorInfoTemplate, err.errorName, err.codeSpace, err.code, err.description), nil
}

func addError(line string, errorDict map[string]string) (errorInfo, error) {
Expand Down Expand Up @@ -55,13 +53,10 @@ func addError(line string, errorDict map[string]string) (errorInfo, error) {
code: code,
description: description,
}, nil
} else {
return errorInfo{}, errors.New("failed to get error info in: " + line)
}
} else {
return errorInfo{}, errors.New("failed to parse error info in: " + line)
return errorInfo{}, errors.New("failed to get error info in: " + line)
}

return errorInfo{}, errors.New("failed to parse error info in: " + line)
}

func getErrors(p string) ([]errorInfo, error) {
Expand Down
8 changes: 5 additions & 3 deletions tools/error_doc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ func findModuleWithFiles(targetPath string) (map[string][]string, []string, erro
errorFile := "errors.go"
filePaths, err := findFilesWithName(targetPath, errorFile)
if len(filePaths) == 0 || err != nil {
return nil, nil, errors.New("Not find target files in x folder")
return nil, nil, errors.New("not find target files in x folder")
}

// get each module name and bind it to paths (one module may have multiple errors.go)
moduleWithPaths := make(map[string][]string)
for _, filePath := range filePaths {
moduleName := findModuleName(filePath)
if moduleName == "" {
return nil, nil, errors.New("Failed to get module name for " + filePath)
return nil, nil, errors.New("failed to get module name for " + filePath)
}
moduleWithPaths[moduleName] = append(moduleWithPaths[moduleName], filePath)
}

// sort keys and filepaths
var modules []string
n := len(moduleWithPaths)
modules := make([]string, 0, n)

for moduleName := range moduleWithPaths {
modules = append(modules, moduleName)
sort.Strings(moduleWithPaths[moduleName])
Expand Down

0 comments on commit a640923

Please sign in to comment.