From 80b97f5567d7ae433292845a97b4d6a86f4c8997 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Wed, 25 Sep 2024 14:44:46 -0400 Subject: [PATCH] feat: ignore auto-generated C# files --- .../src/analysis/generated_content.rs | 25 +++++++++++++++++++ .../src/model/config_file.rs | 1 + 2 files changed, 26 insertions(+) diff --git a/crates/static-analysis-kernel/src/analysis/generated_content.rs b/crates/static-analysis-kernel/src/analysis/generated_content.rs index fb4b74fd..8eaa85b9 100644 --- a/crates/static-analysis-kernel/src/analysis/generated_content.rs +++ b/crates/static-analysis-kernel/src/analysis/generated_content.rs @@ -45,6 +45,9 @@ pub fn is_generated_file(full_content: &str, language: &Language) -> bool { | content.contains("GENERATED CODE -- DO NOT EDIT!") | content.contains(THRIFT_HEADER) } + Language::Csharp => { + content.contains(" false, } } @@ -80,6 +83,12 @@ pub const DEFAULT_IGNORED_GLOBS: &[&str] = &[ "**/.bundle/**/*", // Java "**/.gradle/**/*", + // C# + "**/TemporaryGeneratedFile_.*.cs", + "**/*.designer.cs", + "**/*.generated.cs", + "**/*.g.cs", + "**/*.g.i.cs", ]; #[cfg(test)] @@ -195,6 +204,22 @@ mod tests { )); } + #[test] + fn test_is_generated_file_csharp() { + assert!(!is_generated_file( + &"// \nfunction smtg(){}", + &Language::Csharp, + )); + assert!(is_generated_file( + &"// \nfunction smtg(){}", + &Language::Csharp + )); + assert!(is_generated_file( + &"//----\n \n Autogenerated\n \n//----\nfunction smtg(){}", + &Language::Csharp + )); + } + #[test] fn test_is_minified_file_javascript() { assert!(is_minified_file( diff --git a/crates/static-analysis-kernel/src/model/config_file.rs b/crates/static-analysis-kernel/src/model/config_file.rs index 84b70889..b4644e27 100644 --- a/crates/static-analysis-kernel/src/model/config_file.rs +++ b/crates/static-analysis-kernel/src/model/config_file.rs @@ -135,6 +135,7 @@ impl From for PathPattern { .literal_separator(true) .empty_alternates(true) .backslash_escape(true) + .case_insensitive(true) .build() .map(|g| g.compile_matcher()) .ok(),