Browse Source

Merge branch 'mjtrangoni-fix-deadcode-issues'

* mjtrangoni-fix-deadcode-issues:
  tech: removes unused code
  add deadcode linter to circleci
  pkg: fix deadcode issues
  build.go: fix deadcode issues
bergquist 7 years ago
parent
commit
afce0feb05

+ 2 - 1
.circleci/config.yml

@@ -27,13 +27,14 @@ jobs:
     steps:
     steps:
       - checkout
       - checkout
       - run: 'go get -u gopkg.in/alecthomas/gometalinter.v2'
       - run: 'go get -u gopkg.in/alecthomas/gometalinter.v2'
+      - run: 'go get -u github.com/tsenart/deadcode'
       - run: 'go get -u github.com/gordonklaus/ineffassign'
       - run: 'go get -u github.com/gordonklaus/ineffassign'
       - run: 'go get -u github.com/opennota/check/cmd/structcheck'
       - run: 'go get -u github.com/opennota/check/cmd/structcheck'
       - run: 'go get -u github.com/mdempsky/unconvert'
       - run: 'go get -u github.com/mdempsky/unconvert'
       - run: 'go get -u github.com/opennota/check/cmd/varcheck'
       - run: 'go get -u github.com/opennota/check/cmd/varcheck'
       - run:
       - run:
           name: run linters
           name: run linters
-          command: 'gometalinter.v2 --enable-gc --vendor --deadline 10m --disable-all --enable=ineffassign --enable=structcheck --enable=unconvert --enable=varcheck ./...'
+          command: 'gometalinter.v2 --enable-gc --vendor --deadline 10m --disable-all --enable=deadcode --enable=ineffassign --enable=structcheck --enable=unconvert --enable=varcheck ./...'
 
 
   test-frontend:
   test-frontend:
     docker:
     docker:

+ 8 - 47
build.go

@@ -16,7 +16,6 @@ import (
 	"os/exec"
 	"os/exec"
 	"path"
 	"path"
 	"path/filepath"
 	"path/filepath"
-	"regexp"
 	"runtime"
 	"runtime"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -24,14 +23,14 @@ import (
 )
 )
 
 
 var (
 var (
-	versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
-	goarch    string
-	goos      string
-	gocc      string
-	gocxx     string
-	cgo       string
-	pkgArch   string
-	version   string = "v1"
+	//versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
+	goarch  string
+	goos    string
+	gocc    string
+	gocxx   string
+	cgo     string
+	pkgArch string
+	version string = "v1"
 	// deb & rpm does not support semver so have to handle their version a little differently
 	// deb & rpm does not support semver so have to handle their version a little differently
 	linuxPackageVersion   string = "v1"
 	linuxPackageVersion   string = "v1"
 	linuxPackageIteration string = ""
 	linuxPackageIteration string = ""
@@ -44,8 +43,6 @@ var (
 	isDev                 bool     = false
 	isDev                 bool     = false
 )
 )
 
 
-const minGoVersion = 1.8
-
 func main() {
 func main() {
 	log.SetOutput(os.Stdout)
 	log.SetOutput(os.Stdout)
 	log.SetFlags(0)
 	log.SetFlags(0)
@@ -326,20 +323,6 @@ func createPackage(options linuxPackageOptions) {
 	runPrint("fpm", append([]string{"-t", options.packageType}, args...)...)
 	runPrint("fpm", append([]string{"-t", options.packageType}, args...)...)
 }
 }
 
 
-func verifyGitRepoIsClean() {
-	rs, err := runError("git", "ls-files", "--modified")
-	if err != nil {
-		log.Fatalf("Failed to check if git tree was clean, %v, %v\n", string(rs), err)
-		return
-	}
-	count := len(string(rs))
-	if count > 0 {
-		log.Fatalf("Git repository has modified files, aborting")
-	}
-
-	log.Println("Git repository is clean")
-}
-
 func ensureGoPath() {
 func ensureGoPath() {
 	if os.Getenv("GOPATH") == "" {
 	if os.Getenv("GOPATH") == "" {
 		cwd, err := os.Getwd()
 		cwd, err := os.Getwd()
@@ -352,10 +335,6 @@ func ensureGoPath() {
 	}
 	}
 }
 }
 
 
-func ChangeWorkingDir(dir string) {
-	os.Chdir(dir)
-}
-
 func grunt(params ...string) {
 func grunt(params ...string) {
 	if runtime.GOOS == "windows" {
 	if runtime.GOOS == "windows" {
 		runPrint(`.\node_modules\.bin\grunt`, params...)
 		runPrint(`.\node_modules\.bin\grunt`, params...)
@@ -492,24 +471,6 @@ func buildStamp() int64 {
 	return s
 	return s
 }
 }
 
 
-func buildArch() string {
-	os := goos
-	if os == "darwin" {
-		os = "macosx"
-	}
-	return fmt.Sprintf("%s-%s", os, goarch)
-}
-
-func run(cmd string, args ...string) []byte {
-	bs, err := runError(cmd, args...)
-	if err != nil {
-		log.Println(cmd, strings.Join(args, " "))
-		log.Println(string(bs))
-		log.Fatal(err)
-	}
-	return bytes.TrimSpace(bs)
-}
-
 func runError(cmd string, args ...string) ([]byte, error) {
 func runError(cmd string, args ...string) ([]byte, error) {
 	ecmd := exec.Command(cmd, args...)
 	ecmd := exec.Command(cmd, args...)
 	bs, err := ecmd.CombinedOutput()
 	bs, err := ecmd.CombinedOutput()

+ 0 - 16
pkg/api/annotations.go

@@ -294,19 +294,3 @@ func canSave(c *m.ReqContext, repo annotations.Repository, annotationID int64) R
 
 
 	return nil
 	return nil
 }
 }
-
-func canSaveByRegionID(c *m.ReqContext, repo annotations.Repository, regionID int64) Response {
-	items, err := repo.Find(&annotations.ItemQuery{RegionId: regionID, OrgId: c.OrgId})
-
-	if err != nil || len(items) == 0 {
-		return Error(500, "Could not find annotation to update", err)
-	}
-
-	dashboardID := items[0].DashboardId
-
-	if canSave, err := canSaveByDashboardID(c, dashboardID); err != nil || !canSave {
-		return dashboardGuardianResponse(err)
-	}
-
-	return nil
-}

+ 0 - 2
pkg/middleware/render_auth.go

@@ -31,8 +31,6 @@ func initContextWithRenderAuth(ctx *m.ReqContext) bool {
 	return true
 	return true
 }
 }
 
 
-type renderContextFunc func(key string) (string, error)
-
 func AddRenderAuthKey(orgId int64, userId int64, orgRole m.RoleType) string {
 func AddRenderAuthKey(orgId int64, userId int64, orgRole m.RoleType) string {
 	renderKeysLock.Lock()
 	renderKeysLock.Lock()
 
 

+ 32 - 31
pkg/services/sqlstore/migrations/stats_mig.go

@@ -2,37 +2,38 @@ package migrations
 
 
 import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
 import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
 
 
-func addStatsMigrations(mg *Migrator) {
-	statTable := Table{
-		Name: "stat",
-		Columns: []*Column{
-			{Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
-			{Name: "metric", Type: DB_Varchar, Length: 20, Nullable: false},
-			{Name: "type", Type: DB_Int, Nullable: false},
-		},
-		Indices: []*Index{
-			{Cols: []string{"metric"}, Type: UniqueIndex},
-		},
-	}
-
-	// create table
-	mg.AddMigration("create stat table", NewAddTableMigration(statTable))
-
-	// create indices
-	mg.AddMigration("add index stat.metric", NewAddIndexMigration(statTable, statTable.Indices[0]))
-
-	statValue := Table{
-		Name: "stat_value",
-		Columns: []*Column{
-			{Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
-			{Name: "value", Type: DB_Double, Nullable: false},
-			{Name: "time", Type: DB_DateTime, Nullable: false},
-		},
-	}
-
-	// create table
-	mg.AddMigration("create stat_value table", NewAddTableMigration(statValue))
-}
+// commented out because of the deadcode CI check
+//func addStatsMigrations(mg *Migrator) {
+//	statTable := Table{
+//		Name: "stat",
+//		Columns: []*Column{
+//			{Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
+//			{Name: "metric", Type: DB_Varchar, Length: 20, Nullable: false},
+//			{Name: "type", Type: DB_Int, Nullable: false},
+//		},
+//		Indices: []*Index{
+//			{Cols: []string{"metric"}, Type: UniqueIndex},
+//		},
+//	}
+//
+//	// create table
+//	mg.AddMigration("create stat table", NewAddTableMigration(statTable))
+//
+//	// create indices
+//	mg.AddMigration("add index stat.metric", NewAddIndexMigration(statTable, statTable.Indices[0]))
+//
+//	statValue := Table{
+//		Name: "stat_value",
+//		Columns: []*Column{
+//			{Name: "id", Type: DB_Int, IsPrimaryKey: true, IsAutoIncrement: true},
+//			{Name: "value", Type: DB_Double, Nullable: false},
+//			{Name: "time", Type: DB_DateTime, Nullable: false},
+//		},
+//	}
+//
+//	// create table
+//	mg.AddMigration("create stat_value table", NewAddTableMigration(statValue))
+//}
 
 
 func addTestDataMigrations(mg *Migrator) {
 func addTestDataMigrations(mg *Migrator) {
 	testData := Table{
 	testData := Table{