Skip to content

Commit 9374bc4

Browse files
preview/check-run
1 parent ef04b8d commit 9374bc4

File tree

7 files changed

+194
-0
lines changed

7 files changed

+194
-0
lines changed

BadCode.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Intentionally terrible C# to demonstrate linter failures
2+
3+
4+
using System; using System.Collections.Generic; // extra spaces + wrong on-line ordering
5+
using System. Linq; // misplaced space after “System.”
6+
using System.Threading.Tasks; // comment trailing spaces
7+
8+
namespace BadlyFormattedNS { // brace on same line, double spaces
9+
public class bad_class // wrong casing + double spaces
10+
{
11+
private static readonly int ANSWER =42;// field casing, spacing, rogue constant
12+
13+
public BadCode( ) {Console . WriteLine( "Created" );} // spaces everywhere & braces
14+
15+
public void DoStuff( IDictionary< string ,List <int>> data )
16+
{ if(data==null){throw new ArgumentNullException ( nameof ( data ) );}
17+
foreach( var kvp in data ){
18+
Console.WriteLine( $"Key:{kvp.Key}, Count = {kvp.Value.Count}"); } /* crowded */
19+
} // incorrect indentation + brace style
20+
21+
internal static async Task < IEnumerable < int > >GetValuesAsync( )
22+
{
23+
await Task . Delay (100 ) ; // spaces around dot + inside parentheses
24+
return new List<int>{1 ,2,3 , 4}; // inconsistent spacing
25+
} // extra spaces before brace
26+
}
27+
} // No newline at end

BadCodeProject.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- BadCodeProject.csproj -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<!-- explicitly include the demo file so the project builds -->
10+
<ItemGroup>
11+
<Compile Include="BadCode.cs" />
12+
</ItemGroup>
13+
</Project>

BadCodeProject.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.0.31903.59
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BadCodeProject", "BadCodeProject\BadCodeProject.csproj", "{12345678-1234-1234-1234-123456789012}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{12345678-1234-1234-1234-123456789012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{12345678-1234-1234-1234-123456789012}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{12345678-1234-1234-1234-123456789012}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{12345678-1234-1234-1234-123456789012}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
EndGlobal

BadCodeProject/BadCodeProject.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

BadCodeProject/Program.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace BadCodeProject
6+
{
7+
public class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
// Unused variable
12+
int unusedVariable = 42;
13+
14+
// Redundant type specification
15+
List<string> strings = new List<string>();
16+
17+
// Possible null reference
18+
string? nullableString = null;
19+
Console.WriteLine(nullableString.Length);
20+
21+
// Inconsistent naming
22+
int my_variable = 10;
23+
int myVariable = 20;
24+
25+
// Unused parameter
26+
void UnusedParameter(int unusedParam)
27+
{
28+
Console.WriteLine("Hello");
29+
}
30+
31+
// Redundant parentheses
32+
int result = (1 + (2 * 3));
33+
34+
// Magic number
35+
if (result > 7)
36+
{
37+
Console.WriteLine("Too high");
38+
}
39+
40+
// Inconsistent string literal
41+
Console.WriteLine("Hello" + " " + "World");
42+
43+
// Unnecessary boxing
44+
object boxed = 42;
45+
46+
// Redundant ToString() call
47+
string number = 42.ToString();
48+
49+
// Unused method
50+
void UnusedMethod()
51+
{
52+
Console.WriteLine("Never called");
53+
}
54+
55+
// Possible multiple enumeration
56+
var numbers = Enumerable.Range(1, 10);
57+
var sum = numbers.Sum();
58+
var count = numbers.Count();
59+
60+
// Inconsistent access modifiers
61+
private int privateField = 0;
62+
public int publicField = 0;
63+
64+
// Unnecessary cast
65+
object obj = "string";
66+
string str = (string)obj;
67+
68+
// Redundant conditional
69+
bool condition = true;
70+
if (condition == true)
71+
{
72+
Console.WriteLine("Redundant");
73+
}
74+
}
75+
}
76+
}

workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: C# Linter
2+
3+
# ───────────── TRIGGER ─────────────
4+
on:
5+
pull_request:
6+
7+
# ───────────── JOBS ─────────────
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-dotnet@v4
15+
with:
16+
dotnet-version: '8.0.x' # .NET 8 already contains 'dotnet format'; no extra tool install needed
17+
18+
# Restore & analyze the new project
19+
- name: Restore packages
20+
run: dotnet restore BadCodeProject.csproj
21+
22+
- name: Run dotnet format
23+
run: dotnet format BadCodeProject.csproj --verify-no-changes --severity info

workflows/resharper.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: ReSharper Inspection
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
inspection:
8+
runs-on: ubuntu-latest
9+
name: ReSharper Code Inspection
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Setup .NET
15+
id: setup-dotnet
16+
uses: actions/setup-dotnet@v4
17+
with:
18+
dotnet-version: '8.0.x'
19+
20+
- name: Restore
21+
run: dotnet restore BadCodeProject.sln
22+
23+
- name: Inspect code with ReSharper
24+
uses: muno92/resharper_inspectcode@v1
25+
with:
26+
solutionPath: ./BadCodeProject.sln
27+
dotnetVersion: ${{ steps.setup-dotnet.outputs.dotnet-version }}

0 commit comments

Comments
 (0)