use std::{collections::BTreeMap, error::Error}; use aderyn_driver::core_ast::NodeID; use aderyn_driver::context::workspace_context::WorkspaceContext; use aderyn_driver::detection_modules::capture; use aderyn_driver::detector::{IssueDetector, IssueSeverity}; #[derive(Default)] pub struct {{detector_name_title_case}} { // Keys are source file name and line number found_instances: BTreeMap<(String, usize, String), NodeID>, } impl IssueDetector for {{detector_name_title_case}} { fn detect(&mut self, context: &WorkspaceContext) -> Result> { // Use the `context` to find nodes, then capture them as shown below // capture!(self, context, ast_node); Ok(!self.found_instances.is_empty()) } fn title(&self) -> String { String::from("Title for {{ detector_name_title_case }}") } fn description(&self) -> String { String::from("Description for {{ detector_name_title_case }}") } fn severity(&self) -> IssueSeverity { // Choose the appropriate severity IssueSeverity::NC } fn name(&self) -> String { "{{ detector_name_kebab_case }}".to_string() } fn instances(&self) -> BTreeMap<(String, usize, String), NodeID> { self.found_instances.clone() } } #[cfg(test)] mod {{detector_name_snake_case}}_tests { use crate::config_tests::tests_configuration; use super::{{detector_name_title_case}}; use aderyn_driver::context::workspace_context::WorkspaceContext; use aderyn_driver::detector::detector_test_helpers::load_contract; use aderyn_driver::detector::IssueDetector; fn test_{{detector_name_snake_case}}_for( _contract_file: String, context: WorkspaceContext, mut detector: impl IssueDetector, ) { // assert that the detector finds instances let found = detector.detect(&context).unwrap(); assert!(found); } #[test] fn test_{{detector_name_snake_case}}() { let detector = {{detector_name_title_case}}::default(); let contracts = tests_configuration().get_contracts_for(detector.name()); for contract_file in contracts { let detector = {{detector_name_title_case}}::default(); let context = load_contract(&contract_file); test_{{detector_name_snake_case}}_for(contract_file, context, detector); } } }