Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Sep 23, 2023
1 parent 3ce706d commit a6d2dab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion gnovm/pkg/gnomod/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (f *File) FetchDeps(path string, remote string, verbose bool) error {
func (f *File) Write(fname string) error {
f.Syntax.Cleanup()
data := modfile.Format(f.Syntax)
err := os.WriteFile(fname, []byte(data), 0o644)
err := os.WriteFile(fname, data, 0o644)
if err != nil {
return fmt.Errorf("writefile %q: %w", fname, err)

Check warning on line 222 in gnovm/pkg/gnomod/file.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/file.go#L222

Added line #L222 was not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnomod/gnomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func GnoToGoMod(f File) (*File, error) {

// Remove replacements that are not replaced by directories.
//
// Explaination:
// Explanation:
// By this stage every replacement should be replace by dir.
// If not replaced by dir, remove it.
//
Expand Down
40 changes: 20 additions & 20 deletions gnovm/pkg/gnomod/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,15 +950,15 @@ func addLine(x *modfile.FileSyntax, hint modfile.Expr, tokens ...string) *modfil
}

newLineAfter := func(i int) *modfile.Line {
new := &modfile.Line{Token: tokens}
newl := &modfile.Line{Token: tokens}
if i == len(x.Stmt) {
x.Stmt = append(x.Stmt, new)
x.Stmt = append(x.Stmt, newl)
} else {
x.Stmt = append(x.Stmt, nil)
copy(x.Stmt[i+2:], x.Stmt[i+1:])
x.Stmt[i+1] = new
x.Stmt[i+1] = newl
}
return new
return newl

Check warning on line 961 in gnovm/pkg/gnomod/read.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/read.go#L953-L961

Added lines #L953 - L961 were not covered by tests
}

if hint != nil {
Expand All @@ -975,9 +975,9 @@ func addLine(x *modfile.FileSyntax, hint modfile.Expr, tokens ...string) *modfil
block := &modfile.LineBlock{Token: stmt.Token[:1], Line: []*modfile.Line{stmt}}
stmt.Token = stmt.Token[1:]
x.Stmt[i] = block
new := &modfile.Line{Token: tokens[1:], InBlock: true}
block.Line = append(block.Line, new)
return new
newl := &modfile.Line{Token: tokens[1:], InBlock: true}
block.Line = append(block.Line, newl)
return newl
}

case *modfile.LineBlock:
Expand All @@ -986,9 +986,9 @@ func addLine(x *modfile.FileSyntax, hint modfile.Expr, tokens ...string) *modfil
return newLineAfter(i)
}

Check warning on line 987 in gnovm/pkg/gnomod/read.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/read.go#L986-L987

Added lines #L986 - L987 were not covered by tests

new := &modfile.Line{Token: tokens[1:], InBlock: true}
stmt.Line = append(stmt.Line, new)
return new
newl := &modfile.Line{Token: tokens[1:], InBlock: true}
stmt.Line = append(stmt.Line, newl)
return newl
}

for j, line := range stmt.Line {
Expand All @@ -1000,24 +1000,24 @@ func addLine(x *modfile.FileSyntax, hint modfile.Expr, tokens ...string) *modfil
// Add new line after hint within the block.
stmt.Line = append(stmt.Line, nil)
copy(stmt.Line[j+2:], stmt.Line[j+1:])
new := &modfile.Line{Token: tokens[1:], InBlock: true}
stmt.Line[j+1] = new
return new
newl := &modfile.Line{Token: tokens[1:], InBlock: true}
stmt.Line[j+1] = newl
return newl

Check warning on line 1005 in gnovm/pkg/gnomod/read.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/read.go#L1001-L1005

Added lines #L1001 - L1005 were not covered by tests
}
}
}
}
}

new := &modfile.Line{Token: tokens}
x.Stmt = append(x.Stmt, new)
return new
newl := &modfile.Line{Token: tokens}
x.Stmt = append(x.Stmt, newl)
return newl
}

func addReplace(syntax *modfile.FileSyntax, replace *[]*modfile.Replace, oldPath, oldVers, newPath, newVers string) error {
need := true
old := module.Version{Path: oldPath, Version: oldVers}
new := module.Version{Path: newPath, Version: newVers}
oldv := module.Version{Path: oldPath, Version: oldVers}
newv := module.Version{Path: newPath, Version: newVers}
tokens := []string{"replace", modfile.AutoQuote(oldPath)}
if oldVers != "" {
tokens = append(tokens, oldVers)
Expand All @@ -1032,7 +1032,7 @@ func addReplace(syntax *modfile.FileSyntax, replace *[]*modfile.Replace, oldPath
if r.Old.Path == oldPath && (oldVers == "" || r.Old.Version == oldVers) {
if need {
// Found replacement for old; update to use new.
r.New = new
r.New = newv
updateLine(r.Syntax, tokens...)
need = false
continue

Check warning on line 1038 in gnovm/pkg/gnomod/read.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/read.go#L1033-L1038

Added lines #L1033 - L1038 were not covered by tests
Expand All @@ -1046,7 +1046,7 @@ func addReplace(syntax *modfile.FileSyntax, replace *[]*modfile.Replace, oldPath
}

Check warning on line 1046 in gnovm/pkg/gnomod/read.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnomod/read.go#L1045-L1046

Added lines #L1045 - L1046 were not covered by tests
}
if need {
*replace = append(*replace, &modfile.Replace{Old: old, New: new, Syntax: addLine(syntax, hint, tokens...)})
*replace = append(*replace, &modfile.Replace{Old: oldv, New: newv, Syntax: addLine(syntax, hint, tokens...)})
}
return nil
}

0 comments on commit a6d2dab

Please sign in to comment.