Skip to content

Commit

Permalink
ISSUE-16 - Make PR requested changes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jmcconnell26 committed Sep 2, 2020
1 parent e3be5d7 commit ae3317a
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 68 deletions.
4 changes: 0 additions & 4 deletions cargo-geiger/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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.
4 changes: 0 additions & 4 deletions cargo-geiger/src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -76,8 +74,6 @@ where
GeigerContext { pack_id_to_metrics }
}

// ---------- END: Public items ----------

fn find_rs_files_in_dir(dir: &Path) -> impl Iterator<Item = PathBuf> {
let walker = WalkDir::new(dir).into_iter();
walker.filter_map(|entry| {
Expand Down
10 changes: 6 additions & 4 deletions cargo-geiger/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,6 +31,12 @@ impl FromStr for Charset {
}
}

pub enum CrateDetectionStatus {
NoneDetectedForbidsUnsafe,
NoneDetectedAllowsUnsafe,
UnsafeDetected,
}

pub struct Display<'a> {
pattern: &'a Pattern,
package: &'a PackageId,
Expand Down Expand Up @@ -150,8 +154,6 @@ pub fn get_kind_group_name(k: DepKind) -> Option<&'static str> {
}
}

// ---------- END: Public items ----------

enum Chunk {
Raw(String),
Package,
Expand Down
4 changes: 0 additions & 4 deletions cargo-geiger/src/format/parse.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::iter;
use std::str;

// ---------- BEGIN: Public items ----------

pub enum RawChunk<'a> {
Text(&'a str),
Argument(&'a str),
Expand Down Expand Up @@ -97,5 +95,3 @@ impl<'a> Iterator for Parser<'a> {
}
}
}

// ---------- END: Public items ----------
15 changes: 5 additions & 10 deletions cargo-geiger/src/format/print.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 ----------
28 changes: 12 additions & 16 deletions cargo-geiger/src/format/table.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
}
}
});
Expand All @@ -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)
}
};
Expand Down Expand Up @@ -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!(
"{}",
Expand All @@ -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_)
Expand Down
4 changes: 0 additions & 4 deletions cargo-geiger/src/format/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,8 +27,6 @@ pub fn get_tree_symbols(cs: Charset) -> TreeSymbols {
}
}

// ---------- END: Public items ----------

const ASCII_TREE_SYMBOLS: TreeSymbols = TreeSymbols {
down: "|",
tee: "|",
Expand Down
4 changes: 0 additions & 4 deletions cargo-geiger/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]>,
Expand Down
4 changes: 0 additions & 4 deletions cargo-geiger/src/rs_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
///
Expand Down
4 changes: 0 additions & 4 deletions cargo-geiger/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -219,8 +217,6 @@ pub fn run_scan_mode_forbid_only(
Ok(())
}

// ---------- END: Public items ----------

#[derive(Debug)]
struct FoundWarningsError {
pub warning_count: u64,
Expand Down
4 changes: 0 additions & 4 deletions cargo-geiger/src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -33,8 +31,6 @@ pub fn walk_dependency_tree(
)
}

// ---------- END: Public items ----------

fn walk_dependency_kind(
kind: DepKind,
deps: &mut Vec<&Node>,
Expand Down
6 changes: 0 additions & 6 deletions geiger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ae3317a

Please sign in to comment.