Repository: go-critic/go-critic
Pull request #1318 (2023-02-21 08:01:28)

cmd,framework: remove lintmain


Patch:
diff --git a/framework/lintmain/internal/check/check.go b/cmd/gocritic/check.go
similarity index 99%
rename from framework/lintmain/internal/check/check.go
rename to cmd/gocritic/check.go
index b4a43b8..a45e84a 100644
--- a/framework/lintmain/internal/check/check.go
+++ b/cmd/gocritic/check.go
@@ -1,4 +1,4 @@
-package check
+package main
 
 import (
 	"bytes"
@@ -26,7 +26,7 @@ import (
 )
 
 // Main implements sub-command entry point.
-func Main(_ context.Context, args []string) error {
+func runCheck(_ context.Context, args []string) error {
 	var p program
 	p.flagSet = flag.NewFlagSet("gocritic", flag.ContinueOnError)
 	p.infoList = linter.GetCheckersInfo()
diff --git a/framework/lintmain/internal/lintdoc/doc.go b/cmd/gocritic/doc.go
similarity index 96%
rename from framework/lintmain/internal/lintdoc/doc.go
rename to cmd/gocritic/doc.go
index 4609114..4f4ccfd 100644
--- a/framework/lintmain/internal/lintdoc/doc.go
+++ b/cmd/gocritic/doc.go
@@ -1,4 +1,4 @@
-package lintdoc
+package main
 
 import (
 	"context"
@@ -13,7 +13,7 @@ import (
 )
 
 // Main implements sub-command entry point.
-func Main(_ context.Context, args []string) error {
+func runDocs(_ context.Context, args []string) error {
 	flagSet := flag.NewFlagSet("gocritic", flag.ContinueOnError)
 	if err := flagSet.Parse(args); err != nil {
 		return err
diff --git a/cmd/gocritic/main.go b/cmd/gocritic/main.go
index 47e8644..f8a87b7 100644
--- a/cmd/gocritic/main.go
+++ b/cmd/gocritic/main.go
@@ -1,8 +1,11 @@
 package main
 
 import (
-	"github.com/go-critic/go-critic/checkers" // Register go-critic checkers
-	"github.com/go-critic/go-critic/framework/lintmain"
+	"log"
+
+	"github.com/go-critic/go-critic/checkers"
+
+	"github.com/cristalhq/acmd"
 )
 
 var Version = "v0.0.0-SNAPSHOT"
@@ -13,8 +16,41 @@ func main() {
 		panic(err)
 	}
 
-	lintmain.Run(lintmain.Config{
+	run(config{
 		Name:    "gocritic",
 		Version: Version,
 	})
 }
+
+// config is used to parametrize the linter.
+type config struct {
+	Version string
+	Name    string
+}
+
+// Run executes corresponding main after sub-command resolving.
+// Does not return.
+func run(cfg config) {
+	log.SetFlags(0)
+
+	cmds := []acmd.Command{
+		{
+			Name:        "check",
+			Description: "run linter over specified targets",
+			ExecFunc:    runCheck,
+		},
+		{
+			Name:        "doc",
+			Description: "get installed checkers documentation",
+			ExecFunc:    runDocs,
+		},
+	}
+
+	r := acmd.RunnerOf(cmds, acmd.Config{
+		AppName: cfg.Name,
+		Version: cfg.Version,
+	})
+	if err := r.Run(); err != nil {
+		log.Print(err.Error())
+	}
+}
diff --git a/framework/lintmain/lintmain.go b/framework/lintmain/lintmain.go
deleted file mode 100644
index 519a565..0000000
--- a/framework/lintmain/lintmain.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package lintmain
-
-import (
-	"log"
-
-	"github.com/go-critic/go-critic/framework/lintmain/internal/check"
-	"github.com/go-critic/go-critic/framework/lintmain/internal/lintdoc"
-
-	"github.com/cristalhq/acmd"
-)
-
-// Config is used to parametrize the linter.
-type Config struct {
-	Version string
-	Name    string
-}
-
-// Run executes corresponding main after sub-command resolving.
-// Does not return.
-func Run(cfg Config) {
-	log.SetFlags(0)
-
-	r := acmd.RunnerOf(cmds, acmd.Config{
-		AppName: cfg.Name,
-		Version: cfg.Version,
-	})
-	if err := r.Run(); err != nil {
-		log.Print(err.Error())
-	}
-}
-
-var cmds = []acmd.Command{
-	{
-		Name:        "check",
-		Description: "run linter over specified targets",
-		ExecFunc:    check.Main,
-	},
-	{
-		Name:        "doc",
-		Description: "get installed checkers documentation",
-		ExecFunc:    lintdoc.Main,
-	},
-}


Test patch:
diff --git a/framework/lintmain/internal/check/check_test.go b/cmd/gocritic/check_test.go
similarity index 98%
rename from framework/lintmain/internal/check/check_test.go
rename to cmd/gocritic/check_test.go
index e6707b8..d1e4428 100644
--- a/framework/lintmain/internal/check/check_test.go
+++ b/cmd/gocritic/check_test.go
@@ -1,4 +1,4 @@
-package check
+package main
 
 import (
 	"testing"