From 207ec468c121ee07b907357b171d23a06e20f098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 5 Nov 2024 14:05:18 +0100 Subject: [PATCH] wip --- cli/tools/lint/linter.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cli/tools/lint/linter.rs b/cli/tools/lint/linter.rs index b2cbb84f42..ee4ccb3eed 100644 --- a/cli/tools/lint/linter.rs +++ b/cli/tools/lint/linter.rs @@ -269,7 +269,10 @@ fn apply_lint_fixes( pub fn is_minified_file(code: &str) -> bool { const LONG_LINE_THRESHOLD: usize = 250; - const WHITESPACE_THRESHOLD: f64 = 0.2; + const WHITESPACE_THRESHOLD: f64 = 0.01; + + let mut whitespace_count = 0; + let mut total_len = 0; let is_possibly_minified = code.lines().any(|line| { // Line length over the threshold suggests a minified file. @@ -284,18 +287,23 @@ pub fn is_minified_file(code: &str) -> bool { return true; } - // Last ditch effort, if there's few whitespaces it's probably minified. + // Last ditch effort, keep track of whitespace count. if line_len > 0 { - let whitespace_count = + whitespace_count += line.chars().filter(|c| c.is_ascii_whitespace()).count(); - return (whitespace_count as f64 / line_len as f64) - < WHITESPACE_THRESHOLD; + total_len += line.len(); } false }); - is_possibly_minified + let whitespace_ratio = whitespace_count as f64 / total_len as f64; + eprintln!("whitespace_ration {}", whitespace_ratio); + if whitespace_ratio < WHITESPACE_THRESHOLD { + true + } else { + is_possibly_minified + } } // Example test module