Skip to content

Commit ec79c36

Browse files
committed
Revert and fix linting and add test
1 parent 5ea4db8 commit ec79c36

58 files changed

Lines changed: 680 additions & 423 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Run linter
21+
uses: golangci/golangci-lint-action@v9
22+
with:
23+
version: v2.12.1

.golangci.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
version: "2"
2+
run:
3+
timeout: 5m
4+
modules-download-mode: readonly
5+
tests: true
6+
7+
linters:
8+
default: none
9+
enable:
10+
- asasalint
11+
- asciicheck
12+
- bidichk
13+
- bodyclose
14+
- copyloopvar
15+
- cyclop
16+
- dogsled
17+
- dupl
18+
- durationcheck
19+
- errcheck
20+
- errname
21+
- errorlint
22+
- exhaustive
23+
- exptostd
24+
- fatcontext
25+
- forbidigo
26+
- funlen
27+
- gocheckcompilerdirectives
28+
- goconst
29+
- gocritic
30+
- gomoddirectives
31+
- gomodguard
32+
- goprintffuncname
33+
- gosec
34+
- govet
35+
- ineffassign
36+
- loggercheck
37+
- makezero
38+
- mirror
39+
- misspell
40+
- nakedret
41+
- nestif
42+
- nilerr
43+
- nolintlint
44+
- nosprintfhostport
45+
- perfsprint
46+
- predeclared
47+
- promlinter
48+
- reassign
49+
- revive
50+
- rowserrcheck
51+
- sloglint
52+
- sqlclosecheck
53+
- staticcheck
54+
- tagliatelle
55+
- testableexamples
56+
- tparallel
57+
- unconvert
58+
- unparam
59+
- unused
60+
- usestdlibvars
61+
- usetesting
62+
- wastedassign # finds wasted assignment statements
63+
settings:
64+
revive:
65+
rules:
66+
# default rules
67+
- name: blank-imports
68+
- name: context-as-argument
69+
- name: context-keys-type
70+
- name: dot-imports
71+
- name: empty-block
72+
- name: error-naming
73+
- name: error-return
74+
- name: error-strings
75+
- name: errorf
76+
- name: increment-decrement
77+
- name: indent-error-flow
78+
- name: range
79+
- name: receiver-naming
80+
- name: redefines-builtin-id
81+
- name: superfluous-else
82+
- name: time-naming
83+
- name: unexported-return
84+
- name: unreachable-code
85+
- name: unused-parameter
86+
- name: var-declaration
87+
# enabled or tweaked by us
88+
- name: use-any
89+
cyclop:
90+
max-complexity: 15
91+
depguard:
92+
rules:
93+
main:
94+
deny:
95+
- pkg: github.com/pkg/errors
96+
desc: Should be replaced by standard lib errors package
97+
forbidigo:
98+
forbid:
99+
- pattern: http\.NotFound.*
100+
- pattern: http\.Error.*
101+
funlen:
102+
lines: 100
103+
gomoddirectives:
104+
replace-allow-list:
105+
- github.com/abbot/go-http-auth
106+
nestif:
107+
min-complexity: 6
108+
exclusions:
109+
generated: lax
110+
presets:
111+
- comments
112+
- common-false-positives
113+
- legacy
114+
- std-error-handling
115+
rules:
116+
- linters:
117+
- bodyclose
118+
- dogsled
119+
- dupl
120+
- funlen
121+
- gosec
122+
path: _test\.go
123+
- linters:
124+
- cyclop
125+
- goconst
126+
- staticcheck
127+
path: (.+)_test\.go
128+
paths:
129+
- third_party$
130+
- builtin$
131+
- examples$

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ogc-specifications
2-
2+
[![Lint](https://github.com/PDOK/ogc-specifications/actions/workflows/lint.yml/badge.svg)](https://github.com/PDOK/ogc-specifications/actions/workflows/lint.yml)
33
![GitHub license](https://img.shields.io/github/license/PDOK/ogc-specifications)
44
[![GitHub
55
release](https://img.shields.io/github/release/PDOK/ogc-specifications.svg)](https://github.com/PDOK/ogc-specifications/releases)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/pdok/ogc-specifications
22

3-
go 1.26
3+
go 1.26.3
44

55
require gopkg.in/yaml.v3 v3.0.1

pkg/utils/xml.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,32 @@ type XMLAttribute []xml.Attr
99

1010
// StripDuplicateAttr removes the duplicate Attributes from a []Attribute
1111
func StripDuplicateAttr(attr []xml.Attr) []xml.Attr {
12-
attributemap := make(map[xml.Name]string)
12+
attributeMap := make(map[xml.Name]string)
1313
for _, a := range attr {
14-
attributemap[xml.Name{Space: a.Name.Space, Local: a.Name.Local}] = a.Value
14+
attributeMap[xml.Name{Space: a.Name.Space, Local: a.Name.Local}] = a.Value
1515
}
1616

1717
var strippedAttr []xml.Attr
18-
for k, v := range attributemap {
18+
for k, v := range attributeMap {
1919
strippedAttr = append(strippedAttr, xml.Attr{Name: k, Value: v})
2020
}
2121
return strippedAttr
2222
}
2323

2424
// UnmarshalXML func for the XMLAttr struct
2525
func (xmlattr *XMLAttribute) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
26-
var newattributes XMLAttribute
26+
var newAttributes XMLAttribute
2727
for _, attr := range start.Attr {
28-
switch attr.Name.Local {
29-
default:
30-
newattributes = append(newattributes, xml.Attr{Name: attr.Name, Value: attr.Value})
31-
}
28+
newAttributes = append(newAttributes, xml.Attr{Name: attr.Name, Value: attr.Value})
3229
}
33-
*xmlattr = newattributes
30+
*xmlattr = newAttributes
3431

3532
for {
3633
// if it got this far the XML is 'valid' and the xmlattr are set
3734
// so we ignore the err
3835
token, _ := d.Token()
39-
switch el := token.(type) {
40-
case xml.EndElement:
36+
37+
if el, ok := token.(xml.EndElement); ok {
4138
if el == start.End() {
4239
return nil
4340
}

pkg/wcs201/capabilities.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package wcs201
22

33
// ParseXML func
4-
func (c *Capabilities) ParseXML(doc []byte) error {
4+
func (c *Capabilities) ParseXML(_ []byte) error {
55
return nil
66
}
77

88
// ParseYAML func
9-
func (c *Capabilities) ParseYAML(doc []byte) error {
9+
func (c *Capabilities) ParseYAML(_ []byte) error {
1010
return nil
1111
}
1212

pkg/wcs201/getcapabilities_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (gc *GetCapabilitiesRequest) Type() string {
2323
}
2424

2525
// Validate validates the GetCapabilities struct
26-
func (gc *GetCapabilitiesRequest) Validate(c Capabilities) []wsc200.Exception {
26+
func (gc *GetCapabilitiesRequest) Validate(_ Capabilities) []wsc200.Exception {
2727
return nil
2828
}
2929

pkg/wfs200/capabilities.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package wfs200
22

33
import (
44
"encoding/xml"
5+
56
"github.com/pdok/ogc-specifications/pkg/wsc110"
67
)
78

89
// ParseXML func
9-
func (c *Capabilities) ParseXML(doc []byte) error {
10+
func (c *Capabilities) ParseXML(_ []byte) error {
1011
return nil
1112
}
1213

1314
// ParseYAML func
14-
func (c *Capabilities) ParseYAML(doc []byte) error {
15+
func (c *Capabilities) ParseYAML(_ []byte) error {
1516
return nil
1617
}
1718

@@ -164,7 +165,7 @@ type MetadataHref struct {
164165
// FilterCapabilities struct for the WFS 2.0.0
165166
type FilterCapabilities struct {
166167
Conformance Conformance `xml:"fes:Conformance" yaml:"conformance"`
167-
IDCapabilities IdCapabilities `xml:"fes:Id_Capabilities" yaml:"idCapabilities"`
168+
IDCapabilities IDCapabilities `xml:"fes:Id_Capabilities" yaml:"idCapabilities"`
168169
ScalarCapabilities ScalarCapabilities `xml:"fes:Scalar_Capabilities" yaml:"scalarCapabilities"`
169170
SpatialCapabilities SpatialCapabilities `xml:"fes:Spatial_Capabilities" yaml:"spatialCapabilities"`
170171
// NO TemporalCapabilities!!!
@@ -176,8 +177,8 @@ type Conformance struct {
176177
Constraint []ValueConstraint `xml:"fes:Constraint" yaml:"constraint"`
177178
}
178179

179-
// IdCapabilities struct for the WFS 2.0.0
180-
type IdCapabilities struct {
180+
// IDCapabilities struct for the WFS 2.0.0
181+
type IDCapabilities struct {
181182
ResourceIdentifier ResourceIdentifier `xml:"fes:ResourceIdentifier" yaml:"resourceIdentifier"`
182183
}
183184

pkg/wfs200/crs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const (
1111

1212
// CRS struct with namespace/authority/registry and code
1313
type CRS struct {
14-
Namespace string //TODO maybe AuthorityType is a better name...?
14+
Namespace string // TODO maybe AuthorityType is a better name...?
1515
Code int
1616
}
1717

pkg/wfs200/crs_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ othercrs:
5151
err := yaml.Unmarshal(test.yaml, &ftl)
5252
if err != nil {
5353
t.Errorf("test: %d, yaml.UnMarshal failed with '%s'\n", k, err)
54-
} else {
55-
if ftl.DefaultCRS.Code != test.expectedcrs.Code || ftl.DefaultCRS.Namespace != test.expectedcrs.Namespace {
56-
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedcrs, ftl.DefaultCRS)
57-
}
54+
} else if ftl.DefaultCRS.Code != test.expectedcrs.Code || ftl.DefaultCRS.Namespace != test.expectedcrs.Namespace {
55+
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedcrs, ftl.DefaultCRS)
5856
}
5957
}
6058
}
@@ -70,13 +68,11 @@ func TestMarshalYAMLCrs(t *testing.T) {
7068
}
7169
for k, test := range tests {
7270
yamlCRS, err := yaml.Marshal(test.CRS)
71+
7372
if err != nil {
7473
t.Errorf("test: %d, yaml.Marshal failed with '%s'\n", k, err)
75-
} else {
76-
stringCRS := string(yamlCRS)
77-
if stringCRS != test.expectedYAML {
78-
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS)
79-
}
74+
} else if stringCRS := string(yamlCRS); stringCRS != test.expectedYAML {
75+
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS)
8076
}
8177
}
8278
}

0 commit comments

Comments
 (0)