From 9374bc4034eb32262cef6aa7b91b27744560acd4 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 16 Jul 2025 11:57:42 -0400 Subject: [PATCH 1/2] preview/check-run --- BadCode.cs | 27 ++++++++++ BadCodeProject.csproj | 13 +++++ BadCodeProject.sln | 18 +++++++ BadCodeProject/BadCodeProject.csproj | 10 ++++ BadCodeProject/Program.cs | 76 ++++++++++++++++++++++++++++ workflows/lint.yml | 23 +++++++++ workflows/resharper.yml | 27 ++++++++++ 7 files changed, 194 insertions(+) create mode 100644 BadCode.cs create mode 100644 BadCodeProject.csproj create mode 100644 BadCodeProject.sln create mode 100644 BadCodeProject/BadCodeProject.csproj create mode 100644 BadCodeProject/Program.cs create mode 100644 workflows/lint.yml create mode 100644 workflows/resharper.yml diff --git a/BadCode.cs b/BadCode.cs new file mode 100644 index 0000000..504bbc1 --- /dev/null +++ b/BadCode.cs @@ -0,0 +1,27 @@ + // Intentionally terrible C# to demonstrate linter failures + + +using System; using System.Collections.Generic; // extra spaces + wrong on-line ordering +using System. Linq; // misplaced space after “System.” +using System.Threading.Tasks; // comment trailing spaces + +namespace BadlyFormattedNS { // brace on same line, double spaces +public class bad_class // wrong casing + double spaces +{ + private static readonly int ANSWER =42;// field casing, spacing, rogue constant + + public BadCode( ) {Console . WriteLine( "Created" );} // spaces everywhere & braces + + public void DoStuff( IDictionary< string ,List > data ) + { if(data==null){throw new ArgumentNullException ( nameof ( data ) );} + foreach( var kvp in data ){ + Console.WriteLine( $"Key:{kvp.Key}, Count = {kvp.Value.Count}"); } /* crowded */ + } // incorrect indentation + brace style + + internal static async Task < IEnumerable < int > >GetValuesAsync( ) +{ + await Task . Delay (100 ) ; // spaces around dot + inside parentheses + return new List{1 ,2,3 , 4}; // inconsistent spacing +} // extra spaces before brace +} +} // No newline at end diff --git a/BadCodeProject.csproj b/BadCodeProject.csproj new file mode 100644 index 0000000..2e6bfb3 --- /dev/null +++ b/BadCodeProject.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/BadCodeProject.sln b/BadCodeProject.sln new file mode 100644 index 0000000..b822695 --- /dev/null +++ b/BadCodeProject.sln @@ -0,0 +1,18 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BadCodeProject", "BadCodeProject\BadCodeProject.csproj", "{12345678-1234-1234-1234-123456789012}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {12345678-1234-1234-1234-123456789012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12345678-1234-1234-1234-123456789012}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12345678-1234-1234-1234-123456789012}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12345678-1234-1234-1234-123456789012}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal \ No newline at end of file diff --git a/BadCodeProject/BadCodeProject.csproj b/BadCodeProject/BadCodeProject.csproj new file mode 100644 index 0000000..184149b --- /dev/null +++ b/BadCodeProject/BadCodeProject.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + \ No newline at end of file diff --git a/BadCodeProject/Program.cs b/BadCodeProject/Program.cs new file mode 100644 index 0000000..7b0ea3a --- /dev/null +++ b/BadCodeProject/Program.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace BadCodeProject +{ + public class Program + { + public static void Main(string[] args) + { + // Unused variable + int unusedVariable = 42; + + // Redundant type specification + List strings = new List(); + + // Possible null reference + string? nullableString = null; + Console.WriteLine(nullableString.Length); + + // Inconsistent naming + int my_variable = 10; + int myVariable = 20; + + // Unused parameter + void UnusedParameter(int unusedParam) + { + Console.WriteLine("Hello"); + } + + // Redundant parentheses + int result = (1 + (2 * 3)); + + // Magic number + if (result > 7) + { + Console.WriteLine("Too high"); + } + + // Inconsistent string literal + Console.WriteLine("Hello" + " " + "World"); + + // Unnecessary boxing + object boxed = 42; + + // Redundant ToString() call + string number = 42.ToString(); + + // Unused method + void UnusedMethod() + { + Console.WriteLine("Never called"); + } + + // Possible multiple enumeration + var numbers = Enumerable.Range(1, 10); + var sum = numbers.Sum(); + var count = numbers.Count(); + + // Inconsistent access modifiers + private int privateField = 0; + public int publicField = 0; + + // Unnecessary cast + object obj = "string"; + string str = (string)obj; + + // Redundant conditional + bool condition = true; + if (condition == true) + { + Console.WriteLine("Redundant"); + } + } + } +} \ No newline at end of file diff --git a/workflows/lint.yml b/workflows/lint.yml new file mode 100644 index 0000000..6c78d91 --- /dev/null +++ b/workflows/lint.yml @@ -0,0 +1,23 @@ +name: C# Linter + +# ───────────── TRIGGER ───────────── +on: + pull_request: + +# ───────────── JOBS ───────────── +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' # .NET 8 already contains 'dotnet format'; no extra tool install needed + + # Restore & analyze the new project + - name: Restore packages + run: dotnet restore BadCodeProject.csproj + + - name: Run dotnet format + run: dotnet format BadCodeProject.csproj --verify-no-changes --severity info \ No newline at end of file diff --git a/workflows/resharper.yml b/workflows/resharper.yml new file mode 100644 index 0000000..46624bf --- /dev/null +++ b/workflows/resharper.yml @@ -0,0 +1,27 @@ +name: ReSharper Inspection + +on: + pull_request: + +jobs: + inspection: + runs-on: ubuntu-latest + name: ReSharper Code Inspection + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + id: setup-dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + - name: Restore + run: dotnet restore BadCodeProject.sln + + - name: Inspect code with ReSharper + uses: muno92/resharper_inspectcode@v1 + with: + solutionPath: ./BadCodeProject.sln + dotnetVersion: ${{ steps.setup-dotnet.outputs.dotnet-version }} \ No newline at end of file From 8246997e28f1a2ef2a958815f543cf6976bba043 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 16 Jul 2025 11:58:56 -0400 Subject: [PATCH 2/2] fix paths --- {workflows => .github/workflows}/lint.yml | 0 {workflows => .github/workflows}/resharper.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {workflows => .github/workflows}/lint.yml (100%) rename {workflows => .github/workflows}/resharper.yml (100%) diff --git a/workflows/lint.yml b/.github/workflows/lint.yml similarity index 100% rename from workflows/lint.yml rename to .github/workflows/lint.yml diff --git a/workflows/resharper.yml b/.github/workflows/resharper.yml similarity index 100% rename from workflows/resharper.yml rename to .github/workflows/resharper.yml