1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-07 06:46:59 -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.
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<T: DirectiveKind>(
#[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;

View file

@ -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 =