Skip to content

Commit

Permalink
lint error fixes (projectdiscovery#5531)
Browse files Browse the repository at this point in the history
* lint error fixes

* chore: satisfy non-constant format str in call lint (govet)

Signed-off-by: Dwi Siswanto <[email protected]>

---------

Signed-off-by: Dwi Siswanto <[email protected]>
Co-authored-by: Dwi Siswanto <[email protected]>
  • Loading branch information
tarunKoyalwar and dwisiswant0 authored Aug 16, 2024
1 parent 0675aa4 commit 1c76398
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 21 deletions.
8 changes: 4 additions & 4 deletions cmd/tmc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func process(opts options) error {
var updated bool // if max-requests is updated
dataString, updated, err = parseAndAddMaxRequests(templateCatalog, path, dataString)
if err != nil {
gologger.Info().Label("max-request").Msgf(logErrMsg(path, err, opts.debug, errFile))
gologger.Info().Label("max-request").Msg(logErrMsg(path, err, opts.debug, errFile))
} else {
if updated {
gologger.Info().Label("max-request").Msgf("✅ updated template: %s\n", path)
Expand Down Expand Up @@ -255,7 +255,7 @@ func enhanceTemplate(data string) (string, bool, error) {
return data, false, errorutil.New("validation failed").WithTag("validate")
}
if templateResp.Error.Name != "" {
return data, false, errorutil.New(templateResp.Error.Name)
return data, false, errorutil.New("%s", templateResp.Error.Name)
}
if strings.TrimSpace(templateResp.Enhanced) == "" && !templateResp.Lint {
if templateResp.LintError.Reason != "" {
Expand Down Expand Up @@ -289,7 +289,7 @@ func formatTemplate(data string) (string, bool, error) {
return data, false, errorutil.New("validation failed").WithTag("validate")
}
if templateResp.Error.Name != "" {
return data, false, errorutil.New(templateResp.Error.Name)
return data, false, errorutil.New("%s", templateResp.Error.Name)
}
if strings.TrimSpace(templateResp.Updated) == "" && !templateResp.Lint {
if templateResp.LintError.Reason != "" {
Expand Down Expand Up @@ -345,7 +345,7 @@ func validateTemplate(data string) (bool, error) {
return false, errorutil.New("validation failed").WithTag("validate")
}
if validateResp.Error.Name != "" {
return false, errorutil.New(validateResp.Error.Name)
return false, errorutil.New("%s", validateResp.Error.Name)
}
return false, errorutil.New("template validation failed")
}
Expand Down
2 changes: 1 addition & 1 deletion lib/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ func TestMain(m *testing.M) {
// no need to run this test on github actions
return
}
m.Run()
os.Exit(m.Run())
}
2 changes: 1 addition & 1 deletion pkg/input/formats/openapi/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func getSchemaExample(schema *openapi3.Schema) (interface{}, bool) {
return schema.Default, true
}

if schema.Enum != nil && len(schema.Enum) > 0 {
if len(schema.Enum) > 0 {
return schema.Enum[0], true
}
return nil, false
Expand Down
4 changes: 2 additions & 2 deletions pkg/input/formats/openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func GenerateRequestsFromSchema(schema *openapi3.T, opts formats.InputFormatOpti
}
missingVarMap[param.Name] = struct{}{}
}

for _, serverURL := range schema.Servers {
pathURL := serverURL.URL
// Split the server URL into baseURL and serverPath
Expand Down Expand Up @@ -203,7 +203,7 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
paramValue = value.Schema.Value.Default
} else if value.Schema.Value.Example != nil {
paramValue = value.Schema.Value.Example
} else if value.Schema.Value.Enum != nil && len(value.Schema.Value.Enum) > 0 {
} else if len(value.Schema.Value.Enum) > 0 {
paramValue = value.Schema.Value.Enum[0]
} else {
if !opts.opts.SkipFormatValidation {
Expand Down
2 changes: 1 addition & 1 deletion pkg/js/devtools/bindgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func identifyGenDecl(pkg *ast.Package, decl *ast.GenDecl, data *TemplateData) {
if !spec.Names[0].IsExported() {
continue
}
if spec.Values == nil || len(spec.Values) == 0 {
if len(spec.Values) == 0 {
continue
}
data.PackageVars[spec.Names[0].Name] = spec.Names[0].Name
Expand Down
2 changes: 1 addition & 1 deletion pkg/js/devtools/tsgen/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func (p *EntityParser) extractVarsNConstants() {
if !spec.Names[0].IsExported() {
continue
}
if spec.Values == nil || len(spec.Values) == 0 {
if len(spec.Values) == 0 {
continue
}
// get comments or description
Expand Down
10 changes: 7 additions & 3 deletions pkg/js/utils/nucleijs.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ func (j *NucleiJS) HandleError(err error, msg ...string) {
if len(msg) == 0 {
j.ThrowError(err)
}
j.Throw(fmt.Sprintf("%s: %s", strings.Join(msg, ":"), err.Error()))
j.Throw("%s: %s", strings.Join(msg, ":"), err.Error())
}

// Throw throws an error in goja runtime
func (j *NucleiJS) Throw(format string, args ...interface{}) {
panic(j.runtime().ToValue(fmt.Sprintf(format, args...)))
if len(args) > 0 {
panic(j.runtime().ToValue(fmt.Sprintf(format, args...)))
}

panic(j.runtime().ToValue(format))
}

// GetArg returns argument at index from goja runtime if not found throws error
Expand Down Expand Up @@ -95,7 +99,7 @@ func (j *NucleiJS) GetArgSafe(args []goja.Value, index int, defaultValue any) an
// Require throws an error if expression is false
func (j *NucleiJS) Require(expr bool, msg string) {
if !expr {
j.Throw(msg)
j.Throw("%s", msg)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,12 @@ func tryParseCause(err error) error {
if strings.HasPrefix(msg, "ReadStatusLine:") {
// last index is actual error (from rawhttp)
parts := strings.Split(msg, ":")
return errkit.New(strings.TrimSpace(parts[len(parts)-1]))
return errkit.New("%s", strings.TrimSpace(parts[len(parts)-1]))
}
if strings.Contains(msg, "read ") {
// same here
parts := strings.Split(msg, ":")
return errkit.New(strings.TrimSpace(parts[len(parts)-1]))
return errkit.New("%s", strings.TrimSpace(parts[len(parts)-1]))
}
return err
}
2 changes: 1 addition & 1 deletion pkg/projectfile/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func hash(v interface{}) (string, error) {

sh := sha256.New()

if _, err = io.WriteString(sh, string(data)); err != nil {
if _, err = sh.Write(data); err != nil {
return "", err
}
return hex.EncodeToString(sh.Sum(nil)), nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/protocols/common/helpers/responsehighlighter/hexdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func toHighLightedHexDump(hexDump, snippetToHighlight string) (HighlightableHexD
hexDumpRowValues := hexDumpParsePattern.FindAllStringSubmatch(hexDump, -1)
if hexDumpRowValues == nil || len(hexDumpRowValues) != strings.Count(hexDump, "\n") {
message := "could not parse hexdump"
gologger.Warning().Msgf(message)
gologger.Warning().Msg(message)

return HighlightableHexDump{}, errors.New(message)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/protocols/dns/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (request *Request) execute(input *contextargs.Context, domain string, metad
if request.options.Options.Debug || request.options.Options.DebugRequests || request.options.Options.StoreResponse {
msg := fmt.Sprintf("[%s] Dumped DNS request for %s", request.options.TemplateID, question)
if request.options.Options.Debug || request.options.Options.DebugRequests {
gologger.Info().Str("domain", domain).Msgf(msg)
gologger.Info().Str("domain", domain).Msg(msg)
gologger.Print().Msgf("%s", requestString)
}
if request.options.Options.StoreResponse {
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocols/headless/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (request *Request) executeRequestWithPayloads(input *contextargs.Context, p
reqBuilder.WriteString("\t" + actStepStr + "\n")
}
}
gologger.Debug().Msgf(reqBuilder.String())
gologger.Debug().Msg(reqBuilder.String())
}

var responseBody string
Expand Down
2 changes: 1 addition & 1 deletion pkg/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (c *ReportingClient) Close() {
if failed > 0 {
msgBuilder.WriteString(fmt.Sprintf(", %d failed", failed))
}
gologger.Info().Msgf(msgBuilder.String())
gologger.Info().Msgf("%v", msgBuilder.String())
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/tmplexec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func (e *TemplateExecuter) Compile() error {
if cliOptions.Verbose {
rawErrorMessage := dslCompilationError.Error()
formattedErrorMessage := strings.ToUpper(rawErrorMessage[:1]) + rawErrorMessage[1:] + "."
gologger.Warning().Msgf(formattedErrorMessage)

gologger.Warning().Msg(formattedErrorMessage)
gologger.Info().Msgf("The available custom DSL functions are:")

fmt.Println(dsl.GetPrintableDslFunctionSignatures(cliOptions.NoColor))
}
}
Expand Down

0 comments on commit 1c76398

Please sign in to comment.