Skip to content

Commit

Permalink
lint: Use golangci-lint for license check (#1157)
Browse files Browse the repository at this point in the history
Instead of a hand-written license header check,
use the goheader linter included in golangci-lint.

Also deletes a stale exclude-rules in golangci.yml
that was copied over from Zap.

---------

Co-authored-by: Jacob Oaks <[email protected]>
  • Loading branch information
abhinav and JacobOaks committed Feb 12, 2024
1 parent 4c7a22b commit ecc5bc7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
37 changes: 31 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ linters:
- revive
- errorlint

# License header check:
- goheader

linters-settings:
govet:
# These govet checks are disabled by default, but they're useful.
Expand All @@ -30,6 +33,34 @@ linters-settings:
- sortslice
- unusedwrite

goheader:
values:
const:
COMPANY: 'Uber Technologies, Inc.'
regexp:
YEAR_RANGE: '\d{4}(-\d{4})?'
template: |-
Copyright (c) {{ YEAR_RANGE }} {{ COMPANY }}
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
issues:
# Print all issues reported by all linters.
max-issues-per-linter: 0
Expand Down Expand Up @@ -62,9 +93,3 @@ issues:
- linters: [revive]
path: '_test\.go$'
text: 'should not use dot imports'

# Ignore logger.Sync() errcheck failures in example_test.go
# since those are intended to be uncomplicated examples.
- linters: [errcheck]
path: example_test.go
text: 'Error return value of `logger.Sync` is not checked'
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build:
go build ./...

.PHONY: lint
lint: golangci-lint tidy-lint license-lint fx-lint docs-lint
lint: golangci-lint tidy-lint fx-lint docs-lint

.PHONY: test
test:
Expand Down Expand Up @@ -58,10 +58,6 @@ tidy-lint:
go mod tidy && \
git diff --exit-code -- go.mod go.sum) &&) true

.PHONY: license-lint
license-lint:
./checklicense.sh

.PHONY: fx-lint
fx-lint: $(FXLINT)
@$(FXLINT) ./...
Expand All @@ -76,4 +72,3 @@ $(MDOX): tools/go.mod

$(FXLINT): tools/cmd/fxlint/main.go
cd tools && go install go.uber.org/fx/tools/cmd/fxlint

17 changes: 0 additions & 17 deletions checklicense.sh

This file was deleted.

2 changes: 1 addition & 1 deletion signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPSignalE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Expand Down
2 changes: 1 addition & 1 deletion signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPSignalE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Expand Down

0 comments on commit ecc5bc7

Please sign in to comment.