Skip to content
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

Add linters and the formatter #17

Merged
merged 14 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
pull_request: null
push:
branches:
- master

jobs:
multiple_checks:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: 'stable'
- run: go version

- name: Lint
run: make lint

- name: Vet
run: go vet ./...

- name: Tidy
run: go mod tidy

- name: Fail if changes
run: git diff-index --exit-code HEAD
27 changes: 27 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
run:
tests: false
timeout: 10m

linters-settings:
revive:
rules:
- name: unused-parameter
severity: warning
disabled: true

gomoddirectives:
replace-allow-list:
- github.com/linode/linodego

govet:
disable:
- shadow
dupl:
threshold: 100

linters:
fast: false
zliang-akamai marked this conversation as resolved.
Show resolved Hide resolved
enable:
- gofumpt
- goimports
- gosec
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@ LINODE_DEBUG ?= 0
# The path to the pubkey to configure the E2E testing instance with.
TEST_PUBKEY ?= ~/.ssh/id_rsa.pub

SKIP_DOCKER ?= 0

GOLANGCILINT := golangci-lint
GOLANGCILINT_IMG := golangci/golangci-lint:latest
GOLANGCILINT_ARGS := run

# Whether to cleanup the Linode instance used in the testing
CLEANUP_TEST_LINODE_INSTANCE ?= false

lint:
ifeq ($(SKIP_DOCKER), 1)
$(GOLANGCILINT) $(GOLANGCILINT_ARGS)
else
docker run --rm -v $(shell pwd):/app -w /app $(GOLANGCILINT_IMG) $(GOLANGCILINT) $(GOLANGCILINT_ARGS)
endif

fmt:
gofumpt -w -l .

fix-lint: fmt
$(GOLANGCILINT) $(GOLANGCILINT_ARGS) --fix

# Installs dependencies required to run the remote E2E suite.
test-deps:
pip3 install --upgrade ansible -r https://raw.githubusercontent.com/linode/ansible_linode/main/requirements.txt
Expand Down
11 changes: 6 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/go-resty/resty/v2"
)

const APIHost = "169.254.169.254"
const APIProto = "http"
const APIVersion = "v1"
const (
APIHost = "169.254.169.254"
APIProto = "http"
APIVersion = "v1"
)

// Client represents an instance of a Linode Metadata Service client.
type Client struct {
Expand Down Expand Up @@ -79,7 +81,6 @@ func NewClient(ctx context.Context, opts ...ClientOption) (*Client, error) {
}

result.updateHostURL()

result.setUserAgent(userAgent)

if clientOpts.ManagedToken && clientOpts.StartingToken == "" {
Expand Down Expand Up @@ -137,7 +138,7 @@ func (c *Client) updateHostURL() {
}

// middlewareTokenRefresh handles automatically refreshing managed tokens.
func (c *Client) middlewareTokenRefresh(rc *resty.Client, r *resty.Request) error {
func (c *Client) middlewareTokenRefresh(_ *resty.Client, r *resty.Request) error {
// Don't run this middleware when generating tokens
if r.URL == "token" {
return nil
Expand Down
3 changes: 2 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package metadata

import (
"fmt"
"github.com/go-resty/resty/v2"
"net/http"
"strings"

"github.com/go-resty/resty/v2"
)

// APIError is the error-set returned by the Linode API when presented with an invalid request
Expand Down