Chore/fix lint issues (#27704)

* Chore: Fix linting issues

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-09-22 16:22:19 +02:00
committed by GitHub
parent ffc11cb63c
commit a5d9196a53
70 changed files with 274 additions and 276 deletions
+1 -1
View File
@@ -303,7 +303,7 @@ func SetAlertState(cmd *models.SetAlertStateCommand) error {
alert.EvalData = cmd.EvalData
if cmd.Error == "" {
alert.ExecutionError = " " //without this space, xorm skips updating this field
alert.ExecutionError = " " // without this space, xorm skips updating this field
} else {
alert.ExecutionError = cmd.Error
}
+1 -1
View File
@@ -97,7 +97,7 @@ func (ss *SqlStore) GetAlertNotificationUidWithId(query *models.GetAlertNotifica
return err
}
ss.CacheService.Set(cacheKey, query.Result, -1) //Infinite, never changes
ss.CacheService.Set(cacheKey, query.Result, -1) // Infinite, never changes
return nil
}
+1 -3
View File
@@ -23,9 +23,7 @@ func validateTimeRange(item *annotations.Item) error {
item.Epoch = item.EpochEnd
}
if item.EpochEnd < item.Epoch {
tmp := item.Epoch
item.Epoch = item.EpochEnd
item.EpochEnd = tmp
item.Epoch, item.EpochEnd = item.EpochEnd, item.Epoch
}
return nil
}
@@ -102,7 +102,7 @@ func TestOldAnnotationsAreDeletedFirst(t *testing.T) {
})
})
//create some test annotations
// create some test annotations
a := annotations.Item{
DashboardId: 1,
OrgId: 1,
+1 -1
View File
@@ -153,7 +153,7 @@ func TestAnnotations(t *testing.T) {
OrgId: 1,
DashboardId: 1,
From: 1,
To: 15, //this will exclude the second test annotation
To: 15, // this will exclude the second test annotation
Tags: []string{"outage", "error"},
})
+5 -5
View File
@@ -42,7 +42,7 @@ func TestApiKeyDataAccess(t *testing.T) {
})
t.Run("Add an expiring key", func(t *testing.T) {
//expires in one hour
// expires in one hour
cmd := models.AddApiKeyCommand{OrgId: 1, Name: "expiring-in-an-hour", Key: "asd2", SecondsToLive: 3600}
err := AddApiKey(&cmd)
assert.Nil(t, err)
@@ -62,7 +62,7 @@ func TestApiKeyDataAccess(t *testing.T) {
})
t.Run("Add a key with negative lifespan", func(t *testing.T) {
//expires in one day
// expires in one day
cmd := models.AddApiKeyCommand{OrgId: 1, Name: "key-with-negative-lifespan", Key: "asd3", SecondsToLive: -3600}
err := AddApiKey(&cmd)
assert.EqualError(t, err, models.ErrInvalidApiKeyExpiration.Error())
@@ -73,17 +73,17 @@ func TestApiKeyDataAccess(t *testing.T) {
})
t.Run("Add keys", func(t *testing.T) {
//never expires
// never expires
cmd := models.AddApiKeyCommand{OrgId: 1, Name: "key1", Key: "key1", SecondsToLive: 0}
err := AddApiKey(&cmd)
assert.Nil(t, err)
//expires in 1s
// expires in 1s
cmd = models.AddApiKeyCommand{OrgId: 1, Name: "key2", Key: "key2", SecondsToLive: 1}
err = AddApiKey(&cmd)
assert.Nil(t, err)
//expires in one hour
// expires in one hour
cmd = models.AddApiKeyCommand{OrgId: 1, Name: "key3", Key: "key3", SecondsToLive: 3600}
err = AddApiKey(&cmd)
assert.Nil(t, err)
+1 -1
View File
@@ -454,7 +454,7 @@ func GetDashboardPermissionsForUser(query *models.GetDashboardPermissionsForUser
`
params = append(params, query.UserId)
//check the user's role for dashboards that do not have hasAcl set
// check the user's role for dashboards that do not have hasAcl set
sql += `LEFT JOIN org_user ouRole ON ouRole.user_id = ? AND ouRole.org_id = ?`
params = append(params, query.UserId)
params = append(params, query.OrgId)
@@ -65,9 +65,9 @@ func addAnnotationMig(mg *Migrator) {
Name: "tags", Type: DB_NVarchar, Nullable: true, Length: 500,
}))
///
/// Annotation tag
///
//
// Annotation tag
//
annotationTagTable := Table{
Name: "annotation_tag",
Columns: []*Column{
@@ -40,7 +40,9 @@ func TestMigrations(t *testing.T) {
has, err := x.SQL(sql).Get(&r)
So(err, ShouldBeNil)
So(has, ShouldBeTrue)
expectedMigrations := mg.MigrationsCount() //we currently skip to migrations. We should rewrite skipped migrations to write in the log as well. until then we have to keep this
// we currently skip to migrations. We should rewrite skipped migrations to write in the log as well.
// until then we have to keep this
expectedMigrations := mg.MigrationsCount()
So(r.Count, ShouldEqual, expectedMigrations)
mg = NewMigrator(x)
@@ -3,7 +3,7 @@ package migrations
import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
// commented out because of the deadcode CI check
//func addStatsMigrations(mg *Migrator) {
// func addStatsMigrations(mg *Migrator) {
// statTable := Table{
// Name: "stat",
// Columns: []*Column{
@@ -33,7 +33,7 @@ import . "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
//
// // create table
// mg.AddMigration("create stat_value table", NewAddTableMigration(statValue))
//}
// }
func addTestDataMigrations(mg *Migrator) {
testData := Table{
+1 -1
View File
@@ -201,7 +201,7 @@ type CopyTableDataMigration struct {
targetTable string
sourceCols []string
targetCols []string
//colMap map[string]string
// colMap map[string]string
}
func NewCopyTableDataMigration(targetTable string, sourceTable string, colMap map[string]string) *CopyTableDataMigration {
@@ -76,7 +76,7 @@ func (db *Sqlite3) IndexCheckSql(tableName, indexName string) (string, []interfa
func (db *Sqlite3) DropIndexSql(tableName string, index *Index) string {
quote := db.Quote
//var unique string
// var unique string
idxName := index.XName(tableName)
return fmt.Sprintf("DROP INDEX %v", quote(idxName))
}
+11 -11
View File
@@ -35,7 +35,7 @@ func GetOrgQuotaByTarget(query *models.GetOrgQuotaByTargetQuery) error {
quota.Limit = query.Default
}
//get quota used.
// get quota used.
rawSql := fmt.Sprintf("SELECT COUNT(*) as count from %s where org_id=?", dialect.Quote(query.Target))
resp := make([]*targetCount, 0)
if err := x.SQL(rawSql, query.OrgId).Find(&resp); err != nil {
@@ -78,7 +78,7 @@ func GetOrgQuotas(query *models.GetOrgQuotasQuery) error {
result := make([]*models.OrgQuotaDTO, len(quotas))
for i, q := range quotas {
//get quota used.
// get quota used.
rawSql := fmt.Sprintf("SELECT COUNT(*) as count from %s where org_id=?", dialect.Quote(q.Target))
resp := make([]*targetCount, 0)
if err := x.SQL(rawSql, q.OrgId).Find(&resp); err != nil {
@@ -97,7 +97,7 @@ func GetOrgQuotas(query *models.GetOrgQuotasQuery) error {
func UpdateOrgQuota(cmd *models.UpdateOrgQuotaCmd) error {
return inTransaction(func(sess *DBSession) error {
//Check if quota is already defined in the DB
// Check if quota is already defined in the DB
quota := models.Quota{
Target: cmd.Target,
OrgId: cmd.OrgId,
@@ -110,12 +110,12 @@ func UpdateOrgQuota(cmd *models.UpdateOrgQuotaCmd) error {
quota.Limit = cmd.Limit
if !has {
quota.Created = time.Now()
//No quota in the DB for this target, so create a new one.
// No quota in the DB for this target, so create a new one.
if _, err := sess.Insert(&quota); err != nil {
return err
}
} else {
//update existing quota entry in the DB.
// update existing quota entry in the DB.
_, err := sess.ID(quota.Id).Update(&quota)
if err != nil {
return err
@@ -138,7 +138,7 @@ func GetUserQuotaByTarget(query *models.GetUserQuotaByTargetQuery) error {
quota.Limit = query.Default
}
//get quota used.
// get quota used.
rawSql := fmt.Sprintf("SELECT COUNT(*) as count from %s where user_id=?", dialect.Quote(query.Target))
resp := make([]*targetCount, 0)
if err := x.SQL(rawSql, query.UserId).Find(&resp); err != nil {
@@ -181,7 +181,7 @@ func GetUserQuotas(query *models.GetUserQuotasQuery) error {
result := make([]*models.UserQuotaDTO, len(quotas))
for i, q := range quotas {
//get quota used.
// get quota used.
rawSql := fmt.Sprintf("SELECT COUNT(*) as count from %s where user_id=?", dialect.Quote(q.Target))
resp := make([]*targetCount, 0)
if err := x.SQL(rawSql, q.UserId).Find(&resp); err != nil {
@@ -200,7 +200,7 @@ func GetUserQuotas(query *models.GetUserQuotasQuery) error {
func UpdateUserQuota(cmd *models.UpdateUserQuotaCmd) error {
return inTransaction(func(sess *DBSession) error {
//Check if quota is already defined in the DB
// Check if quota is already defined in the DB
quota := models.Quota{
Target: cmd.Target,
UserId: cmd.UserId,
@@ -213,12 +213,12 @@ func UpdateUserQuota(cmd *models.UpdateUserQuotaCmd) error {
quota.Limit = cmd.Limit
if !has {
quota.Created = time.Now()
//No quota in the DB for this target, so create a new one.
// No quota in the DB for this target, so create a new one.
if _, err := sess.Insert(&quota); err != nil {
return err
}
} else {
//update existing quota entry in the DB.
// update existing quota entry in the DB.
_, err := sess.ID(quota.Id).Update(&quota)
if err != nil {
return err
@@ -230,7 +230,7 @@ func UpdateUserQuota(cmd *models.UpdateUserQuotaCmd) error {
}
func GetGlobalQuotaByTarget(query *models.GetGlobalQuotaByTargetQuery) error {
//get quota used.
// get quota used.
rawSql := fmt.Sprintf("SELECT COUNT(*) as count from %s", dialect.Quote(query.Target))
resp := make([]*targetCount, 0)
if err := x.SQL(rawSql).Find(&resp); err != nil {
+2 -2
View File
@@ -92,10 +92,10 @@ func TestQuotaCommandsAndQueries(t *testing.T) {
So(err, ShouldBeNil)
So(len(query.Result), ShouldEqual, 4)
for _, res := range query.Result {
limit := 5 //default quota limit
limit := 5 // default quota limit
used := 0
if res.Target == "org_user" {
limit = 10 //customized quota limit.
limit = 10 // customized quota limit.
used = 1
}
So(res.Limit, ShouldEqual, limit)
+1 -1
View File
@@ -560,7 +560,7 @@ func DeleteUser(cmd *models.DeleteUserCommand) error {
}
func deleteUserInTransaction(sess *DBSession, cmd *models.DeleteUserCommand) error {
//Check if user exists
// Check if user exists
user := models.User{Id: cmd.UserId}
has, err := sess.Get(&user)
if err != nil {