From b8d7876db2e1264825620c6654b03e434de860bd Mon Sep 17 00:00:00 2001 From: Ben Heidemann Date: Sun, 27 Oct 2024 20:12:03 +0000 Subject: [PATCH] refactor: format & lint --- cli/tools/coverage/ignore_directives.rs | 11 +++--- cli/tools/coverage/mod.rs | 50 ++++++++++++------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/cli/tools/coverage/ignore_directives.rs b/cli/tools/coverage/ignore_directives.rs index c88eec4a79..b605f4d225 100644 --- a/cli/tools/coverage/ignore_directives.rs +++ b/cli/tools/coverage/ignore_directives.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; - // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + use deno_ast::swc::common::comments::Comment; use deno_ast::swc::common::comments::CommentKind; use deno_ast::view as ast_view; @@ -9,6 +8,7 @@ use deno_ast::SourceRange; use deno_ast::SourceRanged; use deno_ast::SourceRangedForSpanned as _; use deno_ast::SourceTextInfoProvider as _; +use std::collections::HashMap; static COVERAGE_IGNORE_START_DIRECTIVE: &str = "deno-coverage-ignore-start"; static COVERAGE_IGNORE_STOP_DIRECTIVE: &str = "deno-coverage-ignore-stop"; @@ -59,8 +59,7 @@ pub fn parse_range_ignore_directives( if current_range.is_none() { current_range = Some(comment.range()); } - } - else if depth > 0 && prefix == COVERAGE_IGNORE_STOP_DIRECTIVE { + } else if depth > 0 && prefix == COVERAGE_IGNORE_STOP_DIRECTIVE { depth -= 1; if depth == 0 { let mut range = current_range.take().unwrap(); @@ -165,7 +164,9 @@ fn parse_ignore_comment( #[cfg(test)] mod tests { - use deno_ast::{MediaType, ModuleSpecifier, ParsedSource}; + use deno_ast::MediaType; + use deno_ast::ModuleSpecifier; + use deno_ast::ParsedSource; use crate::tools::coverage::ast_parser; diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index f2dbe4733e..07ce004dad 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -284,17 +284,17 @@ fn generate_coverage_report( ); if line_index > 0 - && coverage_ignore_next_directives - .contains_key(&(line_index - 1 as usize)) + && coverage_ignore_next_directives.contains_key(&(line_index - 1_usize)) { continue; } if coverage_ignore_range_directives .iter() - .any(|(start, stop)| *start <= line_index && *stop >= line_index) { - continue; - } + .any(|(start, stop)| *start <= line_index && *stop >= line_index) + { + continue; + } coverage_report.named_functions.push(FunctionCoverageItem { name: function.function_name.clone(), @@ -310,17 +310,17 @@ fn generate_coverage_report( range_to_src_line_index(range, &text_lines, &maybe_source_map); if line_index > 0 - && coverage_ignore_next_directives - .contains_key(&(line_index - 1 as usize)) + && coverage_ignore_next_directives.contains_key(&(line_index - 1_usize)) { continue; } if coverage_ignore_range_directives .iter() - .any(|(start, stop)| *start <= line_index && *stop >= line_index) { - continue; - } + .any(|(start, stop)| *start <= line_index && *stop >= line_index) + { + continue; + } // From https://manpages.debian.org/unstable/lcov/geninfo.1.en.html: // @@ -400,26 +400,24 @@ fn generate_coverage_report( let found_lines_coverage_filter = |(line, _): &(usize, i64)| -> bool { if coverage_ignore_range_directives .iter() - .any(|(start, stop)| start <= line && stop >= line) { - return false; - } - - if coverage_ignore_next_directives.get(&line).is_some() { - return false; - } - - if *line == 0 as usize { - return true; - } - - if coverage_ignore_next_directives - .get(&(line - 1 as usize)) - .is_some() + .any(|(start, stop)| start <= line && stop >= line) { return false; } - return true; + if coverage_ignore_next_directives.contains_key(line) { + return false; + } + + if *line == 0_usize { + return true; + } + + if coverage_ignore_next_directives.contains_key(&(line - 1_usize)) { + return false; + } + + true }; coverage_report.found_lines =