diff --git a/.gitignore b/.gitignore index 14599b5..2c21088 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ target debug.log release node_modules -tarpaulin-report.html -build_rs_cov.profraw - +tarpaulin-report.html +build_rs_cov.profraw .idea/ diff --git a/crates/fta/src/config/mod.rs b/crates/fta/src/config/mod.rs index 9870929..c7d7efe 100644 --- a/crates/fta/src/config/mod.rs +++ b/crates/fta/src/config/mod.rs @@ -25,6 +25,7 @@ pub fn read_config(config_path: &str) -> FtaConfig { ]), output_limit: Some(5000), score_cap: Some(1000), + include_comments: Some(false), }; if Path::new(config_path).exists() { @@ -57,6 +58,9 @@ pub fn read_config(config_path: &str) -> FtaConfig { }, output_limit: provided_config.output_limit.or(default_config.output_limit), score_cap: provided_config.score_cap.or(default_config.score_cap), + include_comments: provided_config + .include_comments + .or(default_config.include_comments), } } else { default_config diff --git a/crates/fta/src/config/tests.rs b/crates/fta/src/config/tests.rs index 4df1559..ccaf30b 100644 --- a/crates/fta/src/config/tests.rs +++ b/crates/fta/src/config/tests.rs @@ -18,7 +18,8 @@ mod tests { "exclude_filenames": [".tmp.go"], "exclude_directories": ["/test"], "output_limit": 2500, - "score_cap": 500 + "score_cap": 500, + "include_comments": true } "#; @@ -57,6 +58,7 @@ mod tests { ); assert_eq!(config.output_limit, Some(2500)); assert_eq!(config.score_cap, Some(500)); + assert_eq!(config.include_comments, Some(true)); } #[test] diff --git a/crates/fta/src/lib.rs b/crates/fta/src/lib.rs index 7bdd5f4..d9f9421 100644 --- a/crates/fta/src/lib.rs +++ b/crates/fta/src/lib.rs @@ -94,7 +94,7 @@ fn do_analysis( source_code: &str, use_tsx: bool, ) -> Result { - let (result, line_count) = parse::parse_module(source_code, use_tsx); + let (result, line_count) = parse::parse_module(source_code, use_tsx, config.include_comments); match result { Ok(module) => Ok(collect_results( diff --git a/crates/fta/src/parse/mod.rs b/crates/fta/src/parse/mod.rs index b51bffb..6a5305a 100644 --- a/crates/fta/src/parse/mod.rs +++ b/crates/fta/src/parse/mod.rs @@ -9,8 +9,11 @@ use swc_ecma_parser::{error::Error, lexer::Lexer, Parser, Syntax, TsConfig}; mod tests; -pub fn parse_module(source: &str, use_tsx: bool) -> (Result, usize) { - let line_count = source.lines().count(); +pub fn parse_module( + source: &str, + use_tsx: bool, + include_comments: bool, +) -> (Result, usize) { let cm: Lrc = Default::default(); let comments = CountingComments::new(); @@ -37,9 +40,19 @@ pub fn parse_module(source: &str, use_tsx: bool) -> (Result, usiz let mut parser = Parser::new_from(lexer); let parsed = parser.parse_module(); - println!("Lines: {:?}, Comments: {:?}", line_count, comments.count()); + println!( + "Lines: {:?}, Comments: {:?}", + source.lines().count(), + comments.count() + ); + + let line_count = if include_comments == true { + source.lines().count() + } else { + source.lines().count() - comments.count() + }; - (parsed, line_count - comments.count()) + (parsed, line_count) } struct CountingComments { diff --git a/crates/fta/src/structs/mod.rs b/crates/fta/src/structs/mod.rs index 0031b05..6cfb595 100644 --- a/crates/fta/src/structs/mod.rs +++ b/crates/fta/src/structs/mod.rs @@ -7,6 +7,7 @@ pub struct FtaConfig { pub exclude_directories: Option>, pub output_limit: Option, pub score_cap: Option, + pub include_comments: Option, } #[derive(Debug, Serialize, PartialEq)]