Skip to main content

fallow_cli/report/ci/
fingerprint.rs

1/// Compute a deterministic fingerprint hash from key fields.
2#[must_use]
3pub fn fingerprint_hash(parts: &[&str]) -> String {
4    fallow_output::codeclimate_fingerprint_hash(parts)
5}
6
7#[cfg(test)]
8#[must_use]
9pub fn finding_fingerprint(rule_id: &str, path: &str, snippet: &str) -> String {
10    fallow_output::sarif_finding_fingerprint(rule_id, path, snippet)
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    #[test]
18    fn fingerprint_is_stable_for_whitespace_only_snippet_changes() {
19        let a = finding_fingerprint(
20            "fallow/unused-export",
21            "src/a.ts",
22            "  export const x = 1;  ",
23        );
24        let b = finding_fingerprint(
25            "fallow/unused-export",
26            "src/a.ts",
27            "\nexport const x = 1;\n",
28        );
29        assert_eq!(a, b);
30    }
31
32    #[test]
33    fn fingerprint_parts_are_separated() {
34        assert_ne!(
35            fingerprint_hash(&["ab", "c"]),
36            fingerprint_hash(&["a", "bc"])
37        );
38    }
39}