From bdc7b2dbc8b4201d6399aef2516356cd890ee7f6 Mon Sep 17 00:00:00 2001 From: Garrett Ladley <92384606+garrettladley@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:06:21 -0400 Subject: [PATCH] feat: use air (#416) --- .gitignore | 1 + CONTRIBUTING.md | 45 +++++++++-------------------------------- backend/.air.toml | 43 +++++++++++++++++++++++++++++++++++++++ cli/commands/backend.go | 8 ++++---- cli/commands/lint.go | 2 +- 5 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 backend/.air.toml diff --git a/.gitignore b/.gitignore index c3f812701..d294615a7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules .vscode .trunk .env.dev +tmp/ \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29c91195d..f413a4612 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,13 +11,19 @@ - [Node.js](https://nodejs.org/en/) - [Yarn](https://yarnpkg.com/) - [Go](https://golang.org/) - > Do not install through brew, use the official website + - Do not install through brew, use the official website - [Docker](https://www.docker.com/) - [PostgreSQL](https://www.postgresql.org/) - Install through brew: `brew install postgresql@15` - It requires you to add all the exports to path so read the end of the installation carefully! - [Trunk](https://marketplace.visualstudio.com/items?itemName=Trunk.io) (Recommended!) - Visual Studio Code extension for linting/formatting +- [Air](https://github.com/cosmtrek/air?tab=readme-ov-file#installation) + - Live reload for Go apps +- [gofumpt](https://github.com/mvdan/gofumpt) + - A stricter gofmt +- [golangci-lint](https://golangci-lint.run/welcome/install/) + - A Go linters aggregator # Setup @@ -121,45 +127,14 @@ ```console go run main.go // run server go test ./... // run tests - go fmt ./... // format code - go vet ./... // lint code + gofumpt -l -w . // format code + golangci-lint run --fix // lint code ``` ### SAC CLI To install use `./install.sh` and then run `sac-cli` to see all commands. - ```console - NAME: - sac-cli - CLI for SAC - - USAGE: - sac-cli [global options] command [command options] - - COMMANDS: - swagger, swag Updates the swagger documentation - test, t Runs tests - help, h Shows a list of commands or help for one command - CI: - format, f Runs formatting tools - lint, l Runs linting tools - * can use --fix to fix linting errors for frontend - Database Operations: - clean, c Remove databases used for testing - migrate, m Migrate the database, creating tables and relationships - reset, r Resets the database, dropping all tables, clearing data, and re-running migrations - * can use --data to just reset data and not drop tables - insert, i Inserts mock data into the database - drop, d Drop data with a migration or drops the entire database - * can use --data to just drop data and not drop tables - - Development: - be Run the backend - fe Run the frontend - - GLOBAL OPTIONS: - --help, -h show help - ``` # Git Flow 1. **Create a new branch** @@ -179,8 +154,6 @@ - We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages. (READ!) - - 3. **Push changes to GitHub** ```console diff --git a/backend/.air.toml b/backend/.air.toml new file mode 100644 index 000000000..8be2456af --- /dev/null +++ b/backend/.air.toml @@ -0,0 +1,43 @@ +root = "." +tmp_dir = "tmp" + +[build] +args_bin = [] +bin = "./tmp/main" +cmd = "go build -o ./tmp/main main.go" +delay = 0 +exclude_dir = ["tmp"] +exclude_file = [] +exclude_regex = ["_test.go"] +exclude_unchanged = false +follow_symlink = false +full_bin = "" +include_dir = ["src"] +include_ext = ["go"] +include_file = [] +kill_delay = "0s" +log = "build-errors.log" +poll = false +poll_interval = 0 +rerun = false +rerun_delay = 500 +send_interrupt = false +stop_on_error = false + +[color] +app = "" +build = "yellow" +main = "magenta" +runner = "green" +watcher = "cyan" + +[log] +main_only = false +time = false + +[misc] +clean_on_exit = true + +[screen] +clear_on_rebuild = false +keep_scroll = true diff --git a/cli/commands/backend.go b/cli/commands/backend.go index 38b736617..ed372ea76 100644 --- a/cli/commands/backend.go +++ b/cli/commands/backend.go @@ -11,9 +11,9 @@ import ( func BackendCommand() *cli.Command { command := &cli.Command{ - Name: "backend", - Usage: "Starts the backend server", - Aliases: []string{"be"}, + Name: "be", + Usage: "Run the backend", + Category: "Development", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "use-dev-dot-env", @@ -35,7 +35,7 @@ func BackendCommand() *cli.Command { } func RunBackend() error { - cmd := exec.Command("go", "run", "main.go") + cmd := exec.Command("air") cmd.Dir = BACKEND_SRC_DIR cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/cli/commands/lint.go b/cli/commands/lint.go index 69a894ceb..f2eaeee9c 100644 --- a/cli/commands/lint.go +++ b/cli/commands/lint.go @@ -89,7 +89,7 @@ func LintFrontend(target string, fix bool) error { func LintBackend() error { fmt.Println("Linting backend") - cmd := exec.Command("go", "vet", "./...") + cmd := exec.Command("golangci-lint", "run", "--fix") cmd.Dir = BACKEND_DIR err := cmd.Run()