Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STAL-2925] feat: ignore auto-generated C# files #515

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading