From c8b8f0bd0d17b4ebc04607890944fb0e1b9f8cb0 Mon Sep 17 00:00:00 2001 From: Logan Date: Thu, 24 Sep 2020 00:18:21 -0600 Subject: [PATCH] add github actions workflows + pre-commit hooks --- .github/workflows/check.yml | 27 +++++++++++++++++++++++++++ .github/workflows/clippy.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/fmt.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/tests.yml | 27 +++++++++++++++++++++++++++ .pre-commit-config.yaml | 17 +++++++++++++++++ .vscode/settings.json | 3 +++ README.md | 20 ++++++++++---------- src/fuzz.rs | 6 +----- src/process.rs | 6 +++--- 9 files changed, 146 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/clippy.yml create mode 100644 .github/workflows/fmt.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .vscode/settings.json diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..0a8b4b9 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,27 @@ +name: Cargo Check +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + check: + name: Check + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.0.0 + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - uses: actions-rs/cargo@v1 + with: + command: check diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..2cf9081 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,29 @@ +name: Clippy +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + clippy: + name: Clippy + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.0.0 + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/.github/workflows/fmt.yml b/.github/workflows/fmt.yml new file mode 100644 index 0000000..8cbd02d --- /dev/null +++ b/.github/workflows/fmt.yml @@ -0,0 +1,29 @@ +name: Rust Format +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + fmt: + name: Rustfmt + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.0.0 + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..ae6d8e9 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,27 @@ +name: Cargo Test +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + test: + name: Test Suite + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.0.0 + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - uses: actions-rs/cargo@v1 + with: + command: test diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d2aadbf --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-added-large-files + - id: check-merge-conflict + - id: detect-private-key + - id: no-commit-to-branch + - repo: https://github.com/doublify/pre-commit-rust + rev: master + hooks: + - id: fmt + - id: cargo-check + - id: clippy diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7023e7d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/run/current-system/sw/bin/python" +} diff --git a/README.md b/README.md index b1b8d2d..99cdfab 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Fuzzy string matching like a boss. It uses Levenshtein Distance to calculate the **Note: This project was originally named `fuzzyrusty`. Someone else cloned and published it to crates.io https://crates.io/crates/fuzzyrusty. _We do not control that crate._ This is why we have changed the name.** -## Installation +## Installation `fuzzywuzzy` is currently available through GitHub or crates.io. For the latest stable releas, add this to your `Cargo.toml`: @@ -34,21 +34,21 @@ assert_eq!(fuzz::partial_ratio("this is a test", "this is a test!"), 100); ``` ### Token Sort Ratio ```rust -assert_eq!(fuzz::ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear"), 91); +assert_eq!(fuzz::ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear"), 91); assert_eq!(fuzz::token_sort_ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear", true, true), 100); ``` ### Token Set Ratio ```rust -assert_eq!(fuzz::ratio("fuzzy was a bear", "fuzzy fuzzy was a bear"), 84); +assert_eq!(fuzz::ratio("fuzzy was a bear", "fuzzy fuzzy was a bear"), 84); assert_eq!(fuzz::token_set_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear", true, true), 100); ``` ### Process ```rust -assert_eq!(process::extract_one( - "cowboys", - &["Atlanta Falcons", "Dallas Cowboys", "New York Jets"], - &utils::full_process, - &fuzz::wratio, - 0, +assert_eq!(process::extract_one( + "cowboys", + &["Atlanta Falcons", "Dallas Cowboys", "New York Jets"], + &utils::full_process, + &fuzz::wratio, + 0, ), Some(("Dallas Cowboys".to_string(), 90))); -``` \ No newline at end of file +``` diff --git a/src/fuzz.rs b/src/fuzz.rs index 2d6d836..5d0356e 100644 --- a/src/fuzz.rs +++ b/src/fuzz.rs @@ -29,11 +29,7 @@ pub fn partial_ratio(s1: &str, s2: &str) -> u8 { let blocks = utils::get_matching_blocks(&shorter, &longer); let mut max: u8 = 0; for (i, j, _) in blocks { - let long_start = if j > i { - j - i - } else { - 0 - }; + let long_start = if j > i { j - i } else { 0 }; let long_end = std::cmp::min(long_start + shorter.len(), longer.len()); let long_substr = &longer[long_start..long_end]; let r = ratio(&shorter, long_substr); diff --git a/src/process.rs b/src/process.rs index fd5ec58..980c053 100644 --- a/src/process.rs +++ b/src/process.rs @@ -15,7 +15,7 @@ where I: IntoIterator, T: AsRef, P: Fn(&str, bool) -> String, - S: Fn(&str, &str, bool, bool) -> u8 + S: Fn(&str, &str, bool, bool) -> u8, { let processed_query: String = processor(query, false); if processed_query.is_empty() { @@ -54,7 +54,7 @@ where I: IntoIterator, T: AsRef, P: Fn(&str, bool) -> String, - S: Fn(&str, &str, bool, bool) -> u8 + S: Fn(&str, &str, bool, bool) -> u8, { let best = extract_without_order(query, choices, processor, scorer, score_cutoff); if best.is_empty() { @@ -133,4 +133,4 @@ mod tests { assert_eq!(best.as_str(), get_baseball_strings()[0]) } } -} \ No newline at end of file +}