mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 20:55:28 +00:00
lint error fixes (#5531)
* lint error fixes * chore: satisfy non-constant format str in call lint (govet) Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io> Co-authored-by: Dwi Siswanto <git@dw1.io>
This commit is contained in:
parent
0675aa48a3
commit
1c76398aea
@ -162,7 +162,7 @@ func process(opts options) error {
|
|||||||
var updated bool // if max-requests is updated
|
var updated bool // if max-requests is updated
|
||||||
dataString, updated, err = parseAndAddMaxRequests(templateCatalog, path, dataString)
|
dataString, updated, err = parseAndAddMaxRequests(templateCatalog, path, dataString)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
if updated {
|
if updated {
|
||||||
gologger.Info().Label("max-request").Msgf("✅ updated template: %s\n", path)
|
gologger.Info().Label("max-request").Msgf("✅ updated template: %s\n", path)
|
||||||
@ -255,7 +255,7 @@ func enhanceTemplate(data string) (string, bool, error) {
|
|||||||
return data, false, errorutil.New("validation failed").WithTag("validate")
|
return data, false, errorutil.New("validation failed").WithTag("validate")
|
||||||
}
|
}
|
||||||
if templateResp.Error.Name != "" {
|
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 strings.TrimSpace(templateResp.Enhanced) == "" && !templateResp.Lint {
|
||||||
if templateResp.LintError.Reason != "" {
|
if templateResp.LintError.Reason != "" {
|
||||||
@ -289,7 +289,7 @@ func formatTemplate(data string) (string, bool, error) {
|
|||||||
return data, false, errorutil.New("validation failed").WithTag("validate")
|
return data, false, errorutil.New("validation failed").WithTag("validate")
|
||||||
}
|
}
|
||||||
if templateResp.Error.Name != "" {
|
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 strings.TrimSpace(templateResp.Updated) == "" && !templateResp.Lint {
|
||||||
if templateResp.LintError.Reason != "" {
|
if templateResp.LintError.Reason != "" {
|
||||||
@ -345,7 +345,7 @@ func validateTemplate(data string) (bool, error) {
|
|||||||
return false, errorutil.New("validation failed").WithTag("validate")
|
return false, errorutil.New("validation failed").WithTag("validate")
|
||||||
}
|
}
|
||||||
if validateResp.Error.Name != "" {
|
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")
|
return false, errorutil.New("template validation failed")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,5 +82,5 @@ func TestMain(m *testing.M) {
|
|||||||
// no need to run this test on github actions
|
// no need to run this test on github actions
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.Run()
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ func getSchemaExample(schema *openapi3.Schema) (interface{}, bool) {
|
|||||||
return schema.Default, true
|
return schema.Default, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if schema.Enum != nil && len(schema.Enum) > 0 {
|
if len(schema.Enum) > 0 {
|
||||||
return schema.Enum[0], true
|
return schema.Enum[0], true
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
|
|||||||
@ -203,7 +203,7 @@ func generateRequestsFromOp(opts *generateReqOptions) error {
|
|||||||
paramValue = value.Schema.Value.Default
|
paramValue = value.Schema.Value.Default
|
||||||
} else if value.Schema.Value.Example != nil {
|
} else if value.Schema.Value.Example != nil {
|
||||||
paramValue = value.Schema.Value.Example
|
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]
|
paramValue = value.Schema.Value.Enum[0]
|
||||||
} else {
|
} else {
|
||||||
if !opts.opts.SkipFormatValidation {
|
if !opts.opts.SkipFormatValidation {
|
||||||
|
|||||||
@ -249,7 +249,7 @@ func identifyGenDecl(pkg *ast.Package, decl *ast.GenDecl, data *TemplateData) {
|
|||||||
if !spec.Names[0].IsExported() {
|
if !spec.Names[0].IsExported() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if spec.Values == nil || len(spec.Values) == 0 {
|
if len(spec.Values) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data.PackageVars[spec.Names[0].Name] = spec.Names[0].Name
|
data.PackageVars[spec.Names[0].Name] = spec.Names[0].Name
|
||||||
|
|||||||
@ -489,7 +489,7 @@ func (p *EntityParser) extractVarsNConstants() {
|
|||||||
if !spec.Names[0].IsExported() {
|
if !spec.Names[0].IsExported() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if spec.Values == nil || len(spec.Values) == 0 {
|
if len(spec.Values) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// get comments or description
|
// get comments or description
|
||||||
|
|||||||
@ -60,12 +60,16 @@ func (j *NucleiJS) HandleError(err error, msg ...string) {
|
|||||||
if len(msg) == 0 {
|
if len(msg) == 0 {
|
||||||
j.ThrowError(err)
|
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
|
// Throw throws an error in goja runtime
|
||||||
func (j *NucleiJS) Throw(format string, args ...interface{}) {
|
func (j *NucleiJS) Throw(format string, args ...interface{}) {
|
||||||
|
if len(args) > 0 {
|
||||||
panic(j.runtime().ToValue(fmt.Sprintf(format, args...)))
|
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
|
// GetArg returns argument at index from goja runtime if not found throws error
|
||||||
@ -95,7 +99,7 @@ func (j *NucleiJS) GetArgSafe(args []goja.Value, index int, defaultValue any) an
|
|||||||
// Require throws an error if expression is false
|
// Require throws an error if expression is false
|
||||||
func (j *NucleiJS) Require(expr bool, msg string) {
|
func (j *NucleiJS) Require(expr bool, msg string) {
|
||||||
if !expr {
|
if !expr {
|
||||||
j.Throw(msg)
|
j.Throw("%s", msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -525,12 +525,12 @@ func tryParseCause(err error) error {
|
|||||||
if strings.HasPrefix(msg, "ReadStatusLine:") {
|
if strings.HasPrefix(msg, "ReadStatusLine:") {
|
||||||
// last index is actual error (from rawhttp)
|
// last index is actual error (from rawhttp)
|
||||||
parts := strings.Split(msg, ":")
|
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 ") {
|
if strings.Contains(msg, "read ") {
|
||||||
// same here
|
// same here
|
||||||
parts := strings.Split(msg, ":")
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ func hash(v interface{}) (string, error) {
|
|||||||
|
|
||||||
sh := sha256.New()
|
sh := sha256.New()
|
||||||
|
|
||||||
if _, err = io.WriteString(sh, string(data)); err != nil {
|
if _, err = sh.Write(data); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return hex.EncodeToString(sh.Sum(nil)), nil
|
return hex.EncodeToString(sh.Sum(nil)), nil
|
||||||
|
|||||||
@ -44,7 +44,8 @@ func toHighLightedHexDump(hexDump, snippetToHighlight string) (HighlightableHexD
|
|||||||
hexDumpRowValues := hexDumpParsePattern.FindAllStringSubmatch(hexDump, -1)
|
hexDumpRowValues := hexDumpParsePattern.FindAllStringSubmatch(hexDump, -1)
|
||||||
if hexDumpRowValues == nil || len(hexDumpRowValues) != strings.Count(hexDump, "\n") {
|
if hexDumpRowValues == nil || len(hexDumpRowValues) != strings.Count(hexDump, "\n") {
|
||||||
message := "could not parse hexdump"
|
message := "could not parse hexdump"
|
||||||
gologger.Warning().Msgf(message)
|
gologger.Warning().Msg(message)
|
||||||
|
|
||||||
return HighlightableHexDump{}, errors.New(message)
|
return HighlightableHexDump{}, errors.New(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
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)
|
msg := fmt.Sprintf("[%s] Dumped DNS request for %s", request.options.TemplateID, question)
|
||||||
if request.options.Options.Debug || request.options.Options.DebugRequests {
|
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)
|
gologger.Print().Msgf("%s", requestString)
|
||||||
}
|
}
|
||||||
if request.options.Options.StoreResponse {
|
if request.options.Options.StoreResponse {
|
||||||
|
|||||||
@ -174,7 +174,7 @@ func (request *Request) executeRequestWithPayloads(input *contextargs.Context, p
|
|||||||
reqBuilder.WriteString("\t" + actStepStr + "\n")
|
reqBuilder.WriteString("\t" + actStepStr + "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gologger.Debug().Msgf(reqBuilder.String())
|
gologger.Debug().Msg(reqBuilder.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseBody string
|
var responseBody string
|
||||||
|
|||||||
@ -240,7 +240,7 @@ func (c *ReportingClient) Close() {
|
|||||||
if failed > 0 {
|
if failed > 0 {
|
||||||
msgBuilder.WriteString(fmt.Sprintf(", %d failed", failed))
|
msgBuilder.WriteString(fmt.Sprintf(", %d failed", failed))
|
||||||
}
|
}
|
||||||
gologger.Info().Msgf(msgBuilder.String())
|
gologger.Info().Msgf("%v", msgBuilder.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,8 +68,10 @@ func (e *TemplateExecuter) Compile() error {
|
|||||||
if cliOptions.Verbose {
|
if cliOptions.Verbose {
|
||||||
rawErrorMessage := dslCompilationError.Error()
|
rawErrorMessage := dslCompilationError.Error()
|
||||||
formattedErrorMessage := strings.ToUpper(rawErrorMessage[:1]) + rawErrorMessage[1:] + "."
|
formattedErrorMessage := strings.ToUpper(rawErrorMessage[:1]) + rawErrorMessage[1:] + "."
|
||||||
gologger.Warning().Msgf(formattedErrorMessage)
|
|
||||||
|
gologger.Warning().Msg(formattedErrorMessage)
|
||||||
gologger.Info().Msgf("The available custom DSL functions are:")
|
gologger.Info().Msgf("The available custom DSL functions are:")
|
||||||
|
|
||||||
fmt.Println(dsl.GetPrintableDslFunctionSignatures(cliOptions.NoColor))
|
fmt.Println(dsl.GetPrintableDslFunctionSignatures(cliOptions.NoColor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user