diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6029cd9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + # - id: no-commit-to-branch + # args: [--branch, master, --branch, main, --pattern, release/.*] + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: mixed-line-ending + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-executables-have-shebangs + + - repo: local + hooks: + - id: clippy + name: clippy + language: system + entry: cargo clippy + pass_filenames: false + always_run: true + + - id: cargo-fmt + name: cargo fmt + language: system + entry: cargo fmt + pass_filenames: false + always_run: true + + - id: check-todos # [NOGREP] + name: check-todos # [NOGREP] + language: system + entry: sh -c "! grep --color=always --binary-files=without-match --dereference-recursive --exclude-dir='notes' --exclude-dir='node_modules' --exclude-dir='.git' --exclude='.pre-commit-config.yaml' --exclude-dir='venv' 'TODO'" # [NOGREP] + pass_filenames: false + always_run: true diff --git a/src/main.rs b/src/main.rs index cd839f7..67f0482 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ use axum::{ }; use futures::StreamExt; use notify::{Config, EventKind, RecommendedWatcher, RecursiveMode, Watcher}; -use pulldown_cmark; use pulldown_cmark::{CodeBlockKind, Event, Options, Tag, html}; use std::convert::Infallible; use std::net::{SocketAddr, ToSocketAddrs}; @@ -114,7 +113,7 @@ fn resolve_addr(host: &str, port: u16) -> io::Result { } async fn root(State(state): State) -> Result, StatusCode> { - render_directory_index(&PathBuf::from(state.root), "").await + render_directory_index(&state.root, "").await } async fn sse_handler( @@ -342,11 +341,11 @@ async fn run_file_watcher(state: AppState) { let tx_fs_clone = tx_fs.clone(); let mut watcher = RecommendedWatcher::new( move |res: Result| { - if let Ok(event) = res { - if matches!(event.kind, EventKind::Modify(_)) { - for path in event.paths { - let _ = tx_fs_clone.blocking_send(path); - } + if let Ok(event) = res + && matches!(event.kind, EventKind::Modify(_)) + { + for path in event.paths { + let _ = tx_fs_clone.blocking_send(path); } } },