Skip to content

Commit 18ca297

Browse files
committed
add Qodana static code analysis
1 parent 5b8828d commit 18ca297

File tree

122 files changed

+587
-475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+587
-475
lines changed

.editorconfig

+6-5
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ dotnet_diagnostic.CA1016.severity = none
6868
#### C# Coding Conventions ####
6969

7070
# Prefer "var" everywhere
71-
csharp_style_var_for_built_in_types = true:silent
72-
csharp_style_var_when_type_is_apparent = true:silent
73-
csharp_style_var_elsewhere = true:silent
71+
csharp_style_var_for_built_in_types = true:suggestion
72+
csharp_style_var_when_type_is_apparent = true:suggestion
73+
csharp_style_var_elsewhere = true:suggestion
7474

7575
# Prefer method-like constructs to have a block body, except for lambdas
7676
csharp_style_expression_bodied_methods = true:warning
@@ -152,9 +152,10 @@ csharp_space_between_method_call_parameter_list_parentheses = false
152152
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
153153
csharp_space_between_method_declaration_name_and_open_parenthesis = false
154154
csharp_space_between_method_declaration_parameter_list_parentheses = false
155-
csharp_space_between_parentheses = false
156155
csharp_space_between_square_brackets = false
157156

157+
csharp_use_roslyn_logic_for_evident_types = true
158+
158159
# Alignment
159160
align_multiline_parameter = true
160161

@@ -194,4 +195,4 @@ dotnet_diagnostic.RCS1037.severity = error
194195
# RCS1036: Remove redundant empty line.
195196
dotnet_diagnostic.RCS1036.severity = error
196197

197-
[resharper_]xml_space_before_self_closing = true
198+
xml_space_before_self_closing = true
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Qodana
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
qodana:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
checks: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }}
20+
fetch-depth: 0
21+
- name: 'Qodana Scan'
22+
uses: jetbrains/[email protected]
23+
env:
24+
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ TestResults
6161
ClientBin
6262
stylecop.*
6363
~$*
64-
*~
6564
*.dbmdl
6665
site/
6766
Generated_Code #added for RIA/Silverlight projects

build/CI.slnx

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<File Path="../.github/workflows/release.yml" />
4545
<File Path="../.github/workflows/stale.yml" />
4646
<File Path="../.github/workflows/winget.yml" />
47+
<File Path="../.github/workflows/qodana_code_quality.yml" />
4748
</Folder>
4849
<Folder Name="/workflows/_/">
4950
<File Path="../.github/workflows/_artifacts_linux.yml" />

qodana.yaml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#-------------------------------------------------------------------------------#
2+
# Qodana analysis is configured by qodana.yaml file #
3+
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
4+
#-------------------------------------------------------------------------------#
5+
version: "1.0"
6+
#Specify IDE code to run analysis without container (Applied in CI/CD pipeline)
7+
ide: QDNET
8+
#Specify inspection profile for code analysis
9+
profile:
10+
name: qodana.starter
11+
include:
12+
- name: ConvertIfStatementToReturnStatement
13+
- name: ConvertIfStatementToConditionalTernaryExpression
14+
- name: AutoPropertyCanBeMadeGetOnly.Global
15+
- name: CanReplaceCastWithLambdaReturnType
16+
- name: ChangeFieldTypeToSystemThreadingLock
17+
- name: ConvertIfStatementToSwitchStatement
18+
- name: ConvertToConstant.Local
19+
- name: DuplicatedSequentialIfBodies
20+
- name: InlineTemporaryVariable
21+
- name: InvertIf
22+
- name: UseVerbatimString
23+
- name: LoopCanBeConvertedToQuery
24+
- name: MemberCanBePrivate.Global
25+
- name: MemberCanBeProtected.Global
26+
- name: MergeIntoPattern
27+
- name: UnusedMethodReturnValue.Global
28+
- name: EditorConfigNoMatchingFiles
29+
- name: ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
30+
- name: PreferConcreteValueOverDefault
31+
- name: PropertyCanBeMadeInitOnly.Global
32+
- name: MoveLocalFunctionAfterJumpStatement
33+
- name: RedundantExplicitParamsArrayCreation
34+
- name: RedundantOverload.Global
35+
- name: RedundantStringInterpolation
36+
- name: RedundantVerbatimStringPrefix
37+
- name: ReplaceSubstringWithRangeIndexer
38+
- name: RCS1001
39+
- name: RCS1003
40+
- name: RCS1123
41+
- name: SYSLIB1045
42+
- name: CA1826
43+
- name: RCS1256
44+
- name: RCS1118
45+
- name: RCS1077
46+
- name: RCS1205
47+
- name: RCS1214
48+
- name: RCS1249
49+
- name: RCS1192
50+
- name: SYSLIB1054
51+
- name: CA1512
52+
- name: CA1866
53+
- name: CA1859
54+
- name: RCS1246
55+
- name: CA1829
56+
- name: RCS1266
57+
- name: RCS1267
58+
- name: RCS1227
59+
- name: SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault
60+
- name: SwitchStatementHandlesSomeKnownEnumValuesWithDefault
61+
- name: RedundantAlwaysMatchSubpattern
62+
- name: UnusedType.Global
63+
- name: UnusedMemberInSuper.Global
64+
- name: UnusedMember.Local
65+
- name: EditorConfigKeyCorrectness
66+
- name: UseCollectionCountProperty
67+
- name: UseDiscardAssignment
68+
- name: ArrangeNamespaceBody
69+
- name: SuggestDiscardDeclarationVarStyle
70+
- name: ArrangeTrailingCommaInMultilineLists
71+
- name: ArrangeObjectCreationWhenTypeNotEvident
72+
- name: UseRawString
73+
- name: VirtualMemberNeverOverridden.Global
74+
75+
#Enable inspections
76+
#include:
77+
# - name: <SomeEnabledInspectionId>
78+
#Disable inspections
79+
#exclude:
80+
# - name: <SomeDisabledInspectionId>
81+
# paths:
82+
# - <path/where/not/run/inspection>
83+
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
84+
#bootstrap: sh ./prepare-qodana.sh
85+
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
86+
#plugins:
87+
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)

src/GitVersion.App.Tests/HelpWriterTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void AllArgsAreInHelp()
3535
{ nameof(Arguments.ShowVariable), "/showvariable" },
3636
{ nameof(Arguments.Format), "/format" }
3737
};
38-
string helpText = string.Empty;
38+
var helpText = string.Empty;
3939

4040
this.helpWriter.WriteTo(s => helpText = s);
4141

src/GitVersion.App.Tests/VersionWriterTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void WriteVersionShouldWriteFileVersionWithNoPrereleaseTag()
2222
{
2323
var asm = GenerateAssembly(new Version(1, 0, 0), "");
2424

25-
string? version = string.Empty;
25+
var version = string.Empty;
2626
this.versionWriter.WriteTo(asm, v => version = v);
2727
Assert.Multiple(() =>
2828
{
@@ -36,7 +36,7 @@ public void WriteVersionShouldWriteFileVersionWithPrereleaseTag()
3636
{
3737
var asm = GenerateAssembly(new Version(1, 0, 0), "-beta4");
3838

39-
string? version = string.Empty;
39+
var version = string.Empty;
4040
this.versionWriter.WriteTo(asm, v => version = v);
4141
Assert.Multiple(() =>
4242
{

src/GitVersion.App/OverrideConfigurationOptionParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal class OverrideConfigurationOptionParser
4141
/// <remarks>Only simple types are supported</remarks>
4242
private static bool IsSupportedPropertyType(Type propertyType)
4343
{
44-
Type unwrappedType = Nullable.GetUnderlyingType(propertyType) ?? propertyType;
44+
var unwrappedType = Nullable.GetUnderlyingType(propertyType) ?? propertyType;
4545

4646
return unwrappedType == typeof(string)
4747
|| unwrappedType.IsEnum

src/GitVersion.App/QuotedStringHelpers.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public static string[] SplitUnquoted(string? input, char splitChar)
2626
return [];
2727

2828
var split = new List<string>();
29-
bool isPreviousCharBackslash = false;
30-
bool isInsideQuotes = false;
29+
var isPreviousCharBackslash = false;
30+
var isInsideQuotes = false;
3131

32-
int startIndex = 0;
33-
for (int i = 0; i < input.Length; i++)
32+
var startIndex = 0;
33+
for (var i = 0; i < input.Length; i++)
3434
{
35-
char current = input[i];
35+
var current = input[i];
3636
switch (current)
3737
{
3838
case '"':

src/GitVersion.Configuration/ConfigurationFileLocator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
4040

4141
public string? GetConfigurationFile(string? directoryPath)
4242
{
43-
string? customConfigurationFile = GetCustomConfigurationFilePathIfEligable(directoryPath);
43+
var customConfigurationFile = GetCustomConfigurationFilePathIfEligable(directoryPath);
4444
if (!string.IsNullOrWhiteSpace(customConfigurationFile))
4545
{
4646
this.log.Info($"Found configuration file at '{customConfigurationFile}'");
@@ -52,7 +52,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
5252
return null;
5353
}
5454

55-
string[] files = fileSystem.Directory.GetFiles(directoryPath);
55+
var files = fileSystem.Directory.GetFiles(directoryPath);
5656
foreach (var fileName in this.SupportedConfigFileNames)
5757
{
5858
this.log.Debug($"Trying to find configuration file {fileName} at '{directoryPath}'");
@@ -71,7 +71,7 @@ public void Verify(string? workingDirectory, string? projectRootDirectory)
7171
{
7272
if (!string.IsNullOrWhiteSpace(this.ConfigurationFile))
7373
{
74-
string configurationFilePath = this.ConfigurationFile;
74+
var configurationFilePath = this.ConfigurationFile;
7575
if (!string.IsNullOrWhiteSpace(directoryPath))
7676
{
7777
configurationFilePath = FileSystemHelper.Path.Combine(directoryPath, this.ConfigurationFile);

src/GitVersion.Configuration/ConfigurationProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private IGitVersionConfiguration ProvideConfiguration(string? configFile,
9797
string? workflow = null;
9898
foreach (var item in new[] { overrideConfigurationFromFile, overrideConfiguration })
9999
{
100-
if (item?.TryGetValue("workflow", out object? value) == true && value != null)
100+
if (item?.TryGetValue("workflow", out var value) == true && value != null)
101101
{
102102
workflow = (string)value;
103103
}

src/GitVersion.Configuration/ConfigurationSerializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private sealed class JsonPropertyNameInspector(ITypeInspector innerTypeDescripto
3030
public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object? container) =>
3131
innerTypeDescriptor.GetProperties(type, container)
3232
.Where(p => p.GetCustomAttribute<JsonIgnoreAttribute>() == null)
33-
.Select(p =>
33+
.Select(IPropertyDescriptor (p) =>
3434
{
3535
var descriptor = new PropertyDescriptor(p);
3636
var member = p.GetCustomAttribute<JsonPropertyNameAttribute>();
@@ -39,7 +39,7 @@ public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object
3939
descriptor.Name = member.Name;
4040
}
4141

42-
return (IPropertyDescriptor)descriptor;
42+
return descriptor;
4343
})
4444
.OrderBy(p => p.Order);
4545
}

src/GitVersion.Configuration/GitVersionConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public string? NextVersion
120120

121121
[JsonIgnore]
122122
IReadOnlyDictionary<string, IBranchConfiguration> IGitVersionConfiguration.Branches
123-
=> Branches.ToDictionary(element => element.Key, element => (IBranchConfiguration)element.Value);
123+
=> Branches.ToDictionary(element => element.Key, IBranchConfiguration (element) => element.Value);
124124

125125
[JsonPropertyName("branches")]
126126
[JsonPropertyDescription("The header for all the individual branch configuration.")]

src/GitVersion.Configuration/VersionStrategiesConverter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
2020
{
2121
while (!parser.TryConsume<SequenceEnd>(out var _))
2222
{
23-
string data = parser.Consume<Scalar>().Value;
23+
var data = parser.Consume<Scalar>().Value;
2424

2525
var strategy = Enum.Parse<VersionStrategies>(data);
2626
strategies.Add(strategy);
2727
}
2828
}
2929
else
3030
{
31-
string data = parser.Consume<Scalar>().Value;
31+
var data = parser.Consume<Scalar>().Value;
3232

3333
var deserializer = new DeserializerBuilder()
3434
.WithNamingConvention(UnderscoredNamingConvention.Instance)
@@ -42,7 +42,7 @@ public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeseria
4242

4343
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
4444
{
45-
VersionStrategies[] strategies = (VersionStrategies[])value!;
45+
var strategies = (VersionStrategies[])value!;
4646

4747
var s = new SerializerBuilder()
4848
.JsonCompatible()

src/GitVersion.Core.Tests/IntegrationTests/OtherScenarios.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void HasDirtyFlagWhenUncommittedChangesAreInRepository(bool stageFile, in
109109
using var fixture = new EmptyRepositoryFixture();
110110
fixture.MakeACommit();
111111

112-
for (int i = 0; i < numberOfFiles; i++)
112+
for (var i = 0; i < numberOfFiles; i++)
113113
{
114114
var tempFile = FileSystemHelper.Path.GetRandomFileName();
115115
var repoFile = FileSystemHelper.Path.Combine(fixture.RepositoryPath, FileSystemHelper.Path.GetFileNameWithoutExtension(tempFile) + ".txt");
@@ -1217,7 +1217,7 @@ public void EnsurePreventIncrementWhenCurrentCommitTaggedOnReleaseBranchAndIncre
12171217

12181218
if (tags is not null)
12191219
{
1220-
foreach (string tag in tags)
1220+
foreach (var tag in tags)
12211221
{
12221222
fixture.ApplyTag(tag);
12231223
}

src/GitVersion.Core.Tests/IntegrationTests/PerformanceScenarios.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public void RepositoryWithALotOfTags()
1313
using var fixture = new EmptyRepositoryFixture();
1414

1515
Random random = new(4711);
16-
SemanticVersion semanticVersion = SemanticVersion.Empty;
17-
for (int i = 0; i < 500; i++)
16+
var semanticVersion = SemanticVersion.Empty;
17+
for (var i = 0; i < 500; i++)
1818
{
19-
VersionField versionField = (VersionField)random.Next(1, 4);
19+
var versionField = (VersionField)random.Next(1, 4);
2020
semanticVersion = semanticVersion.Increment(versionField, string.Empty, forceIncrement: true);
2121
fixture.MakeATaggedCommit(semanticVersion.ToString("j"));
2222
}

src/GitVersion.Core.Tests/Mainline/MainlineScenariosWithAGitFlow+GivenADevelopBranchWithOneCommitMergedToMainWhen.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void OneTimeSetUp()
5858
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+2")]
5959
public string GetVersionWithNoLabelOnMain(IncrementStrategy incrementOnMain, IncrementStrategy increment)
6060
{
61-
IGitVersionConfiguration mainline = MainlineBuilder
61+
var mainline = MainlineBuilder
6262
.WithBranch("main", b => b.WithIncrement(incrementOnMain).WithLabel(null))
6363
.WithBranch("develop", b => b.WithIncrement(increment))
6464
.Build();
@@ -87,7 +87,7 @@ public string GetVersionWithNoLabelOnMain(IncrementStrategy incrementOnMain, Inc
8787
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-1+2")]
8888
public string GetVersionWithEmptyLabelOnMain(IncrementStrategy incrementOnMain, IncrementStrategy increment)
8989
{
90-
IGitVersionConfiguration mainline = MainlineBuilder
90+
var mainline = MainlineBuilder
9191
.WithBranch("main", b => b.WithIncrement(incrementOnMain).WithLabel(string.Empty))
9292
.WithBranch("develop", b => b.WithIncrement(increment))
9393
.Build();

src/GitVersion.Core.Tests/Mainline/MainlineScenariosWithAGitFlow+GivenADevelopBranchWithOneCommitMergedToMainWhenMergedCommitTaggedAsStable.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void OneTimeSetUp()
6060
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+0")]
6161
public string GetVersionWithTrackMergeTargetOnDevelop(IncrementStrategy incrementOnMain, IncrementStrategy increment)
6262
{
63-
IGitVersionConfiguration mainline = MainlineBuilder
63+
var mainline = MainlineBuilder
6464
.WithBranch("main", b => b.WithIncrement(incrementOnMain).WithLabel(null))
6565
.WithBranch("develop", b => b.WithIncrement(increment).WithTrackMergeTarget(true))
6666
.Build();
@@ -89,7 +89,7 @@ public string GetVersionWithTrackMergeTargetOnDevelop(IncrementStrategy incremen
8989
[TestCase(IncrementStrategy.Major, IncrementStrategy.Major, ExpectedResult = "2.0.0-alpha.1+1")]
9090
public string GetVersionWithNoTrackMergeTargetOnDevelop(IncrementStrategy incrementOnMain, IncrementStrategy increment)
9191
{
92-
IGitVersionConfiguration mainline = MainlineBuilder
92+
var mainline = MainlineBuilder
9393
.WithBranch("main", b => b.WithIncrement(incrementOnMain).WithLabel(null))
9494
.WithBranch("develop", b => b.WithIncrement(increment).WithTrackMergeTarget(false))
9595
.Build();

src/GitVersion.Core.Tests/Mainline/MainlineScenariosWithAGitHubFlow+GivenAFeatureBranchWithAMergeCommitFromMainMergedBackToMainWhen.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void OneTimeSetUp()
133133
[TestCase(IncrementStrategy.Major, IncrementStrategy.Inherit, "bar", ExpectedResult = "3.0.0-bar.1+3")]
134134
public string GetVersion(IncrementStrategy increment, IncrementStrategy incrementOnFeature, string? label)
135135
{
136-
IGitVersionConfiguration mainline = MainlineBuilder
136+
var mainline = MainlineBuilder
137137
.WithBranch("main", b => b.WithIncrement(increment).WithLabel(label))
138138
.WithBranch("feature", b => b.WithIncrement(incrementOnFeature))
139139
.Build();
@@ -227,7 +227,7 @@ public string GetVersion(IncrementStrategy increment, IncrementStrategy incremen
227227
public string GetVersionWithPreventIncrementOfMergedBranchVersionFalseOnMain(
228228
IncrementStrategy increment, IncrementStrategy incrementOnFeature, string? label)
229229
{
230-
IGitVersionConfiguration mainline = MainlineBuilder
230+
var mainline = MainlineBuilder
231231
.WithBranch("main", b => b.WithIncrement(increment).WithLabel(label).WithPreventIncrementOfMergedBranch(false))
232232
.WithBranch("feature", b => b.WithIncrement(incrementOnFeature))
233233
.Build();

0 commit comments

Comments
 (0)