Skip to content

Commit 55a3075

Browse files
committed
cedar-go: upgrade golangci-lint checks to v2 and fix all issues found
I preserved the list of linters that we run, but enabled almost all of the revive rules. We can disable them as we see fit in the future. The only regrettable exclusion is on the `exported` rule in the `types/` directory. We should make an effort to document all of the public types. Signed-off-by: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
1 parent f574d16 commit 55a3075

35 files changed

+522
-684
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,4 @@ jobs:
1919
go-version: "1.22"
2020
cache: false
2121
- name: golangci-lint
22-
uses: golangci/golangci-lint-action@v4
23-
with:
24-
# Require: The version of golangci-lint to use.
25-
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
26-
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
27-
version: v1.56.2
28-
29-
# Optional: working directory, useful for monorepos
30-
# working-directory: somedir
31-
32-
# Optional: golangci-lint command line arguments.
33-
#
34-
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
35-
# The location of the configuration file can be changed by using `--config=`
36-
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
37-
38-
# Optional: show only new issues if it's a pull request. The default value is `false`.
39-
# only-new-issues: true
40-
41-
# Optional: if set to true, then all caching functionality will be completely disabled,
42-
# takes precedence over all other caching options.
43-
# skip-cache: true
44-
45-
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
46-
# skip-pkg-cache: true
47-
48-
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
49-
# skip-build-cache: true
50-
51-
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
52-
# install-mode: "goinstall"
22+
uses: golangci/golangci-lint-action@v7

.golangci.yml

Lines changed: 30 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -1,218 +1,34 @@
1-
run:
2-
build-tags:
3-
- dev
4-
timeout: 10m
5-
go: 1.22
6-
1+
version: "2"
72
linters:
8-
disable-all: true
93
enable:
10-
- bodyclose
11-
- errcheck
12-
- errname
13-
- gofmt
14-
- goimports
15-
- govet
16-
- ineffassign
17-
- staticcheck
18-
- unused
19-
- revive
4+
- errcheck
5+
- errname
6+
- govet
7+
- ineffassign
8+
- revive
9+
- staticcheck
10+
exclusions:
11+
rules:
12+
# Legitimate exclusion - we don't need to thoroughly document internal types
13+
- path: internal/
14+
linters:
15+
- revive
16+
text: exported
2017

21-
issues:
22-
max-issues-per-linter: 100
23-
max-same-issues: 100
24-
exclude-rules:
25-
# Exclude some linters from running on tests files.
26-
- path: _test\.go
27-
linters:
28-
- bodyclose
18+
# Legitimate exclusion - we don't need to thoroughly document unstable interfaces
19+
- path: x/
20+
linters:
21+
- revive
22+
text: exported
2923

30-
linters-settings:
31-
staticcheck:
32-
# Disabled checks:
33-
# - SA1019: Using a deprecated function, variable, constant or field
34-
# - SA9003: Empty body in an if or else branch
35-
checks: ["all", "-SA1019", "-SA9003"]
36-
revive:
37-
rules:
38-
- name: add-constant
39-
disabled: true
40-
- name: atomic
41-
disabled: false
42-
severity: error
43-
- name: argument-limit
44-
disabled: false
45-
- name: banned-characters
46-
disabled: false
47-
severity: error
48-
- name: bare-return
49-
disabled: true
50-
- name: blank-imports
51-
disabled: false
52-
severity: error
53-
- name: bool-literal-in-expr
54-
disabled: false
55-
- name: call-to-gc
56-
disabled: false
57-
- name: cognitive-complexity # revisit periodically - exclude tests
58-
disabled: false
59-
arguments: [65] # emprically set to upper bound
60-
- name: comment-spacings
61-
disabled: false
62-
- name: confusing-naming # too opinionated
63-
disabled: true
64-
- name: confusing-results
65-
disabled: false
66-
- name: constant-logical-expr
67-
disabled: false
68-
severity: error
69-
- name: context-as-argument
70-
disabled: false
71-
- name: context-keys-type
72-
disabled: false
73-
- name: cyclomatic # revisit - exclude tests
74-
disabled: false
75-
arguments: [92] # emprically set to upper bound
76-
- name: datarace
77-
disabled: false
78-
severity: error
79-
- name: deep-exit
80-
disabled: false
81-
- name: defer # often wrong
82-
disabled: false
83-
- name: dot-imports
84-
disabled: false
85-
severity: error
86-
- name: duplicated-imports
87-
disabled: false
88-
severity: error
89-
- name: early-return
90-
disabled: false
91-
- name: empty-block
92-
disabled: false
93-
- name: empty-lines # maybe correct but annoying
94-
disabled: true
95-
- name: enforce-map-style
96-
disabled: false
97-
severity: error
98-
- name: enforce-slice-style
99-
disabled: false
100-
severity: error
101-
- name: errorf
102-
disabled: false
103-
severity: error
104-
- name: error-naming
105-
disabled: false
106-
severity: error
107-
- name: error-return # fine, but unnecessarily picky
108-
disabled: false
109-
- name: error-strings # fine, but unnecessarily picky
110-
disabled: false
111-
- name: exported # possibly too opinionated
112-
disabled: false
113-
- name: file-header
114-
disabled: false
115-
severity: error
116-
- name: flag-parameter # often wrong
117-
disabled: true
118-
- name: function-length # revisit - exclude tests
119-
disabled: false
120-
arguments: [136, 702] # emprically set to upper bound
121-
- name: function-result-limit
122-
disabled: false
123-
- name: get-return
124-
disabled: false
125-
- name: identical-branches
126-
disabled: false
127-
severity: error
128-
- name: if-return # reasonable candidate but too opinonated
129-
disabled: false
130-
- name: import-alias-naming
131-
disabled: false
132-
- name: import-shadowing # sounds nice, but too many good variable names are taken up by packages.
133-
disabled: false
134-
- name: increment-decrement # just style
135-
disabled: false
136-
- name: indent-error-flow # fine, but unnecessarily picky
137-
disabled: true
138-
- name: line-length-limit
139-
disabled: true
140-
- name: max-public-structs # too opinionated
141-
disabled: true
142-
- name: modifies-parameter
143-
disabled: false
144-
severity: error
145-
- name: modifies-value-receiver
146-
disabled: false
147-
severity: error
148-
- name: nested-structs # deliberately used in some places
149-
disabled: true
150-
- name: optimize-operands-order
151-
disabled: false
152-
severity: error
153-
- name: package-comments
154-
disabled: false
155-
severity: error
156-
- name: range
157-
disabled: false
158-
severity: error
159-
- name: range-val-address
160-
disabled: false
161-
severity: error
162-
- name: range-val-in-closure
163-
disabled: false
164-
severity: error
165-
- name: receiver-naming # unnecessarily picky
166-
disabled: true
167-
- name: redefines-builtin-id # useful
168-
disabled: false
169-
- name: redundant-import-alias
170-
disabled: false
171-
- name: string-of-int
172-
disabled: false
173-
severity: error
174-
- name: string-format
175-
disabled: false
176-
severity: error
177-
- name: struct-tag # often wrong
178-
disabled: false
179-
- name: superfluous-else
180-
disabled: false
181-
severity: error
182-
- name: time-equal
183-
disabled: false
184-
severity: error
185-
- name: time-naming
186-
disabled: false
187-
- name: unchecked-type-assertion # a panic here is sometimes correct as a programming error
188-
disabled: false
189-
- name: unconditional-recursion
190-
disabled: false
191-
severity: error
192-
- name: unexported-naming
193-
disabled: false
194-
severity: error
195-
- name: unexported-return
196-
disabled: false
197-
- name: unhandled-error # complains about e.g. fmt.Println
198-
disabled: true
199-
- name: unnecessary-stmt # opinionated
200-
disabled: false
201-
- name: unreachable-code
202-
disabled: false
203-
severity: error
204-
- name: unused-parameter
205-
disabled: false
206-
- name: unused-receiver # too picky
207-
disabled: true
208-
- name: useless-break
209-
disabled: false
210-
- name: use-any # opinionated
211-
disabled: true
212-
- name: var-declaration # too picky
213-
disabled: false
214-
- name: var-naming # incompatible with this codebase
215-
disabled: true
216-
- name: waitgroup-by-value
217-
disabled: false
218-
severity: error
24+
# Legitimate exclusion - we don't need to thoroughly document internal packages
25+
- path: internal/
26+
linters:
27+
- revive
28+
text: package-comments
29+
30+
# We will make an effort to remove this exclusion
31+
- path: types/
32+
linters:
33+
- revive
34+
text: exported

ast/annotation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/cedar-policy/cedar-go/x/exp/ast"
66
)
77

8+
// Annotations allows access to Cedar annotations on a policy
89
type Annotations ast.Annotations
910

1011
func (a *Annotations) unwrap() *ast.Annotations {
@@ -41,7 +42,8 @@ func (a *Annotations) Forbid() *Policy {
4142
return wrapPolicy(a.unwrap().Forbid())
4243
}
4344

44-
// If a previous annotation exists with the same key, this builder will replace it.
45+
// Annotate adds an annotation to a Policy. If a previous annotation exists with the same key, this builder will
46+
// replace it.
4547
func (p *Policy) Annotate(key types.Ident, value types.String) *Policy {
4648
return wrapPolicy(p.unwrap().Annotate(key, value))
4749
}

0 commit comments

Comments
 (0)