Closed
Description
Hello!
I spent a couple of days, but I did not find an elegant way to implement this:
package main
import (
"flag"
"log"
"os"
"golang.org/x/tools/go/analysis/singlechecker"
"github.com/Antonboom/myanalyzer/pkg/analyzer"
"github.com/Antonboom/myanalyzer/pkg/config"
)
var (
configPath = flag.String("config", "", "path to config file (yml)")
dumpCfg = flag.Bool("dump-config", false, "dump config example (yml) in stdout")
)
func main() {
flag.Parse()
if *dumpCfg {
mustNil(config.Dump(config.Default, os.Stdout))
return
}
cfg := config.Default
if *configPath != "" {
var err error
cfg, err = config.ParseFromFile(*configPath)
mustNil(err)
mustNil(config.Validate(cfg))
}
singlechecker.Main(analyzer.New(cfg)) // <-- Own flags logic inside via internal packages.
}
Inputs:
- It is assumed that the analyzer is used both as a module and as a binary.
- I want the linter to be configured using a config file (or via config struct if used as module).
- I don't want to lose the set of flags and functionality from the
golang.org/x/tools/go/analysis/singlechecker
.
I found a workaround using analysis.Analyzer.Flags
and flag.Value
implementation interface for config.Config
, but this leads to singletons, package-level hacks, etc.
Now I see that a lot of linters that are configured through the configuration file refuse to use the golang.org/x/tools/go/analysis/singlechecker(multichecker)
.
Metadata
Metadata
Assignees
Type
Projects
Status
Incoming