1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 07:08:27 -05:00

refactor: format & lint

This commit is contained in:
Ben Heidemann 2024-10-27 20:12:03 +00:00
parent 0da0f36945
commit b8d7876db2
2 changed files with 30 additions and 31 deletions

View file

@ -1,6 +1,5 @@
use std::collections::HashMap;
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use deno_ast::swc::common::comments::Comment; use deno_ast::swc::common::comments::Comment;
use deno_ast::swc::common::comments::CommentKind; use deno_ast::swc::common::comments::CommentKind;
use deno_ast::view as ast_view; use deno_ast::view as ast_view;
@ -9,6 +8,7 @@ use deno_ast::SourceRange;
use deno_ast::SourceRanged; use deno_ast::SourceRanged;
use deno_ast::SourceRangedForSpanned as _; use deno_ast::SourceRangedForSpanned as _;
use deno_ast::SourceTextInfoProvider as _; use deno_ast::SourceTextInfoProvider as _;
use std::collections::HashMap;
static COVERAGE_IGNORE_START_DIRECTIVE: &str = "deno-coverage-ignore-start"; static COVERAGE_IGNORE_START_DIRECTIVE: &str = "deno-coverage-ignore-start";
static COVERAGE_IGNORE_STOP_DIRECTIVE: &str = "deno-coverage-ignore-stop"; 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() { if current_range.is_none() {
current_range = Some(comment.range()); 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; depth -= 1;
if depth == 0 { if depth == 0 {
let mut range = current_range.take().unwrap(); let mut range = current_range.take().unwrap();
@ -165,7 +164,9 @@ fn parse_ignore_comment<T: DirectiveKind>(
#[cfg(test)] #[cfg(test)]
mod tests { 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; use crate::tools::coverage::ast_parser;

View file

@ -284,17 +284,17 @@ fn generate_coverage_report(
); );
if line_index > 0 if line_index > 0
&& coverage_ignore_next_directives && coverage_ignore_next_directives.contains_key(&(line_index - 1_usize))
.contains_key(&(line_index - 1 as usize))
{ {
continue; continue;
} }
if coverage_ignore_range_directives if coverage_ignore_range_directives
.iter() .iter()
.any(|(start, stop)| *start <= line_index && *stop >= line_index) { .any(|(start, stop)| *start <= line_index && *stop >= line_index)
continue; {
} continue;
}
coverage_report.named_functions.push(FunctionCoverageItem { coverage_report.named_functions.push(FunctionCoverageItem {
name: function.function_name.clone(), name: function.function_name.clone(),
@ -310,17 +310,17 @@ fn generate_coverage_report(
range_to_src_line_index(range, &text_lines, &maybe_source_map); range_to_src_line_index(range, &text_lines, &maybe_source_map);
if line_index > 0 if line_index > 0
&& coverage_ignore_next_directives && coverage_ignore_next_directives.contains_key(&(line_index - 1_usize))
.contains_key(&(line_index - 1 as usize))
{ {
continue; continue;
} }
if coverage_ignore_range_directives if coverage_ignore_range_directives
.iter() .iter()
.any(|(start, stop)| *start <= line_index && *stop >= line_index) { .any(|(start, stop)| *start <= line_index && *stop >= line_index)
continue; {
} continue;
}
// From https://manpages.debian.org/unstable/lcov/geninfo.1.en.html: // 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 { let found_lines_coverage_filter = |(line, _): &(usize, i64)| -> bool {
if coverage_ignore_range_directives if coverage_ignore_range_directives
.iter() .iter()
.any(|(start, stop)| start <= line && stop >= line) { .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()
{ {
return false; 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 = coverage_report.found_lines =