From 02748b50bd2ac353468eb52a3dd415861b0d1e24 Mon Sep 17 00:00:00 2001 From: nokazn <41154684+nokazn@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:49:26 +0900 Subject: [PATCH] chore: add linter & formatter settings --- .github/workflows/static-check.yml | 20 +++++++++++++++++ .rustfmt.toml | 1 + .vscode/settings.json | 14 ++++++++++++ default.nix | 17 ++++++++------ dprint.json | 16 +++++++++++++ flake.nix | 4 +++- justfile | 36 ++++++++++++++++++++++++++++++ shell.nix | 17 ++++++++------ src/main.rs | 2 +- 9 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/static-check.yml create mode 100644 .rustfmt.toml create mode 100644 .vscode/settings.json create mode 100644 dprint.json create mode 100644 justfile diff --git a/.github/workflows/static-check.yml b/.github/workflows/static-check.yml new file mode 100644 index 0000000..cf4581b --- /dev/null +++ b/.github/workflows/static-check.yml @@ -0,0 +1,20 @@ +name: static-check + +on: + push: + branches: + - main + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: dtolnay/rust-toolchain@stable + - name: Check formatting + run: cargo fmt --check + - name: Lint + run: cargo clippy + - name: Run tests + run: cargo test --locked --frozen --all-features diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..b196eaa --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +tab_spaces = 2 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..81399c4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer", + "editor.formatOnSave": true + }, + "[nix]": { + "editor.defaultFormatter": "B4dM4n.nixpkgs-fmt", + "editor.formatOnSave": true + }, + "[json][jsonc][toml][markdown]": { + "editor.defaultFormatter": "dprint.dprint", + "editor.formatOnSave": true + } +} diff --git a/default.nix b/default.nix index 39bacff..89308a3 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,10 @@ -(import ( - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; - sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } -) { - src = ./.; -}).defaultNix +(import + ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; + } + ) + { + src = ./.; + }).defaultNix diff --git a/dprint.json b/dprint.json new file mode 100644 index 0000000..e1afca3 --- /dev/null +++ b/dprint.json @@ -0,0 +1,16 @@ +{ + "json": { + }, + "markdown": { + }, + "toml": { + }, + "excludes": [ + "**/*-lock.json" + ], + "plugins": [ + "https://plugins.dprint.dev/json-0.19.1.wasm", + "https://plugins.dprint.dev/markdown-0.16.3.wasm", + "https://plugins.dprint.dev/toml-0.5.4.wasm" + ] +} diff --git a/flake.nix b/flake.nix index 0de18db..aa6ba6c 100644 --- a/flake.nix +++ b/flake.nix @@ -18,8 +18,10 @@ cargo rustc rustfmt - pre-commit rustPackages.clippy + pre-commit + nixpkgs-fmt + just ]; RUST_SRC_PATH = rustPlatform.rustLibSrc; }; diff --git a/justfile b/justfile new file mode 100644 index 0000000..5ad7442 --- /dev/null +++ b/justfile @@ -0,0 +1,36 @@ +default: + @just --list + +check: + just fmt --check + just lint + just test + +fmt check="": + if [[ "{{check}}" == "--check" ]]; then \ + just fmt-rust --check; \ + just fmt-nix --check; \ + just fmt-dprint --diff; \ + else \ + just fmt-rust; \ + just fmt-nix; \ + just fmt-dprint; \ + fi + +fmt-rust *flags: + cargo fmt {{flags}} + +fmt-nix *flags: + find . -type f -iname '*.nix' | xargs nixpkgs-fmt {{flags}} + +fmt-dprint *flags: + dprint fmt {{flags}} + +lint: + cargo clippy + +test: + cargo test --locked --frozen --all-features -- --nocapture + +build: + cargo build diff --git a/shell.nix b/shell.nix index 77db547..47458ad 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,10 @@ -(import ( - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; - sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } -) { - src = ./.; -}).shellNix +(import + ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; + } + ) + { + src = ./.; + }).shellNix diff --git a/src/main.rs b/src/main.rs index e7a11a9..80a1832 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - println!("Hello, world!"); + println!("Hello, world!"); }