Skip to content

Commit

Permalink
fix pipeline linting (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
srliao authored Sep 22, 2023
1 parent 0d4ce88 commit 6453281
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 73 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ linters-settings:
use-field-name: true
rules:
json: snake
yaml: snake

severity:
default-severity: error
Expand Down
3 changes: 0 additions & 3 deletions backend/pkg/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"math/rand"
"os"
"testing"
"time"

"github.com/genshinsim/gcsim/backend/pkg/services/db"
"github.com/genshinsim/gcsim/pkg/model"
Expand Down Expand Up @@ -97,8 +96,6 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}

rand.Seed(time.Now().Unix())

// run tests
code := m.Run()

Expand Down
1 change: 1 addition & 0 deletions pipeline/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data
10 changes: 5 additions & 5 deletions pipeline/cmd/pipeline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
)

type config struct {
//input data
// input data
charPath string
weapPath string
artifactPath string
excelPath string

//output paths
// output paths
uiOut string
dbOut string
}
Expand All @@ -31,7 +31,7 @@ func main() {
flag.StringVar(&cfg.dbOut, "outdb", "./ui/packages/db/src/Data", "folder to output generated json for DB")
flag.Parse()

//generate character data
// generate character data
log.Println("running pipeline for characters...")
g, err := character.NewGenerator(character.GeneratorConfig{
Root: cfg.charPath,
Expand All @@ -53,7 +53,7 @@ func main() {
panic(err)
}

//generate weapon data
// generate weapon data
log.Println("running pipeline for weapons...")
gw, err := weapon.NewGenerator(weapon.GeneratorConfig{
Root: cfg.weapPath,
Expand All @@ -69,7 +69,7 @@ func main() {
panic(err)
}

//generate artifact data
// generate artifact data
log.Println("running pipeline for artifacts...")
ga, err := artifact.NewGenerator(artifact.GeneratorConfig{
Root: cfg.artifactPath,
Expand Down
8 changes: 4 additions & 4 deletions pipeline/pkg/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Config struct {
Key string `yaml:"key,omitempty"`
TextMapId string `yaml:"text_map_id,omitempty"`

//extra fields to be populate but not read from yaml
// extra fields to be populate but not read from yaml
RelativePath string `yaml:"-"`
}

Expand All @@ -38,16 +38,16 @@ func NewGenerator(cfg GeneratorConfig) (*Generator, error) {
}
g.artifacts = a

textIdCheck := make(map[string]bool)
textIDCheck := make(map[string]bool)

for _, v := range a {
if _, ok := g.data[v.Key]; ok {
return nil, fmt.Errorf("duplicated key %v found; second instance at %v", v.Key, v.RelativePath)
}
if _, ok := textIdCheck[v.TextMapId]; ok {
if _, ok := textIDCheck[v.TextMapId]; ok {
return nil, fmt.Errorf("duplicated text map id %v found; second instance at %v", v.TextMapId, v.RelativePath)
}
textIdCheck[v.TextMapId] = true
textIDCheck[v.TextMapId] = true
g.data[v.Key] = &model.ArtifactData{
TextMapId: v.TextMapId,
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/pkg/artifact/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func readArtifact(path string) (Config, error) {
c := Config{}
data, err := os.ReadFile(path)
if err != nil {
return c, fmt.Errorf("error reading %v: %v", path, err)
return c, fmt.Errorf("error reading %v: %w", path, err)
}
err = yaml.Unmarshal(data, &c)
if err != nil {
return c, fmt.Errorf("error parsing config %v: %v", path, err)
return c, fmt.Errorf("error parsing config %v: %w", path, err)
}

return c, nil
Expand Down
4 changes: 2 additions & 2 deletions pipeline/pkg/artifact/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (g *Generator) DumpJSON(path string) error {
//delete existing
// delete existing
err := g.writeCharDataJSON(path + "/artifact_data.generated.json")
if err != nil {
return err
Expand All @@ -28,7 +28,7 @@ func (g *Generator) writeCharDataJSON(path string) error {
}
s := protojson.Format(m)
os.Remove(path)
err := os.WriteFile(path, []byte(s), 0644)
err := os.WriteFile(path, []byte(s), 0o644)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/pkg/character/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Config struct {
Key string `yaml:"key,omitempty"`
Shortcuts []string `yaml:"shortcuts,omitempty"`

//extra fields to be populate but not read from yaml
// extra fields to be populate but not read from yaml
RelativePath string `yaml:"-"`
}

Expand Down
4 changes: 2 additions & 2 deletions pipeline/pkg/character/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func readChar(path string) (Config, error) {
c := Config{}
data, err := os.ReadFile(path)
if err != nil {
return c, fmt.Errorf("error reading %v: %v", path, err)
return c, fmt.Errorf("error reading %v: %w", path, err)
}
err = yaml.Unmarshal(data, &c)
if err != nil {
return c, fmt.Errorf("error parsing config %v: %v", path, err)
return c, fmt.Errorf("error parsing config %v: %w", path, err)
}

return c, nil
Expand Down
7 changes: 3 additions & 4 deletions pipeline/pkg/character/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestParseCharConfigs(t *testing.T) {
//write 2 config yaml to file, read it back
// write 2 config yaml to file, read it back
dir := t.TempDir()
r := []Config{
{
Expand All @@ -20,15 +20,15 @@ func TestParseCharConfigs(t *testing.T) {
},
}
for _, v := range r {
err := os.Mkdir(dir+"/"+v.PackageName, 0755)
err := os.Mkdir(dir+"/"+v.PackageName, 0o755)
if err != nil {
t.Fatal(err)
}
data, err := yaml.Marshal(v)
if err != nil {
t.Fatal(err)
}
err = os.WriteFile(fmt.Sprintf("%v/%v/config.yml", dir, v.PackageName), data, 0644)
err = os.WriteFile(fmt.Sprintf("%v/%v/config.yml", dir, v.PackageName), data, 0o644)
if err != nil {
t.Fatal(err)
}
Expand All @@ -48,5 +48,4 @@ func TestParseCharConfigs(t *testing.T) {
t.Errorf("data not matching, expecting pkg name %v, got pkg name %v", r[i].PackageName, v.PackageName)
}
}

}
6 changes: 3 additions & 3 deletions pipeline/pkg/character/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (g *Generator) DumpJSON(path string) error {
//delete existing
// delete existing
err := g.writeCharDataJSON(path + "/char_data.generated.json")
if err != nil {
return err
Expand All @@ -20,7 +20,7 @@ func (g *Generator) DumpJSON(path string) error {
func (g *Generator) writeCharDataJSON(path string) error {
data := make(map[string]*model.AvatarData)
for _, v := range g.data {
//hide promodata from ui json; not needed
// hide promodata from ui json; not needed
x := proto.Clone(v).(*model.AvatarData)
x.Stats = nil
data[v.Key] = x
Expand All @@ -30,7 +30,7 @@ func (g *Generator) writeCharDataJSON(path string) error {
}
s := protojson.Format(m)
os.Remove(path)
err := os.WriteFile(path, []byte(s), 0644)
err := os.WriteFile(path, []byte(s), 0o644)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions pipeline/pkg/data/avatar/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func (a *DataSource) parseChar(id, sub int32) (*model.AvatarData, error) {
err = a.parseWeaponClass(c, err)
err = a.parseIconName(c, err)

//grab character skills and map that to skill/burst/attack first
// grab character skills and map that to skill/burst/attack first
err = a.parseSkillIDs(c, err)

//element is based on character burst skill
//this MUST BE DONE AFTER parsing skill
// element is based on character burst skill
// this MUST BE DONE AFTER parsing skill
err = a.parseElement(c, err)

//handle stat block
// handle stat block
err = a.parseBaseStats(c, err)
err = a.parseStatCurves(c, err)
err = a.parsePromoData(c, err)
Expand Down Expand Up @@ -124,8 +124,8 @@ func (a *DataSource) parseCharAssociation(c *model.AvatarData, err error) error
}
c.Region = model.ZoneType(model.ZoneType_value[fd.AvatarAssocType])
if c.Region == model.ZoneType_INVALID_ZONE_TYPE {
//region does not have to be valid; just warn here
//traveler for example does not have a region
// region does not have to be valid; just warn here
// traveler for example does not have a region
log.Printf("WARNING: invalid region for char id %v: %v\n", c.Id, fd.AvatarAssocType)
}
return err
Expand Down Expand Up @@ -185,7 +185,7 @@ func (a *DataSource) parseSkillIDs(c *model.AvatarData, err error) error {
}

func (a *DataSource) parseElement(c *model.AvatarData, err error) error {
//element is found from burstID
// element is found from burstID
burstId := c.GetSkillDetails().GetBurst()
se, ok := a.skillExcel[burstId]
if !ok {
Expand Down
13 changes: 6 additions & 7 deletions pipeline/pkg/data/avatar/avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestParseCharacter(t *testing.T) {
t.Fatal(err)
}

//needs to be typed so the comparison works
var id int32 = 10000002 //ayaka
// needs to be typed so the comparison works
var id int32 = 10000002 // ayaka

d, err := a.parseChar(id, 0)
if err != nil {
Expand All @@ -33,12 +33,12 @@ func TestParseCharacter(t *testing.T) {
expect(t, "element", model.Element_Ice, d.Element)
expect(t, "weapon class", model.WeaponClass_WEAPON_SWORD_ONE_HAND, d.WeaponClass)
expect(t, "icon", string("UI_AvatarIcon_Ayaka"), d.IconName)
expect(t, "burst id", int32(10019), d.GetSkillDetails().GetBurst()) //ayaka burst is 10019
expect(t, "burst id", int32(10019), d.GetSkillDetails().GetBurst()) // ayaka burst is 10019
expect(t, "attack id", int32(10024), d.GetSkillDetails().GetAttack())
expect(t, "skill id", int32(10018), d.GetSkillDetails().GetSkill())
expectTol(t, "burst energy cost", float64(80), d.GetSkillDetails().GetBurstEnergyCost(), 0.000000001)

//stat block
// stat block
expectTol(t, "base attack", 26.6266, d.GetStats().BaseAtk, 0.00001)
expectTol(t, "base hp", 1000.98602, d.GetStats().BaseHp, 0.00001)
expectTol(t, "base def", 61.02659, d.GetStats().BaseDef, 0.00001)
Expand All @@ -61,8 +61,8 @@ func TestParseCharacter(t *testing.T) {
}
}

//make sure traveler is picking up correct skills
id = 10000007 //lumine
// make sure traveler is picking up correct skills
id = 10000007 // lumine

d, err = a.parseChar(id, 707)
if err != nil {
Expand All @@ -84,7 +84,6 @@ func TestParseCharacter(t *testing.T) {
expect(t, "attack id", int32(100556), d.GetSkillDetails().GetAttack())
expect(t, "skill id", int32(10602), d.GetSkillDetails().GetSkill())
expectTol(t, "burst energy cost", float64(80), d.GetSkillDetails().GetBurstEnergyCost(), 0.000000001)

}

func expect(t *testing.T, msg string, expect, got any) error {
Expand Down
18 changes: 9 additions & 9 deletions pipeline/pkg/data/avatar/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func loadAvatarExcel(path string) (map[int32]dm.AvatarExcel, error) {
return nil, err
}
data := make(map[int32]dm.AvatarExcel)
for _, v := range res {
//mhy can break this...
//sanity check in case mhy allows for duplicated ids in future
if _, ok := data[v.ID]; ok {
return nil, fmt.Errorf("unexpected duplicated id: %v", v.ID)
for i := range res {
// mhy can break this...
// sanity check in case mhy allows for duplicated ids in future
if _, ok := data[res[i].ID]; ok {
return nil, fmt.Errorf("unexpected duplicated id: %v", res[i].ID)
}
data[v.ID] = v
data[res[i].ID] = res[i]
}
return data, nil
}
Expand All @@ -55,7 +55,7 @@ func loadAvatarSkillDepot(path string) (map[int32]dm.AvatarSkillDepot, error) {
}
data := make(map[int32]dm.AvatarSkillDepot)
for _, v := range res {
//sanity check in case mhy allows for duplicated ids in future
// sanity check in case mhy allows for duplicated ids in future
if _, ok := data[v.ID]; ok {
return nil, fmt.Errorf("unexpected duplicated id: %v", v.ID)
}
Expand All @@ -72,7 +72,7 @@ func loadAvatarSkillExcel(path string) (map[int32]dm.AvatarSkillExcel, error) {
}
data := make(map[int32]dm.AvatarSkillExcel)
for _, v := range res {
//sanity check in case mhy allows for duplicated ids in future
// sanity check in case mhy allows for duplicated ids in future
if _, ok := data[v.ID]; ok {
return nil, fmt.Errorf("unexpected duplicated id: %v", v.ID)
}
Expand All @@ -89,7 +89,7 @@ func loadAvatarFetterInfo(path string) (map[int32]dm.AvatarFetterInfo, error) {
}
data := make(map[int32]dm.AvatarFetterInfo)
for _, v := range res {
//sanity check in case mhy allows for duplicated ids in future
// sanity check in case mhy allows for duplicated ids in future
if _, ok := data[v.AvatarId]; ok {
return nil, fmt.Errorf("unexpected duplicated id: %v", v.AvatarId)
}
Expand Down
3 changes: 0 additions & 3 deletions pipeline/pkg/data/avatar/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestLoadAvatarSkillExcel(t *testing.T) {
if len(res) == 0 {
t.Error("res length cannot be 0")
}

}

func TestLoadFetterInfo(t *testing.T) {
Expand All @@ -63,7 +62,6 @@ func TestLoadFetterInfo(t *testing.T) {
if len(res) == 0 {
t.Error("res length cannot be 0")
}

}

func TestLoadPromotData(t *testing.T) {
Expand All @@ -77,5 +75,4 @@ func TestLoadPromotData(t *testing.T) {
if len(res) == 0 {
t.Error("res length cannot be 0")
}

}
Loading

0 comments on commit 6453281

Please sign in to comment.