Skip to content

Commit

Permalink
Feat: TIMING env debug, rework runner to separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RDambrosio016 committed Jul 20, 2020
1 parent 61ec81f commit 4aa7720
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 113 deletions.
6 changes: 6 additions & 0 deletions rslint/src/lib.rs
Expand Up @@ -41,6 +41,12 @@
//! - The timestamp of when the cache file was generated
//!
//! If you would like to know more about cache you should check out [the cache module](cache)
//!
//! # Profiling
//! If you would like to profile the performance of RSLint you should first run benchmarks. RSLint also allows for showing an approximation of the duration
//! of every major linting operation, as well as an average of the top ten slowest rules.
//! To display these statistics set the env var `TIMING` to `1`


pub mod diagnostic;
pub mod formatters;
Expand Down
39 changes: 29 additions & 10 deletions rslint/src/rules/mod.rs
Expand Up @@ -96,6 +96,34 @@ pub enum Outcome {
Warning,
}

impl From<&Vec<Diagnostic<usize>>> for Outcome {
fn from(diagnostics: &Vec<Diagnostic<usize>>) -> Self {
let mut outcome = Outcome::Success;
for diagnostic in diagnostics.iter() {
match diagnostic.severity {
Severity::Error | Severity::Bug => outcome = Outcome::Error,
Severity::Warning if outcome != Outcome::Error => outcome = Outcome::Warning,
_ => {},
}
}
outcome
}
}

impl From<&Vec<Outcome>> for Outcome {
fn from(outcomes: &Vec<Outcome>) -> Self {
let mut res = Outcome::Success;
for outcome in outcomes.iter() {
match outcome {
Outcome::Error => res = Outcome::Error,
Outcome::Warning if res != Outcome::Error => res = Outcome::Warning,
_ => {},
}
}
res
}
}

/// The overall result of running a rule on a file constructed by a vector of diagnostics
#[derive(Debug, Clone)]
pub struct RuleResult {
Expand Down Expand Up @@ -143,17 +171,8 @@ impl RuleResult {
/// Make a new rule result from a list of diagnostics
impl<'a> From<Vec<Diagnostic<usize>>> for RuleResult {
fn from(diagnostics: Vec<Diagnostic<usize>>) -> Self {
let mut outcome = Outcome::Success;
for diagnostic in diagnostics.iter() {
match diagnostic.severity {
Severity::Error | Severity::Bug => outcome = Outcome::Error,
Severity::Warning => outcome = Outcome::Warning,
_ => {},
}
}

Self {
outcome,
outcome: Outcome::from(&diagnostics),
diagnostics
}
}
Expand Down

0 comments on commit 4aa7720

Please sign in to comment.