Project: Lunar.dev (Orchestration & Management / API Gateway)
File: LINTING.md

This document describes different linters & formatters that are applied in this project and how to work with them in local development. All linters also run on our CI pipelines - see the dedicated for implementation. The Go code in this project is linted using the linters aggregator, which covers a wide range of linting issues. All the default linters are turned on, as well as a few additional ones. You may inspect the used and compare it to the and their description by `golangci-lint`. Thanks to , linting should work automatically in VSCode. The `--fix` flag will try to solve linting issues automatically, however please note that sometimes it will not be able to do so (e.g. bad variable naming). If you are experiencing issues or suspect linting is not working correctly, go to Code -> Settings/Preferences... -> Settings, and then search for "go lint tool". Then, Under Go: Lint Tool* make sure "golangci-lint" is chosen, Under Go: Lint On Save* make sure "package" is chosen. The linter should discover the configuration file automatically. In case you want to invoke `golangci-lint` from the command line, you may install it with ```bash brew install golangci-lint brew upgrade golangci-lint ``` Then, simply run `golangci-lint run ./...` in any of the Go modules in this project to obtain a full list of linting errors, if exist. You may pass the `--fix` flag here as well in order to fix issues automatically where possible. NOTE if you encounter an error such as ```bash ERRO Running error: 1 error occurred: can't run linter goanalysis_metalinter: goimports: can't extract issues from gofmt diff output... ``` Try to install/update `diffutils` with `brew install diffutils`, then try again (). It seems that `gofmt` (which run as part of `golangci-lint`) is against max line length formatting (see ). However, one of the linters, `lll`, is configured to report lines longer than 80 characters as a linting issue. (Adapted from ) In order to automatically break long lines in VSCode, do the following: Install `golines` () by running ```shell go install github.com/segmentio/golines@latest ``` Make sure your `PATH` includes your `GOPATH` - in your `.zshrc` (or compatible), add ```bash export GOPATH="$HOME/go" PATH="$GOPATH/bin:$PATH" ``` Install the `Run On Save` VSCode In VSCode, go to Code -> Settings/Preferences... -> Settings, and then search for "runonsave". Under Emeraldwalk: Runonsave, click the link to edit on `settings.json`, and modify it to include the following: ```json // rest of config... "emeraldwalk.runonsave": { "commands": [ { "match": "\\.go$", "cmd": "golines ${file} -w -m 80" } ] } // rest of config... ``` Restart VSCode; your files should now be automatically formatted according to the linter rules. We use in order to keep our Dockerfiles linted. It implements the from the official Docker documentation. Install Hadolint on your local machine: ```bash brew install hadolint ``` Run on our single current Dockerfile: ```bash hadolint Dockerfiles/amd64/Dockerfile ``` Install VSCode extension in order to see linting warnings & errors right within the IDE. You need to install Hadolint on your machine in order for this extension to work.