Skip to content

Commit

Permalink
chore: add linter & formatter settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nokazn committed Jan 26, 2024
1 parent 6b46dac commit 02748b5
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 16 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/static-check.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tab_spaces = 2
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
}
17 changes: 10 additions & 7 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
cargo
rustc
rustfmt
pre-commit
rustPackages.clippy
pre-commit
nixpkgs-fmt
just
];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
Expand Down
36 changes: 36 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 10 additions & 7 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("Hello, world!");
println!("Hello, world!");
}

0 comments on commit 02748b5

Please sign in to comment.