Skip to content

Commit

Permalink
fix: Skip non .cs files IO-1156 (#240)
Browse files Browse the repository at this point in the history
* test: Add test for Directory.Build.props false positives

* fix: Skip non `.cs` files

* fix: Codacy issue
  • Loading branch information
lolgab authored Jul 31, 2024
1 parent 418bb42 commit 433fafa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/multiple-tests/skip-non-cs-files/patterns.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<module name="root">
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="SonarLint\.xml"/>
</module>
</module>
3 changes: 3 additions & 0 deletions docs/multiple-tests/skip-non-cs-files/results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="4.3">
</checkstyle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
</ItemGroup>
</Project>


14 changes: 14 additions & 0 deletions docs/multiple-tests/skip-non-cs-files/src/SonarLint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
<Rules>
<Rule>
<Key>S103</Key>
<Parameters>
<Parameter>
<Key>maximumLineLength</Key>
<Value>24</Value>
</Parameter>
</Parameters>
</Rule>
</Rules>
</AnalysisInput>
14 changes: 13 additions & 1 deletion src/Analyzer/CodeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ protected virtual void Dispose(bool disposing)

protected override async Task Analyze(CancellationToken cancellationToken)
{
foreach (var file in Config.Files) await Analyze(file, cancellationToken).ConfigureAwait(false);
foreach (var file in Config.Files) {
// skip all files that don't have the main language extension
// To allow Semgrep to run on C# configuration files
// We are analyzing `Directory.Packages.props` as if it was a C# file
// This is to avoid that.
// More info here: https://codacy.zendesk.com/agent/tickets/44462
if (!file.EndsWith(".cs"))
{
continue;
}

await Analyze(file, cancellationToken).ConfigureAwait(false);
}
}

public async Task Analyze(string file, CancellationToken cancellationToken)
Expand Down

0 comments on commit 433fafa

Please sign in to comment.