Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9374bc4

Browse files
preview/check-run
1 parentef04b8d commit9374bc4

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+
usingSystem;usingSystem.Collections.Generic;// extra spaces + wrong on-line ordering
5+
usingSystem.Linq;// misplaced space after “System.”
6+
usingSystem.Threading.Tasks;// comment trailing spaces
7+
8+
namespaceBadlyFormattedNS{// brace on same line, double spaces
9+
publicclassbad_class// wrong casing + double spaces
10+
{
11+
privatestaticreadonlyintANSWER=42;// field casing, spacing, rogue constant
12+
13+
publicBadCode(){Console.WriteLine("Created");}// spaces everywhere & braces
14+
15+
publicvoidDoStuff(IDictionary<string,List<int>>data)
16+
{if(data==null){thrownewArgumentNullException(nameof(data));}
17+
foreach(varkvpindata){
18+
Console.WriteLine($"Key:{kvp.Key}, Count ={kvp.Value.Count}");}/* crowded */
19+
}// incorrect indentation + brace style
20+
21+
internalstaticasyncTask<IEnumerable<int>>GetValuesAsync()
22+
{
23+
awaitTask.Delay(100);// spaces around dot + inside parentheses
24+
returnnewList<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+
<ProjectSdk="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+
<CompileInclude="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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<ProjectSdk="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+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.Linq;
4+
5+
namespaceBadCodeProject
6+
{
7+
publicclassProgram
8+
{
9+
publicstaticvoidMain(string[]args)
10+
{
11+
// Unused variable
12+
intunusedVariable=42;
13+
14+
// Redundant type specification
15+
List<string>strings=newList<string>();
16+
17+
// Possible null reference
18+
string?nullableString=null;
19+
Console.WriteLine(nullableString.Length);
20+
21+
// Inconsistent naming
22+
intmy_variable=10;
23+
intmyVariable=20;
24+
25+
// Unused parameter
26+
voidUnusedParameter(intunusedParam)
27+
{
28+
Console.WriteLine("Hello");
29+
}
30+
31+
// Redundant parentheses
32+
intresult=(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+
objectboxed=42;
45+
46+
// Redundant ToString() call
47+
stringnumber=42.ToString();
48+
49+
// Unused method
50+
voidUnusedMethod()
51+
{
52+
Console.WriteLine("Never called");
53+
}
54+
55+
// Possible multiple enumeration
56+
varnumbers=Enumerable.Range(1,10);
57+
varsum=numbers.Sum();
58+
varcount=numbers.Count();
59+
60+
// Inconsistent access modifiers
61+
privateintprivateField=0;
62+
publicintpublicField=0;
63+
64+
// Unnecessary cast
65+
objectobj="string";
66+
stringstr=(string)obj;
67+
68+
// Redundant conditional
69+
boolcondition=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)

[8]ページ先頭

©2009-2025 Movatter.jp