Skip to content

Commit

Permalink
Merge pull request #515 from DataDog/amaan.qureshi/STAL-2925
Browse files Browse the repository at this point in the history
[STAL-2925] feat: ignore auto-generated C# files
  • Loading branch information
amaanq authored Sep 25, 2024
2 parents 5391280 + 80b97f5 commit 64e2ced
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions crates/static-analysis-kernel/src/analysis/generated_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<autogenerated") | content.contains("<auto-generated")
}
_ => false,
}
}
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -195,6 +204,22 @@ mod tests {
));
}

#[test]
fn test_is_generated_file_csharp() {
assert!(!is_generated_file(
&"// <notautogenerated>\nfunction smtg(){}",
&Language::Csharp,
));
assert!(is_generated_file(
&"// <autogenerated>\nfunction smtg(){}",
&Language::Csharp
));
assert!(is_generated_file(
&"//----\n <auto-generated>\n Autogenerated\n </auto-generated>\n//----\nfunction smtg(){}",
&Language::Csharp
));
}

#[test]
fn test_is_minified_file_javascript() {
assert!(is_minified_file(
Expand Down
1 change: 1 addition & 0 deletions crates/static-analysis-kernel/src/model/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ impl From<String> for PathPattern {
.literal_separator(true)
.empty_alternates(true)
.backslash_escape(true)
.case_insensitive(true)
.build()
.map(|g| g.compile_matcher())
.ok(),
Expand Down

0 comments on commit 64e2ced

Please sign in to comment.