diff --git a/.dprint.json b/.dprint.json index 7877f17647..d42ad4083c 100644 --- a/.dprint.json +++ b/.dprint.json @@ -43,6 +43,7 @@ "tests/specs/fmt", "tests/specs/lint/bom", "tests/specs/lint/default_ts", + "tests/specs/lint/minified", "tests/specs/lint/syntax_error_reporting", "tests/specs/publish/no_check_surfaces_syntax_error", "tests/specs/run/default_ts", diff --git a/cli/tools/lint/minified_file.rs b/cli/tools/lint/minified_file.rs index c015debd46..5bb3e60c87 100644 --- a/cli/tools/lint/minified_file.rs +++ b/cli/tools/lint/minified_file.rs @@ -14,12 +14,13 @@ impl FileMetrics { let long_lines_ratio = self.long_lines_count as f64 / self.total_lines as f64; - (long_lines_ratio > 0.3 || self.whitespace_ratio < 0.05) - && !(self.has_license_comment && self.total_lines < 5) + (long_lines_ratio >= 0.2 || self.whitespace_ratio < 0.05) + && !(self.has_license_comment && self.total_lines < 3) } } pub fn analyze_content(content: &str) -> FileMetrics { + const LONG_LINE_LEN: usize = 250; let mut total_lines = 0; let mut long_lines_count = 0; let mut whitespace_count = 0; @@ -73,7 +74,7 @@ pub fn analyze_content(content: &str) -> FileMetrics { } // Check line length - if line_buffer.len() > 250 { + if line_buffer.len() > LONG_LINE_LEN { long_lines_count += 1; } diff --git a/tests/specs/lint/minified/__test__.jsonc b/tests/specs/lint/minified/__test__.jsonc new file mode 100644 index 0000000000..5fb3162bdf --- /dev/null +++ b/tests/specs/lint/minified/__test__.jsonc @@ -0,0 +1,7 @@ +{ + "tests": { + "args": ["lint", "minified.js"], + "output": "minified.out", + "exitCode": 1 + } +} diff --git a/tests/specs/lint/minified/minified.js b/tests/specs/lint/minified/minified.js new file mode 100644 index 0000000000..5db24c1509 --- /dev/null +++ b/tests/specs/lint/minified/minified.js @@ -0,0 +1,5 @@ +/* +* Copyright (c) 2024 Example Corp. +* Licensed under MIT License +*/ +function f(a,b){return a.concat(b)}var x=function(n){return n+1};function g(a,b){return a.concat(b)}var x=function(n){return n+1};function h(a,b){return a.concat(b)}var x=function(n){return n+1};function i(a,b){return a.concat(b)}var x=function(n){return n+1};function j(a,b){return a.concat(b)}var x=function(n){return n+1}; \ No newline at end of file