Skip to content

Commit bad12cd

Browse files
committed
fixed warnings
1 parent 582c6ea commit bad12cd

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

crates/cli/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,21 @@ struct SarifTool { driver: SarifDriver }
152152
struct SarifDriver { name: String, version: String }
153153
#[derive(serde::Serialize)]
154154
struct SarifResult {
155-
ruleId: String,
155+
rule_id: String,
156156
level: String,
157157
message: SarifMessage,
158158
locations: Vec<SarifLocation>,
159159
}
160160
#[derive(serde::Serialize)]
161161
struct SarifMessage { text: String }
162162
#[derive(serde::Serialize)]
163-
struct SarifLocation { physicalLocation: SarifPhysicalLocation }
163+
struct SarifLocation { physical_location: SarifPhysicalLocation }
164164
#[derive(serde::Serialize)]
165-
struct SarifPhysicalLocation { artifactLocation: SarifArtifactLocation, region: SarifRegion }
165+
struct SarifPhysicalLocation { artifact_location: SarifArtifactLocation, region: SarifRegion }
166166
#[derive(serde::Serialize)]
167167
struct SarifArtifactLocation { uri: String }
168168
#[derive(serde::Serialize)]
169-
struct SarifRegion { startLine: usize, startColumn: usize }
169+
struct SarifRegion { start_line: usize, start_column: usize }
170170

171171
fn to_sarif(findings: &[Finding]) -> SarifLog {
172172
SarifLog {
@@ -175,12 +175,12 @@ fn to_sarif(findings: &[Finding]) -> SarifLog {
175175
runs: vec![SarifRun {
176176
tool: SarifTool { driver: SarifDriver { name: "cryptofind".into(), version: env!("CARGO_PKG_VERSION").into() } },
177177
results: findings.iter().map(|f| SarifResult {
178-
ruleId: f.detector_id.clone(),
178+
rule_id: f.detector_id.clone(),
179179
level: "note".into(),
180180
message: SarifMessage { text: format!("{} in {:?}", f.library, f.language) },
181-
locations: vec![SarifLocation { physicalLocation: SarifPhysicalLocation {
182-
artifactLocation: SarifArtifactLocation { uri: f.file.display().to_string() },
183-
region: SarifRegion { startLine: f.span.line, startColumn: f.span.column },
181+
locations: vec![SarifLocation { physical_location: SarifPhysicalLocation {
182+
artifact_location: SarifArtifactLocation { uri: f.file.display().to_string() },
183+
region: SarifRegion { start_line: f.span.line, start_column: f.span.column },
184184
}}],
185185
}).collect(),
186186
}],

crates/scanner-core/src/lib.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use anyhow::{anyhow, Context, Result};
2-
use aho_corasick::{AhoCorasick, AhoCorasickBuilder};
2+
use aho_corasick::AhoCorasickBuilder;
33
use crossbeam_channel::{bounded, Receiver, Sender};
44
use ignore::WalkBuilder;
5-
use once_cell::sync::OnceCell;
65
use rayon::prelude::*;
76
use regex::Regex;
87
use serde::{Deserialize, Serialize};
9-
use std::collections::{BTreeMap, BTreeSet};
8+
use std::collections::BTreeSet;
109
use std::fs;
11-
use std::io::{self, Read};
10+
use std::io::Read;
1211
use std::path::{Path, PathBuf};
1312
use std::sync::Arc;
14-
use std::time::{Duration, SystemTime};
1513

1614
// ---------------- Types ----------------
1715

@@ -92,13 +90,12 @@ pub trait Detector: Send + Sync {
9290
pub struct Emitter {
9391
tx: Sender<Finding>,
9492
rx: Receiver<Finding>,
95-
buffer: Vec<Finding>,
9693
}
9794

9895
impl Emitter {
9996
pub fn new(bound: usize) -> Self {
10097
let (tx, rx) = bounded(bound);
101-
Self { tx, rx, buffer: Vec::new() }
98+
Self { tx, rx }
10299
}
103100

104101
pub fn send(&mut self, finding: Finding) -> Result<()> {
@@ -497,7 +494,7 @@ impl<'a> Scanner<'a> {
497494
for root in roots {
498495
let mut builder = WalkBuilder::new(root);
499496
builder.hidden(false).git_ignore(true).git_exclude(true).ignore(true);
500-
for ig in &self.config.include_globs { builder.add("."); builder.filter_entry(|_| true); }
497+
for _ig in &self.config.include_globs { builder.add("."); builder.filter_entry(|_| true); }
501498
// exclude_globs are handled later using globset for simplicity
502499
for result in builder.build() {
503500
if let Ok(entry) = result {
@@ -545,7 +542,7 @@ impl<'a> Scanner<'a> {
545542
if let Ok(bytes) = Self::load_file(path) {
546543
let unit = ScanUnit { path: path.clone(), lang, bytes: bytes.clone() };
547544
let stripped = strip_comments(lang, &bytes);
548-
let mut em = Emitter { tx: tx.clone(), rx: rx.clone(), buffer: Vec::new() };
545+
let mut em = Emitter { tx: tx.clone(), rx: rx.clone() };
549546
for det in &self.detectors {
550547
if !det.languages().contains(&lang) { continue; }
551548
if !prefilter_hit(det, &stripped) { continue; }
@@ -594,25 +591,13 @@ pub struct PatternDetector {
594591
id: &'static str,
595592
languages: &'static [Language],
596593
registry: Arc<PatternRegistry>,
597-
ac: OnceCell<AhoCorasick>,
598594
}
599595

600596
impl PatternDetector {
601597
pub fn new(id: &'static str, languages: &'static [Language], registry: Arc<PatternRegistry>) -> Self {
602-
Self { id, languages, registry, ac: OnceCell::new() }
598+
Self { id, languages, registry }
603599
}
604600

605-
fn build_ac(&self) -> AhoCorasick {
606-
// Merge all substrings for relevant libs
607-
let mut subs = BTreeSet::new();
608-
for lib in self.registry.for_language(self.languages[0]) { // languages are same category per detector
609-
for s in &lib.prefilter_substrings { subs.insert(s.clone()); }
610-
}
611-
AhoCorasickBuilder::new()
612-
.ascii_case_insensitive(true)
613-
.build(subs.into_iter().collect::<Vec<_>>())
614-
.expect("failed to build aho-corasick for detector")
615-
}
616601
}
617602

618603
impl Detector for PatternDetector {

0 commit comments

Comments
 (0)