Skip to content

Commit

Permalink
fix: add an human understanable report message
Browse files Browse the repository at this point in the history
Signed-off-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
ldez committed Dec 10, 2024
1 parent e4f0673 commit fc882e4
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package analyzer

import (
"fmt"
"go/token"
"strings"

Expand Down Expand Up @@ -89,8 +88,7 @@ func runAnalysis(pass *analysis.Pass) (interface{}, error) {
}

for _, file := range fileReferences {
filePath := file.Name()
unmodifiedFile, formattedFile, err := gci.LoadFormatGoFile(io.File{FilePath: filePath}, *gciCfg)
unmodifiedFile, formattedFile, err := gci.LoadFormatGoFile(io.File{FilePath: file.Name()}, *gciCfg)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +105,7 @@ func runAnalysis(pass *analysis.Pass) (interface{}, error) {

pass.Report(analysis.Diagnostic{
Pos: fix.TextEdits[0].Pos,
Message: fmt.Sprintf("fix by `%s %s`", generateCmdLine(*gciCfg), filePath),
Message: "Invalid import order",
SuggestedFixes: []analysis.SuggestedFix{*fix},
})
}
Expand Down Expand Up @@ -140,35 +138,3 @@ func generateGciConfiguration(modPath string) *config.YamlConfig {

return &config.YamlConfig{Cfg: fmtCfg, SectionStrings: sectionStrings, SectionSeparatorStrings: sectionSeparatorStrings, ModPath: modPath}
}

func generateCmdLine(cfg config.Config) string {
result := "gci write"

if cfg.BoolConfig.NoInlineComments {
result += " --NoInlineComments "
}

if cfg.BoolConfig.NoPrefixComments {
result += " --NoPrefixComments "
}

if cfg.BoolConfig.SkipGenerated {
result += " --skip-generated "
}

if cfg.BoolConfig.CustomOrder {
result += " --custom-order "
}

if cfg.BoolConfig.NoLexOrder {
result += " --no-lex-order"
}

for _, s := range cfg.Sections.String() {
result += fmt.Sprintf(" --Section \"%s\" ", s)
}
for _, s := range cfg.SectionSeparators.String() {
result += fmt.Sprintf(" --SectionSeparator %s ", s)
}
return result
}

0 comments on commit fc882e4

Please sign in to comment.