Skip to content

Setup lint and format of Go, Proto and yaml/markdown #223

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

Merged
merged 41 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6b3114a
Run prettier
kradalby Nov 13, 2021
edfcdc4
Update lint ci file with prettier and proto
kradalby Nov 13, 2021
03b7ec6
Go format with shorter lines
kradalby Nov 13, 2021
dae34ca
Proto format
kradalby Nov 13, 2021
2634215
golangci-lint --fix
kradalby Nov 13, 2021
3ddd996
Add format make entry
kradalby Nov 13, 2021
148437f
Setup more linters and goals for golangci
kradalby Nov 13, 2021
24e0c94
Align with update golangci-lint
kradalby Nov 13, 2021
95b9f03
update buf setup
kradalby Nov 13, 2021
fa0922d
define proto dir for buf
kradalby Nov 13, 2021
b653572
Make format shuld format, not lint
kradalby Nov 13, 2021
806f0d3
Format lint
kradalby Nov 13, 2021
f94b0b5
Remove lint install, update go
kradalby Nov 13, 2021
e8726b1
Add readme note about codestyle
kradalby Nov 14, 2021
f3da299
Format readme
kradalby Nov 14, 2021
052883a
Fix merge conflict
kradalby Nov 14, 2021
1969802
Fix golanglint
kradalby Nov 14, 2021
d0ef850
Add and fix noctx linter
kradalby Nov 14, 2021
89eb13c
Add and fix nlreturn (new line return)
kradalby Nov 14, 2021
4ace54c
Move wsl, might not be feasible
kradalby Nov 14, 2021
668e958
Add and fix unconvert
kradalby Nov 14, 2021
0315f55
Add and fix nilnil
kradalby Nov 14, 2021
19cd7a4
Add and fix exhaustive
kradalby Nov 14, 2021
c9c16c7
Remove unused params or returns
kradalby Nov 14, 2021
9390348
Add and fix goconst
kradalby Nov 14, 2021
796072a
Add and fix ifshort
kradalby Nov 14, 2021
85f28a3
Remove all instances of undefined numbers (gonmd)
kradalby Nov 14, 2021
ba084b9
Lint fix integration tests
kradalby Nov 14, 2021
53ed749
Start work on making gocritic pass
kradalby Nov 14, 2021
471c0b4
Initial work eliminating one/two letter variables
kradalby Nov 14, 2021
333be80
Fix rest of var name in main code
kradalby Nov 15, 2021
8ae682b
Fix var name length in tests
kradalby Nov 15, 2021
78cfba0
Add exceptions to var name length
kradalby Nov 15, 2021
2dde124
Fix formatting
kradalby Nov 15, 2021
0c45f8d
Add and fix errorlint
kradalby Nov 15, 2021
0c005a6
Add and fix errname
kradalby Nov 15, 2021
715542a
Add and fix stylecheck (golint replacement)
kradalby Nov 15, 2021
c4d4c9c
Add and fix gosec
kradalby Nov 15, 2021
db8be91
Add and fix forbidigo
kradalby Nov 15, 2021
25b790d
Add and fix forcetypeassert
kradalby Nov 15, 2021
d673938
Get rid of dynamic errors
kradalby Nov 15, 2021
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
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "1.16.3"
go-version: "1.17.3"

- name: Install dependencies
run: |
go version
go install golang.org/x/lint/golint@latest
sudo apt update
sudo apt install -y make

Expand Down
37 changes: 27 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
---
name: CI

on: [push, pull_request]

jobs:
# The "build" workflow
lint:
# The type of runner that the job will run on
golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Steps represent a sequence of tasks that will be executed as part of the job
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest

prettier-lint:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Install and run golangci-lint as a separate step, it's much faster this
# way because this action has caching. It'll get run again in `make lint`
# below, but it's still much faster in the end than installing
# golangci-lint manually in the `Run lint` step.
- uses: golangci/golangci-lint-action@v2
- name: Prettify code
uses: creyD/[email protected]
with:
prettier_options: >-
--check **/*.{ts,js,md,yaml,yml,sass,css,scss,html}
only_changed: false
dry: true

proto-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bufbuild/[email protected]
- uses: bufbuild/buf-lint-action@v1
with:
input: "proto"
48 changes: 47 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
---
run:
timeout: 5m
timeout: 10m

issues:
skip-dirs:
- gen
linters:
enable-all: true
disable:
- exhaustivestruct
- revive
- lll
- interfacer
- scopelint
- maligned
- golint
- gofmt
- gochecknoglobals
- gochecknoinits
- gocognit
- funlen
- exhaustivestruct
- tagliatelle
- godox
- ireturn

# In progress
- gocritic

# We should strive to enable these:
- wrapcheck
- dupl
- makezero

# We might want to enable this, but it might be a lot of work
- cyclop
- nestif
- wsl # might be incompatible with gofumpt
- testpackage
- paralleltest

linters-settings:
varnamelen:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:( this will hurt

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed The part that hurts

ignore-type-assert-ok: true
ignore-map-index-ok: true
ignore-names:
- err
- db
- id
- ip
- ok
- c
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Calculate version
version = $(shell ./scripts/version-at-commit.sh)

rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))

# GO_SOURCES = $(wildcard *.go)
# PROTO_SOURCES = $(wildcard **/*.proto)
GO_SOURCES = $(call rwildcard,,*.go)
PROTO_SOURCES = $(call rwildcard,,*.proto)


build:
go build -ldflags "-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$(version)" cmd/headscale/headscale.go

Expand All @@ -19,7 +27,12 @@ coverprofile_html:
go tool cover -html=coverage.out

lint:
golangci-lint run --fix
golangci-lint run --fix --timeout 10m

fmt:
prettier --write '**/**.{ts,js,md,yaml,yml,sass,css,scss,html}'
golines --max-len=88 --base-formatter=gofumpt -w $(GO_SOURCES)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 88?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is based on python black (and Raymond Hettinger), which some might hate.

The idea is to make the code more naturally fit on narrow screens, so you can have multiple files open without bad editor wrapping.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll adda note in the reader about code style

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

clang-format -style="{BasedOnStyle: Google, IndentWidth: 4, AlignConsecutiveDeclarations: true, AlignConsecutiveAssignments: true, ColumnLimit: 0}" -i $(PROTO_SOURCES)

proto-lint:
cd proto/ && buf lint
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Suggestions/PRs welcomed!

Please have a look at the documentation under [`docs/`](docs/).


## Disclaimer

1. We have nothing to do with Tailscale, or Tailscale Inc.
Expand All @@ -64,13 +63,30 @@ Please have a look at the documentation under [`docs/`](docs/).

To contribute to Headscale you would need the lastest version of [Go](https://golang.org) and [Buf](https://buf.build)(Protobuf generator).

### Code style

To ensure we have some consistency with a growing number of contributes, this project has adopted linting and style/formatting rules:

The **Go** code is linted with [`golangci-lint`](https://golangci-lint.run) and
formatted with [`golines`](https://github.com/segmentio/golines) (width 88) and
[`gofumpt`](https://github.com/mvdan/gofumpt).
Please configure your editor to run the tools while developing and make sure to
run `make lint` and `make fmt` before committing any code.

The **Proto** code is linted with [`buf`](https://docs.buf.build/lint/overview) and
formatted with [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html).

The **rest** (markdown, yaml, etc) is formatted with [`prettier`](https://prettier.io).

Check out the `.golangci.yaml` and `Makefile` to see the specific configuration.

### Install development tools

- Go
- Buf
- Protobuf tools:

```shell
```shell
make install-protobuf-plugins
```

Expand All @@ -81,6 +97,7 @@ Some parts of the project requires the generation of Go code from Protobuf (if c
```shell
make generate
```

**Note**: Please check in changes from `gen/` in a separate commit to make it easier to review.

To run the tests:
Expand Down Expand Up @@ -261,5 +278,3 @@ make build
</td>
</tr>
</table>


Loading