Skip to content

Commit ddfffcb

Browse files
author
Pi-Cla
committed
Apply go lints
1 parent c8d4e95 commit ddfffcb

12 files changed

Lines changed: 65 additions & 64 deletions

processors/agencyduplicateremover.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ package processors
88

99
import (
1010
"fmt"
11-
"github.com/public-transport/gtfsparser"
12-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1311
"hash/fnv"
1412
"os"
13+
14+
"github.com/public-transport/gtfsparser"
15+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1516
)
1617

1718
// AgencyDuplicateRemover merges semantically equivalent routes
@@ -116,9 +117,7 @@ func (adr *AgencyDuplicateRemover) combineAgencies(feed *gtfsparser.Feed, agenci
116117
}
117118
}
118119

119-
for _, attr := range a.Attributions {
120-
ref.Attributions = append(ref.Attributions, attr)
121-
}
120+
ref.Attributions = append(ref.Attributions, a.Attributions...)
122121

123122
for _, fa := range fareattrs[a] {
124123
if fa.Agency == a {

processors/frequencyminizer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ package processors
88

99
import (
1010
"fmt"
11-
"github.com/public-transport/gtfsparser"
12-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1311
"math"
1412
"os"
1513
"sort"
1614
"strconv"
1715
"sync"
16+
17+
"github.com/public-transport/gtfsparser"
18+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1819
)
1920

2021
// FrequencyMinimizer minimizes trips, stop_times and frequencies by searching optimal covers for trip times.
@@ -123,7 +124,7 @@ func (m FrequencyMinimizer) Run(feed *gtfsparser.Feed) {
123124
curTrip = new(gtfs.Trip)
124125

125126
var newID string
126-
for true {
127+
for {
127128
newID = t.Id + "_" + strconv.FormatInt(int64(suffixC), 10)
128129
if _, in := feed.Trips[newID]; in {
129130
suffixC++

processors/idminimizer.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ package processors
88

99
import (
1010
"fmt"
11-
"github.com/public-transport/gtfsparser"
12-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1311
"os"
1412
"strconv"
13+
14+
"github.com/public-transport/gtfsparser"
15+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1516
)
1617

1718
// IDMinimizer minimizes IDs by replacing them be continuous integer
@@ -246,22 +247,22 @@ func (minimizer IDMinimizer) minimizeStopIds(feed *gtfsparser.Feed) {
246247
func (minimizer IDMinimizer) minimizeAttributionIds(feed *gtfsparser.Feed) {
247248
var idCount int64 = 1
248249

249-
for i, _ := range feed.Attributions {
250+
for i := range feed.Attributions {
250251
newId := minimizer.Prefix + strconv.FormatInt(idCount, minimizer.Base)
251252
feed.Attributions[i].Id = newId
252253
idCount = idCount + 1
253254
}
254255

255256
for _, ag := range feed.Agencies {
256-
for i, _ := range ag.Attributions {
257+
for i := range ag.Attributions {
257258
newId := minimizer.Prefix + strconv.FormatInt(idCount, minimizer.Base)
258259
ag.Attributions[i].Id = newId
259260
idCount = idCount + 1
260261
}
261262
}
262263

263264
for _, r := range feed.Routes {
264-
for i, _ := range r.Attributions {
265+
for i := range r.Attributions {
265266
newId := minimizer.Prefix + strconv.FormatInt(idCount, minimizer.Base)
266267
r.Attributions[i].Id = newId
267268
idCount = idCount + 1
@@ -272,7 +273,7 @@ func (minimizer IDMinimizer) minimizeAttributionIds(feed *gtfsparser.Feed) {
272273
if t.Attributions == nil {
273274
continue
274275
}
275-
for i, _ := range *t.Attributions {
276+
for i := range *t.Attributions {
276277
newId := minimizer.Prefix + strconv.FormatInt(idCount, minimizer.Base)
277278
(*t.Attributions)[i].Id = newId
278279
idCount = idCount + 1

processors/routeduplicateremover.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ package processors
99
import (
1010
"encoding/binary"
1111
"fmt"
12-
"github.com/public-transport/gtfsparser"
13-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1412
"hash/fnv"
1513
"os"
1614
"unsafe"
15+
16+
"github.com/public-transport/gtfsparser"
17+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1718
)
1819

1920
// RouteDuplicateRemover merges semantically equivalent routes
@@ -187,9 +188,7 @@ func (rdr RouteDuplicateRemover) combineRoutes(feed *gtfsparser.Feed, routes []*
187188
}
188189
}
189190

190-
for _, attr := range r.Attributions {
191-
ref.Attributions = append(ref.Attributions, attr)
192-
}
191+
ref.Attributions = append(ref.Attributions, r.Attributions...)
193192

194193
// delete every fare rule that contains this route
195194
for _, fa := range feed.FareAttributes {

processors/servicecaldatesremover.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ package processors
99
import (
1010
"errors"
1111
"fmt"
12+
"os"
13+
1214
"github.com/public-transport/gtfsparser"
1315
gtfs "github.com/public-transport/gtfsparser/gtfs"
14-
"os"
1516
)
1617

1718
// ServiceCalDatesRemover removes any entry in calendar_dates.txt by
@@ -219,7 +220,7 @@ func (sm *ServiceCalDatesRem) freeTripId(feed *gtfsparser.Feed, prefix string) s
219220
return tid
220221
}
221222
}
222-
panic(errors.New("Ran out of free trip ids."))
223+
panic(errors.New("ran out of free trip ids"))
223224
}
224225

225226
// get a free service id with the given prefix
@@ -231,5 +232,5 @@ func (sm *ServiceCalDatesRem) freeServiceId(feed *gtfsparser.Feed, prefix string
231232
return sid
232233
}
233234
}
234-
panic(errors.New("Ran out of free service ids."))
235+
panic(errors.New("ran out of free service ids"))
235236
}

processors/serviceduplicateremover.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ package processors
99
import (
1010
"encoding/binary"
1111
"fmt"
12-
"github.com/public-transport/gtfsparser"
13-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1412
"hash/fnv"
1513
"os"
14+
15+
"github.com/public-transport/gtfsparser"
16+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1617
)
1718

1819
// ServiceDuplicateRemover removes duplicate services. Services are considered equal if they
@@ -47,7 +48,7 @@ func (sdr ServiceDuplicateRemover) Run(feed *gtfsparser.Feed) {
4748
}
4849

4950
sc := amaps[s]
50-
eqServices := sdr.getEquivalentServices(s, amaps, feed, chunks[sc.hash])
51+
eqServices := sdr.getEquivalentServices(s, amaps, chunks[sc.hash])
5152

5253
if len(eqServices) > 0 {
5354
sdr.combineServices(feed, append(eqServices, s), trips)
@@ -65,7 +66,7 @@ func (sdr ServiceDuplicateRemover) Run(feed *gtfsparser.Feed) {
6566
}
6667

6768
// Return the services that are equivalent to service
68-
func (m ServiceDuplicateRemover) getEquivalentServices(serv *gtfs.Service, amaps map[*gtfs.Service]ServiceCompressed, feed *gtfsparser.Feed, chunks [][]*gtfs.Service) []*gtfs.Service {
69+
func (m ServiceDuplicateRemover) getEquivalentServices(serv *gtfs.Service, amaps map[*gtfs.Service]ServiceCompressed, chunks [][]*gtfs.Service) []*gtfs.Service {
6970
rets := make([][]*gtfs.Service, len(chunks))
7071
sem := make(chan empty, len(chunks))
7172

@@ -127,7 +128,7 @@ func (m ServiceDuplicateRemover) getActiveMaps(feed *gtfsparser.Feed) map[*gtfs.
127128
cur.start = first
128129
cur.end = last
129130
cur.activeMap = sm.getActiveOnMap(first.GetTime(), last.GetTime(), s)
130-
cur.hash = m.serviceHash(cur.activeMap, first, last, s)
131+
cur.hash = m.serviceHash(cur.activeMap, first, last)
131132

132133
rets[j][s] = cur
133134
}
@@ -177,7 +178,7 @@ func (m ServiceDuplicateRemover) getServiceChunks(feed *gtfsparser.Feed, amaps m
177178
return chunks
178179
}
179180

180-
func (m ServiceDuplicateRemover) serviceHash(active []bool, first gtfs.Date, last gtfs.Date, s *gtfs.Service) uint32 {
181+
func (m ServiceDuplicateRemover) serviceHash(active []bool, first gtfs.Date, last gtfs.Date) uint32 {
181182
h := fnv.New32a()
182183

183184
bls := boolsToBytes(active)

processors/serviceminimizer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ package processors
88

99
import (
1010
"fmt"
11-
"github.com/public-transport/gtfsparser"
12-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1311
"os"
1412
"time"
13+
14+
"github.com/public-transport/gtfsparser"
15+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1516
)
1617

1718
// ServiceMinimizer minimizes services by finding optimal calendar.txt and
@@ -162,7 +163,7 @@ out:
162163
continue
163164
}
164165

165-
c := sm.countExceptions(service, activeOn, d, startDiff, endDiff, a, b, e)
166+
c := sm.countExceptions(activeOn, d, startDiff, endDiff, a, b, e)
166167

167168
if c < e {
168169
e = c
@@ -182,7 +183,7 @@ out:
182183
sm.updateService(service, bestMap, bestA, bestB, startTime, endTime, start, end)
183184
}
184185

185-
func (sm ServiceMinimizer) countExceptions(s *gtfs.Service, actmap []bool, bm uint, startDiff int, endDiff int, a int, b int, max uint) uint {
186+
func (sm ServiceMinimizer) countExceptions(actmap []bool, bm uint, startDiff int, endDiff int, a int, b int, max uint) uint {
186187
ret := uint(0)
187188
l := len(actmap)
188189

processors/servicenonoverlapper.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ package processors
88

99
import (
1010
"fmt"
11-
"github.com/public-transport/gtfsparser"
12-
gtfs "github.com/public-transport/gtfsparser/gtfs"
13-
"golang.org/x/exp/slices"
1411
"os"
1512
"sort"
1613
"strconv"
14+
15+
"github.com/public-transport/gtfsparser"
16+
gtfs "github.com/public-transport/gtfsparser/gtfs"
17+
"golang.org/x/exp/slices"
1718
)
1819

1920
type DayType struct {
@@ -54,16 +55,16 @@ func (sm ServiceNonOverlapper) Run(feed *gtfsparser.Feed) {
5455
}
5556
}
5657

57-
for wd, _ := range days {
58-
for day, _ := range days[wd] {
58+
for wd := range days {
59+
for day := range days[wd] {
5960
sort.Slice(days[wd][day], func(i, j int) bool {
6061
return days[wd][day][i].Id < days[wd][day][j].Id
6162
})
6263
}
6364
}
6465

6566
// collect day types
66-
for wd, _ := range days {
67+
for wd := range days {
6768
for day, trips := range days[wd] {
6869
found := false
6970
for i, existing := range day_types[wd] {
@@ -82,7 +83,7 @@ func (sm ServiceNonOverlapper) Run(feed *gtfsparser.Feed) {
8283
return len(day_types[wd][i].Dates) > len(day_types[wd][j].Dates)
8384
})
8485

85-
for i, _ := range day_types[wd] {
86+
for i := range day_types[wd] {
8687
sort.Slice(day_types[wd][i].Dates, func(a, b int) bool {
8788
return day_types[wd][i].Dates[a].GetTime().Before(day_types[wd][i].Dates[b].GetTime())
8889
})
@@ -95,7 +96,7 @@ func (sm ServiceNonOverlapper) Run(feed *gtfsparser.Feed) {
9596
feed.StopTimesAddFlds = make(map[string]map[string]map[int]string)
9697

9798
// write services
98-
for wd, _ := range days {
99+
for wd := range days {
99100
for _, t := range day_types[wd] {
100101
weeknums := make([]int, 0)
101102
for _, d := range t.Dates {
@@ -108,7 +109,7 @@ func (sm ServiceNonOverlapper) Run(feed *gtfsparser.Feed) {
108109
if len(day_types[wd]) > 1 {
109110
id += " ("
110111

111-
for i, _ := range weeknums {
112+
for i := range weeknums {
112113
if i == 0 {
113114
id += sm.YearWeekName + strconv.Itoa((weeknums[i]))
114115
continue

processors/shapeduplicateremover.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ package processors
88

99
import (
1010
"fmt"
11-
"github.com/public-transport/gtfsparser"
12-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1311
"math"
1412
"os"
13+
14+
"github.com/public-transport/gtfsparser"
15+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1516
)
1617

1718
// ShapeDuplicateRemover removes duplicate shapes
@@ -70,7 +71,7 @@ func (sdr ShapeDuplicateRemover) Run(feed *gtfsparser.Feed) {
7071
if sdr.deleted[s] {
7172
continue
7273
}
73-
eqShps := sdr.getEquShps(s, feed, chunkIdxs)
74+
eqShps := sdr.getEquShps(s, chunkIdxs)
7475

7576
if len(eqShps) > 0 {
7677
sdr.combineShapes(feed, append(eqShps, s), tidx)
@@ -83,7 +84,7 @@ func (sdr ShapeDuplicateRemover) Run(feed *gtfsparser.Feed) {
8384
}
8485

8586
// Return all shapes that are equivalent (within MaxEqDist) to shape
86-
func (sdr *ShapeDuplicateRemover) getEquShps(shp *gtfs.Shape, feed *gtfsparser.Feed, idxs []*ShapeIdx) []*gtfs.Shape {
87+
func (sdr *ShapeDuplicateRemover) getEquShps(shp *gtfs.Shape, idxs []*ShapeIdx) []*gtfs.Shape {
8788
rets := make([][]*gtfs.Shape, len(idxs))
8889
sem := make(chan empty, len(idxs))
8990

processors/shapeidx.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
package processors
88

99
import (
10-
gtfs "github.com/public-transport/gtfsparser/gtfs"
1110
"math"
11+
12+
gtfs "github.com/public-transport/gtfsparser/gtfs"
1213
)
1314

1415
// ShapeIdx stores objects for fast nearest-neighbor
@@ -137,7 +138,7 @@ func (gi *ShapeIdx) isects(x0, y0, x1, y1 float64, x, y uint) bool {
137138
ocode1 := gi.ocode(x1, y1, xmin, ymin, xmax, ymax)
138139
isect := false
139140

140-
for true {
141+
for {
141142
if (ocode0 | ocode1) == 0 {
142143
return true
143144
} else if (ocode0 & ocode1) != 0 {

0 commit comments

Comments
 (0)