From ae3317ad45eb322a8dda7c8df3dada83d72e8a7b Mon Sep 17 00:00:00 2001 From: Josh McConnell Date: Wed, 2 Sep 2020 19:27:19 +0100 Subject: [PATCH] ISSUE-16 - Make PR requested changes Make the following changes: * Remove all "BEGIN: Public items" comments * Move DetectionStatus enum back to cargo-geiger and rename to CrateDetectionStatus Signed-off-by: Josh McConnell --- cargo-geiger/src/cli.rs | 4 ---- cargo-geiger/src/find.rs | 4 ---- cargo-geiger/src/format.rs | 10 ++++++---- cargo-geiger/src/format/parse.rs | 4 ---- cargo-geiger/src/format/print.rs | 15 +++++---------- cargo-geiger/src/format/table.rs | 28 ++++++++++++---------------- cargo-geiger/src/format/tree.rs | 4 ---- cargo-geiger/src/graph.rs | 4 ---- cargo-geiger/src/rs_file.rs | 4 ---- cargo-geiger/src/scan.rs | 4 ---- cargo-geiger/src/traversal.rs | 4 ---- geiger/src/lib.rs | 6 ------ 12 files changed, 23 insertions(+), 68 deletions(-) diff --git a/cargo-geiger/src/cli.rs b/cargo-geiger/src/cli.rs index 8f7eacee..3ba3ce88 100644 --- a/cargo-geiger/src/cli.rs +++ b/cargo-geiger/src/cli.rs @@ -22,8 +22,6 @@ use cargo_platform::Cfg; use std::path::PathBuf; use std::str::{self, FromStr}; -// ---------- BEGIN: Public items ---------- - /// TODO: Write proper documentation for this. /// This function seems to be looking up the active flags for conditional /// compilation (cargo_platform::Cfg instances). @@ -103,6 +101,4 @@ pub fn resolve<'a, 'cfg>( Ok((packages, resolve)) } -// ---------- END: Public items ---------- - // TODO: Make a wrapper type for canonical paths and hide all mutable access. diff --git a/cargo-geiger/src/find.rs b/cargo-geiger/src/find.rs index 3d2b6d21..b0748a04 100644 --- a/cargo-geiger/src/find.rs +++ b/cargo-geiger/src/find.rs @@ -14,8 +14,6 @@ use std::path::Path; use std::path::PathBuf; use walkdir::WalkDir; -// ---------- BEGIN: Public items ---------- - /// Provides a more terse and searchable name for the wrapped generic /// collection. pub struct GeigerContext { @@ -76,8 +74,6 @@ where GeigerContext { pack_id_to_metrics } } -// ---------- END: Public items ---------- - fn find_rs_files_in_dir(dir: &Path) -> impl Iterator { let walker = WalkDir::new(dir).into_iter(); walker.filter_map(|entry| { diff --git a/cargo-geiger/src/format.rs b/cargo-geiger/src/format.rs index 5ad14654..8e1ed398 100644 --- a/cargo-geiger/src/format.rs +++ b/cargo-geiger/src/format.rs @@ -13,8 +13,6 @@ use std::str::{self, FromStr}; use self::parse::{Parser, RawChunk}; -// ---------- BEGIN: Public items ---------- - #[derive(Clone, Copy, PartialEq)] pub enum Charset { Utf8, @@ -33,6 +31,12 @@ impl FromStr for Charset { } } +pub enum CrateDetectionStatus { + NoneDetectedForbidsUnsafe, + NoneDetectedAllowsUnsafe, + UnsafeDetected, +} + pub struct Display<'a> { pattern: &'a Pattern, package: &'a PackageId, @@ -150,8 +154,6 @@ pub fn get_kind_group_name(k: DepKind) -> Option<&'static str> { } } -// ---------- END: Public items ---------- - enum Chunk { Raw(String), Package, diff --git a/cargo-geiger/src/format/parse.rs b/cargo-geiger/src/format/parse.rs index 07f875a8..15f875ca 100644 --- a/cargo-geiger/src/format/parse.rs +++ b/cargo-geiger/src/format/parse.rs @@ -1,8 +1,6 @@ use std::iter; use std::str; -// ---------- BEGIN: Public items ---------- - pub enum RawChunk<'a> { Text(&'a str), Argument(&'a str), @@ -97,5 +95,3 @@ impl<'a> Iterator for Parser<'a> { } } } - -// ---------- END: Public items ---------- diff --git a/cargo-geiger/src/format/print.rs b/cargo-geiger/src/format/print.rs index c955c3cb..20b88632 100644 --- a/cargo-geiger/src/format/print.rs +++ b/cargo-geiger/src/format/print.rs @@ -1,13 +1,10 @@ -use crate::format::{Charset, Pattern}; +use crate::format::{Charset, CrateDetectionStatus, Pattern}; use cargo::core::shell::Verbosity; use colored::Colorize; -use geiger::DetectionStatus; use geiger::IncludeTests; use petgraph::EdgeDirection; -// ---------- BEGIN: Public items ---------- - #[derive(Clone, Copy)] pub enum Prefix { None, @@ -34,13 +31,11 @@ pub struct PrintConfig<'a> { pub fn colorize( s: String, - detection_status: &DetectionStatus, + detection_status: &CrateDetectionStatus, ) -> colored::ColoredString { match detection_status { - DetectionStatus::NoneDetectedForbidsUnsafe => s.green(), - DetectionStatus::NoneDetectedAllowsUnsafe => s.normal(), - DetectionStatus::UnsafeDetected => s.red().bold(), + CrateDetectionStatus::NoneDetectedForbidsUnsafe => s.green(), + CrateDetectionStatus::NoneDetectedAllowsUnsafe => s.normal(), + CrateDetectionStatus::UnsafeDetected => s.red().bold(), } } - -// ---------- END: Public items ---------- diff --git a/cargo-geiger/src/format/table.rs b/cargo-geiger/src/format/table.rs index 949cf43c..c6e8ec68 100644 --- a/cargo-geiger/src/format/table.rs +++ b/cargo-geiger/src/format/table.rs @@ -1,16 +1,14 @@ use crate::find::GeigerContext; use crate::format::print::{colorize, PrintConfig}; use crate::format::tree::TextTreeLine; -use crate::format::{get_kind_group_name, EmojiSymbols, SymbolKind}; +use crate::format::{CrateDetectionStatus, get_kind_group_name, EmojiSymbols, SymbolKind}; use crate::rs_file::PackageMetrics; use cargo::core::package::PackageSet; -use geiger::{Count, CounterBlock, DetectionStatus}; +use geiger::{Count, CounterBlock}; use std::collections::{HashMap, HashSet}; use std::path::PathBuf; -// ---------- BEGIN: Public items ---------- - // TODO: use a table library, or factor the tableness out in a smarter way. This // is probably easier now when the tree formatting is separated from the tree // traversal. @@ -88,15 +86,15 @@ pub fn print_text_tree_lines_as_table( match (unsafe_found, crate_forbids_unsafe) { (false, true) => { total_packs_none_detected_forbids_unsafe += 1; - DetectionStatus::NoneDetectedForbidsUnsafe + CrateDetectionStatus::NoneDetectedForbidsUnsafe } (false, false) => { total_packs_none_detected_allows_unsafe += 1; - DetectionStatus::NoneDetectedAllowsUnsafe + CrateDetectionStatus::NoneDetectedAllowsUnsafe } (true, _) => { total_packs_unsafe_detected += 1; - DetectionStatus::UnsafeDetected + CrateDetectionStatus::UnsafeDetected } } }); @@ -106,13 +104,13 @@ pub fn print_text_tree_lines_as_table( panic!("Expected to find package by id: {}", &id) }); let icon = match detection_status { - DetectionStatus::NoneDetectedForbidsUnsafe => { + CrateDetectionStatus::NoneDetectedForbidsUnsafe => { emoji_symbols.emoji(SymbolKind::Lock) } - DetectionStatus::NoneDetectedAllowsUnsafe => { + CrateDetectionStatus::NoneDetectedAllowsUnsafe => { emoji_symbols.emoji(SymbolKind::QuestionMark) } - DetectionStatus::UnsafeDetected => { + CrateDetectionStatus::UnsafeDetected => { emoji_symbols.emoji(SymbolKind::Rads) } }; @@ -165,9 +163,9 @@ pub fn print_text_tree_lines_as_table( total_packs_none_detected_allows_unsafe > 0, total_packs_unsafe_detected > 0, ) { - (_, _, true) => DetectionStatus::UnsafeDetected, - (true, false, false) => DetectionStatus::NoneDetectedForbidsUnsafe, - _ => DetectionStatus::NoneDetectedAllowsUnsafe, + (_, _, true) => CrateDetectionStatus::UnsafeDetected, + (true, false, false) => CrateDetectionStatus::NoneDetectedForbidsUnsafe, + _ => CrateDetectionStatus::NoneDetectedAllowsUnsafe, }; println!( "{}", @@ -177,12 +175,10 @@ pub fn print_text_tree_lines_as_table( warning_count } -// ---------- END: Public items ---------- - fn table_footer( used: CounterBlock, not_used: CounterBlock, - status: DetectionStatus, + status: CrateDetectionStatus, ) -> colored::ColoredString { let fmt = |used: &Count, not_used: &Count| { format!("{}/{}", used.unsafe_, used.unsafe_ + not_used.unsafe_) diff --git a/cargo-geiger/src/format/tree.rs b/cargo-geiger/src/format/tree.rs index e1df0e2f..2fcc7a16 100644 --- a/cargo-geiger/src/format/tree.rs +++ b/cargo-geiger/src/format/tree.rs @@ -3,8 +3,6 @@ use crate::format::Charset; use cargo::core::dependency::DepKind; use cargo::core::PackageId; -// ---------- BEGIN: Public items ---------- - /// A step towards decoupling some parts of the table-tree printing from the /// dependency graph traversal. pub enum TextTreeLine { @@ -29,8 +27,6 @@ pub fn get_tree_symbols(cs: Charset) -> TreeSymbols { } } -// ---------- END: Public items ---------- - const ASCII_TREE_SYMBOLS: TreeSymbols = TreeSymbols { down: "|", tee: "|", diff --git a/cargo-geiger/src/graph.rs b/cargo-geiger/src/graph.rs index 51023bdc..d3a1c92e 100644 --- a/cargo-geiger/src/graph.rs +++ b/cargo-geiger/src/graph.rs @@ -7,8 +7,6 @@ use petgraph::graph::NodeIndex; use std::collections::hash_map::Entry; use std::collections::HashMap; -// ---------- BEGIN: Public items ---------- - pub enum ExtraDeps { All, Build, @@ -85,8 +83,6 @@ pub fn build_graph<'a>( Ok(graph) } -// ---------- END: Public items ---------- - struct GraphConfiguration<'a> { target: Option<&'a str>, cfgs: Option<&'a [Cfg]>, diff --git a/cargo-geiger/src/rs_file.rs b/cargo-geiger/src/rs_file.rs index fe4f931f..463d46f8 100644 --- a/cargo-geiger/src/rs_file.rs +++ b/cargo-geiger/src/rs_file.rs @@ -14,8 +14,6 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, PoisonError}; use walkdir::{DirEntry, WalkDir}; -// ---------- BEGIN: Public items ---------- - /// Provides information needed to scan for crate root /// `#![forbid(unsafe_code)]`. /// The wrapped PathBufs are canonicalized. @@ -154,8 +152,6 @@ pub fn resolve_rs_file_deps( Ok(hs) } -// ---------- END: Public items ---------- - /// A cargo Executor to intercept all build tasks and store all ".rs" file /// paths for later scanning. /// diff --git a/cargo-geiger/src/scan.rs b/cargo-geiger/src/scan.rs index 7de8c4d0..16d25c62 100644 --- a/cargo-geiger/src/scan.rs +++ b/cargo-geiger/src/scan.rs @@ -24,8 +24,6 @@ use std::error::Error; use std::fmt; use std::path::PathBuf; -// ---------- BEGIN: Public items ---------- - pub enum ScanMode { // The default scan mode, scan every .rs file. Full, @@ -219,8 +217,6 @@ pub fn run_scan_mode_forbid_only( Ok(()) } -// ---------- END: Public items ---------- - #[derive(Debug)] struct FoundWarningsError { pub warning_count: u64, diff --git a/cargo-geiger/src/traversal.rs b/cargo-geiger/src/traversal.rs index ac683fb1..f80f7c30 100644 --- a/cargo-geiger/src/traversal.rs +++ b/cargo-geiger/src/traversal.rs @@ -8,8 +8,6 @@ use petgraph::visit::EdgeRef; use petgraph::EdgeDirection; use std::collections::HashSet; -// ---------- BEGIN: Public items ---------- - /// To print the returned TextTreeLines in order are expected to produce a nice /// looking tree structure. /// @@ -33,8 +31,6 @@ pub fn walk_dependency_tree( ) } -// ---------- END: Public items ---------- - fn walk_dependency_kind( kind: DepKind, deps: &mut Vec<&Node>, diff --git a/geiger/src/lib.rs b/geiger/src/lib.rs index 4050f201..6a36906b 100644 --- a/geiger/src/lib.rs +++ b/geiger/src/lib.rs @@ -102,12 +102,6 @@ impl Add for CounterBlock { } } -pub enum DetectionStatus { - NoneDetectedForbidsUnsafe, - NoneDetectedAllowsUnsafe, - UnsafeDetected, -} - /// Scan result for a single `.rs` file. #[derive(Debug, Default)] pub struct RsFileMetrics {