Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update github actions, add linter action #54

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint
on:
push:
branches:
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.21'

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55
25 changes: 9 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,28 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: '1.15.3'

- name: Install dependencies
run: |
go version
go get -u golang.org/x/lint/golint
go-version: '1.21'

- name: Run build
run: go build .
- name: Run vet & lint
run: go build .

- name: Run vet
run: |
go vet .
golint .


- name: Run tests
run: go test -v -coverprofile=profile.cov ./...

- name: codecov
uses: codecov/codecov-action@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
issues:
exclude-rules:
- path: '(.+)_test\.go'
linters:
- errcheck
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ import (
jsoniter "github.com/json-iterator/go"
"github.com/paulmach/osm"
)

var c = jsoniter.Config{
EscapeHTML: true,
SortMapKeys: false,
MarshalFloatWith6Digits: true,
}.Froze()
CustomJSONMarshaler = c
CustomJSONUnmarshaler = c

osmm.CustomJSONMarshaler = c
osm.CustomJSONUnmarshaler = c
```

The above change can have dramatic performance implications, see the benchmarks below
Expand Down
7 changes: 5 additions & 2 deletions annotate/relation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -42,7 +42,10 @@ func TestRelation(t *testing.T) {
t.Errorf("expected relations not equal, file saved to %s", filename)

data, _ := xml.MarshalIndent(&osm.OSM{Relations: relations}, "", " ")
ioutil.WriteFile(filename, data, 0644)
err := os.WriteFile(filename, data, 0644)
if err != nil {
t.Fatalf("write error: %v", err)
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion annotate/way_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -36,7 +37,10 @@ func TestWays(t *testing.T) {
t.Errorf("expected way not equal, file saved to %s", filename)

data, _ := xml.MarshalIndent(&osm.OSM{Ways: o.Ways}, "", " ")
ioutil.WriteFile(filename, data, 0644)
err := os.WriteFile(filename, data, 0644)
if err != nil {
t.Fatalf("write error: %v", err)
}
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,6 @@ func TestChange_HistoryDatasource(t *testing.T) {
}
}

func cleanXMLNameFromChange(c *Change) {
c.Version = ""
c.Generator = ""
c.Copyright = ""
c.Attribution = ""
c.License = ""
if c.Create != nil {
cleanXMLNameFromOSM(c.Create)
}
if c.Modify != nil {
cleanXMLNameFromOSM(c.Modify)
}
if c.Delete != nil {
cleanXMLNameFromOSM(c.Delete)
}
}

func BenchmarkChange_MarshalXML(b *testing.B) {
filename := "testdata/changeset_38162206.osc"
data := readFile(b, filename)
Expand Down
10 changes: 8 additions & 2 deletions diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ func BenchmarkDiff_Marshal(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
xml.Marshal(diff)
_, err := xml.Marshal(diff)
if err != nil {
b.Fatalf("marshal error: %v", err)
}
}
}

Expand All @@ -159,6 +162,9 @@ func BenchmarkDiff_Unmarshal(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
diff := &Diff{}
xml.Unmarshal(data, &diff)
err := xml.Unmarshal(data, &diff)
if err != nil {
b.Fatalf("unmarshal error: %v", err)
}
}
}
40 changes: 2 additions & 38 deletions osm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"encoding/xml"
"io/ioutil"
"io"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -280,50 +280,14 @@ func TestOSM_MarshalXML(t *testing.T) {
}
}

func flattenOSM(c *Change) *OSM {
o := c.Create
if o == nil {
o = &OSM{}
}

if c.Modify != nil {
o.Nodes = append(o.Nodes, c.Modify.Nodes...)
o.Ways = append(o.Ways, c.Modify.Ways...)
o.Relations = append(o.Relations, c.Modify.Relations...)
}

if c.Delete != nil {
o.Nodes = append(o.Nodes, c.Delete.Nodes...)
o.Ways = append(o.Ways, c.Delete.Ways...)
o.Relations = append(o.Relations, c.Delete.Relations...)
}

return o
}

func cleanXMLNameFromOSM(o *OSM) {
for _, n := range o.Nodes {
n.XMLName = xmlNameJSONTypeNode{}
}

for _, w := range o.Ways {
w.XMLName = xmlNameJSONTypeWay{}
}

for _, r := range o.Relations {
// r.XMLName = xml.Name{}
r.XMLName = xmlNameJSONTypeRel{}
}
}

func readFile(t testing.TB, filename string) []byte {
f, err := os.Open(filename)
if err != nil {
t.Fatalf("unable to open %s: %v", filename, err)
}
defer f.Close()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
t.Fatalf("unable to read file %s: %v", filename, err)
}
Expand Down
2 changes: 0 additions & 2 deletions osmapi/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func (o *at) applyFeature(p []string) ([]string, error) {
return append(p, "at="+o.t.UTC().Format("2006-01-02T15:04:05Z")), nil
}

func (o *at) feature() {}

// NotesOption defines a valid option for the osmapi.Notes by bounding box api.
type NotesOption interface {
applyNotes([]string) ([]string, error)
Expand Down
30 changes: 24 additions & 6 deletions osmgeojson/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ func BenchmarkConvert(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o)
_, err := Convert(o)
if err != nil {
b.Fatalf("convert error: %v", err)
}
}
}

Expand All @@ -25,7 +28,10 @@ func BenchmarkConvertAnnotated(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o)
_, err := Convert(o)
if err != nil {
b.Fatalf("convert error: %v", err)
}
}
}

Expand All @@ -35,7 +41,10 @@ func BenchmarkConvert_NoID(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoID(true))
_, err := Convert(o, NoID(true))
if err != nil {
b.Fatalf("convert error: %v", err)
}
}
}

Expand All @@ -45,7 +54,10 @@ func BenchmarkConvert_NoMeta(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoMeta(true))
_, err := Convert(o, NoMeta(true))
if err != nil {
b.Fatalf("convert error: %v", err)
}
}
}

Expand All @@ -55,7 +67,10 @@ func BenchmarkConvert_NoRelationMembership(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoRelationMembership(true))
_, err := Convert(o, NoRelationMembership(true))
if err != nil {
b.Fatalf("convert error: %v", err)
}
}
}

Expand All @@ -65,7 +80,10 @@ func BenchmarkConvert_NoIDsMetaMembership(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoID(true), NoMeta(true), NoRelationMembership(true))
_, err := Convert(o, NoID(true), NoMeta(true), NoRelationMembership(true))
if err != nil {
b.Fatalf("convert error: %v", err)
}
}
}

Expand Down
Loading
Loading