Skip to content

Commit 1037f82

Browse files
committed
refactor/fix code to clear up qodana errors/warnings
1 parent 69db309 commit 1037f82

File tree

231 files changed

+1740
-1833
lines changed

Some content is hidden

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

231 files changed

+1740
-1833
lines changed

.editorconfig

+14-38
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,12 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
5858
dotnet_style_prefer_inferred_tuple_names = true:suggestion
5959
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
6060
dotnet_style_prefer_simplified_interpolation = true:suggestion
61-
62-
# Dispose rules (CA2000 and CA2213) ported to IDE analyzers. We already execute the CA rules on the repo, so disable the IDE ones.
63-
dotnet_diagnostic.IDE0005.severity = none
64-
dotnet_diagnostic.IDE0067.severity = none
65-
dotnet_diagnostic.IDE0068.severity = none
66-
dotnet_diagnostic.IDE0069.severity = none
67-
dotnet_diagnostic.CA1016.severity = none
6861
#### C# Coding Conventions ####
6962

7063
# 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
64+
csharp_style_var_for_built_in_types = true:suggestion
65+
csharp_style_var_when_type_is_apparent = true:suggestion
66+
csharp_style_var_elsewhere = true:suggestion
7467

7568
# Prefer method-like constructs to have a block body, except for lambdas
7669
csharp_style_expression_bodied_methods = true:warning
@@ -152,38 +145,15 @@ csharp_space_between_method_call_parameter_list_parentheses = false
152145
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
153146
csharp_space_between_method_declaration_name_and_open_parenthesis = false
154147
csharp_space_between_method_declaration_parameter_list_parentheses = false
155-
csharp_space_between_parentheses = false
156148
csharp_space_between_square_brackets = false
157149

150+
resharper_csharp_use_roslyn_logic_for_evident_types = true
151+
158152
# Alignment
159-
align_multiline_parameter = true
153+
resharper_csharp_align_multiline_parameter = true
160154

161155
# Qualify fields with "this."
162-
csharp_instance_members_qualify_members = field
163-
164-
# IDE0011: Add braces
165-
dotnet_diagnostic.IDE0011.severity = none
166-
167-
# IDE0090: Use 'new(...)'
168-
dotnet_diagnostic.IDE0090.severity = warning
169-
170-
# IDE0041: Use 'is null' check
171-
dotnet_diagnostic.IDE0041.severity = warning
172-
173-
# CA1825: Avoid zero-length array allocations
174-
dotnet_diagnostic.CA1825.severity = warning
175-
176-
# CA1822: Mark members as static
177-
dotnet_diagnostic.CA1822.severity = warning
178-
179-
# CA2208: Instantiate argument exceptions correctly
180-
dotnet_diagnostic.CA2208.severity = warning
181-
182-
# CA1810: Initialize reference type static fields inline
183-
dotnet_diagnostic.CA1810.severity = warning
184-
185-
# CA1816: Dispose methods should call SuppressFinalize
186-
dotnet_diagnostic.CA1816.severity = warning
156+
resharper_csharp_instance_members_qualify_members = field
187157

188158
# IDE0005: Using directive is unnecessary.
189159
dotnet_diagnostic.IDE0005.severity = warning
@@ -194,4 +164,10 @@ dotnet_diagnostic.RCS1037.severity = error
194164
# RCS1036: Remove redundant empty line.
195165
dotnet_diagnostic.RCS1036.severity = error
196166

197-
[resharper_]xml_space_before_self_closing = true
167+
xml_space_before_self_closing = true
168+
169+
resharper_arrange_object_creation_when_type_not_evident_highlighting = none
170+
171+
resharper_unused_auto_property_accessor_global_highlighting = none
172+
173+
resharper_unused_method_return_value_global_highlighting = none

.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

src/GitVersion.App.Tests/ArgumentParserTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public void UpdateAssemblyInfoWithRelativeFilename()
361361
var targetPath = FileSystemHelper.Path.Combine(repo.RepositoryPath, "subdir1", "subdir2");
362362
this.fileSystem.Directory.CreateDirectory(targetPath);
363363

364-
var arguments = this.argumentParser.ParseArguments($"-targetpath {targetPath} -updateAssemblyInfo ..\\..\\CommonAssemblyInfo.cs");
364+
var arguments = this.argumentParser.ParseArguments($@"-targetpath {targetPath} -updateAssemblyInfo ..\..\CommonAssemblyInfo.cs");
365365
arguments.UpdateAssemblyInfo.ShouldBe(true);
366366
arguments.UpdateAssemblyInfoFileName.Count.ShouldBe(1);
367367
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => FileSystemHelper.Path.GetFileName(x).Equals("CommonAssemblyInfo.cs"));
@@ -604,7 +604,7 @@ public void EnsureAssemblyInfoFalse()
604604
[Test]
605605
public void DynamicRepoLocation()
606606
{
607-
var arguments = this.argumentParser.ParseArguments(@"-dynamicRepoLocation /tmp/foo");
607+
var arguments = this.argumentParser.ParseArguments("-dynamicRepoLocation /tmp/foo");
608608
arguments.ClonePath.ShouldBe("/tmp/foo");
609609
}
610610

src/GitVersion.App.Tests/ExecCmdLineArgumentTest.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ public void LogPathContainsForwardSlash()
2525
fixture.MakeATaggedCommit("1.2.3");
2626
fixture.MakeACommit();
2727

28-
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, @" /l ""/tmp/path""", false);
28+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath,
29+
""" /l "/tmp/path" """, false);
2930

3031
result.ExitCode.ShouldBe(0);
3132
result.Output.ShouldNotBeNull();
32-
result.Output.ShouldContain(@"""MajorMinorPatch"": ""1.2.4""");
33+
result.Output.ShouldContain(
34+
"""
35+
"MajorMinorPatch": "1.2.4"
36+
""");
3337
}
3438

3539
[Theory]
@@ -42,7 +46,8 @@ public void CheckBuildServerVerbosityConsole(string verbosityArg, string expecte
4246
fixture.MakeATaggedCommit("1.2.3");
4347
fixture.MakeACommit();
4448

45-
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, $@" {verbosityArg} -output buildserver /l ""/tmp/path""", false);
49+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath,
50+
$""" {verbosityArg} -output buildserver /l "/tmp/path" """, false);
4651

4752
result.ExitCode.ShouldBe(0);
4853
result.Output.ShouldNotBeNull();

src/GitVersion.App.Tests/HelpWriterTests.cs

+2-2
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

@@ -51,7 +51,7 @@ public void AllArgsAreInHelp()
5151
.ShouldBeEmpty();
5252
}
5353

54-
private static bool IsNotInHelp(IReadOnlyDictionary<string, string> lookup, string propertyName, string helpText)
54+
private static bool IsNotInHelp(Dictionary<string, string> lookup, string propertyName, string helpText)
5555
{
5656
if (lookup.TryGetValue(propertyName, out var value))
5757
return !helpText.Contains(value);

src/GitVersion.App.Tests/Helpers/ExecutionResults.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace GitVersion.App.Tests;
66

77
public class ExecutionResults(int exitCode, string? output, string? logContents = null)
88
{
9-
public int ExitCode { get; init; } = exitCode;
10-
public string? Output { get; init; } = output;
9+
public int ExitCode { get; } = exitCode;
10+
public string? Output { get; } = output;
1111
public string? Log { get; init; } = logContents;
1212

1313
public GitVersionVariables? OutputVariables

src/GitVersion.App.Tests/Helpers/ProgramFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void WithEnv(params KeyValuePair<string, string>[] envs)
4949

5050
public Task<ExecutionResults> Run(string arg)
5151
{
52-
var args = arg.Split([' '], StringSplitOptions.RemoveEmptyEntries).ToArray();
52+
var args = arg.Split([' '], StringSplitOptions.RemoveEmptyEntries);
5353
return Run(args);
5454
}
5555

src/GitVersion.App.Tests/UpdateWixVersionFileTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void WixVersionFileVarCountTest()
3939
var gitVersionVarsInWix = GetGitVersionVarsInWixFile(FileSystemHelper.Path.Combine(fixture.RepositoryPath, this.wixVersionFileName));
4040
var gitVersionVars = GitVersionVariables.AvailableVariables;
4141

42-
Assert.That(gitVersionVarsInWix, Has.Count.EqualTo(gitVersionVars.Count()));
42+
Assert.That(gitVersionVarsInWix, Has.Count.EqualTo(gitVersionVars.Count));
4343
}
4444

4545
[Test]

src/GitVersion.App.Tests/VersionWriterTests.cs

+3-3
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
{
@@ -48,7 +48,7 @@ public void WriteVersionShouldWriteFileVersionWithPrereleaseTag()
4848
private static Assembly GenerateAssembly(Version fileVersion, string prereleaseInfo)
4949
{
5050
var attribute = typeof(AssemblyInformationalVersionAttribute);
51-
var csharpCode = $@"[assembly: {attribute.FullName}(""{fileVersion + prereleaseInfo}"")]";
51+
var csharpCode = $"""[assembly: {attribute.FullName}("{fileVersion + prereleaseInfo}")]""";
5252
var compilation = CSharpCompilation.Create("test-asm")
5353
.WithOptions(new(OutputKind.DynamicallyLinkedLibrary))
5454
.AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))

src/GitVersion.App/ArgumentParser.cs

+20-30
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,23 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
177177
var couldNotParseMessage = $"Could not parse command line parameter '{name}'.";
178178

179179
// If we've reached through all argument switches without a match, we can relatively safely assume that the first argument isn't a switch, but the target path.
180-
if (parseEnded)
180+
if (!parseEnded) throw new WarningException(couldNotParseMessage);
181+
if (name?.StartsWith('/') == true)
181182
{
182-
if (name?.StartsWith('/') == true)
183-
{
184-
if (FileSystemHelper.Path.DirectorySeparatorChar == '/' && name.IsValidPath())
185-
{
186-
arguments.TargetPath = name;
187-
return;
188-
}
189-
}
190-
else if (!name.IsSwitchArgument())
183+
if (FileSystemHelper.Path.DirectorySeparatorChar == '/' && name.IsValidPath())
191184
{
192185
arguments.TargetPath = name;
193186
return;
194187
}
195-
196-
couldNotParseMessage += " If it is the target path, make sure it exists.";
188+
}
189+
else if (!name.IsSwitchArgument())
190+
{
191+
arguments.TargetPath = name;
192+
return;
197193
}
198194

195+
couldNotParseMessage += " If it is the target path, make sure it exists.";
196+
199197
throw new WarningException(couldNotParseMessage);
200198
}
201199

@@ -289,13 +287,9 @@ private static bool ParseSwitches(Arguments arguments, string? name, IReadOnlyLi
289287
return true;
290288
}
291289

292-
if (name.IsSwitch("updatewixversionfile"))
293-
{
294-
arguments.UpdateWixVersionFile = true;
295-
return true;
296-
}
297-
298-
return false;
290+
if (!name.IsSwitch("updatewixversionfile")) return false;
291+
arguments.UpdateWixVersionFile = true;
292+
return true;
299293
}
300294

301295
private static bool ParseConfigArguments(Arguments arguments, string? name, IReadOnlyList<string>? values, string? value)
@@ -357,14 +351,10 @@ private static bool ParseRemoteArguments(Arguments arguments, string? name, IRea
357351
return true;
358352
}
359353

360-
if (name.IsSwitch("b"))
361-
{
362-
EnsureArgumentValueCount(values);
363-
arguments.TargetBranch = value;
364-
return true;
365-
}
366-
367-
return false;
354+
if (!name.IsSwitch("b")) return false;
355+
EnsureArgumentValueCount(values);
356+
arguments.TargetBranch = value;
357+
return true;
368358
}
369359

370360
private static void ParseShowVariable(Arguments arguments, string? value, string? name)
@@ -379,7 +369,7 @@ private static void ParseShowVariable(Arguments arguments, string? value, string
379369
if (versionVariable == null)
380370
{
381371
var message = $"{name} requires a valid version variable. Available variables are:{FileSystemHelper.Path.NewLine}" +
382-
string.Join(", ", availableVariables.Select(x => string.Concat("'", x, "'")));
372+
string.Join(", ", availableVariables.Select(x => $"'{x}'"));
383373
throw new WarningException(message);
384374
}
385375

@@ -562,14 +552,14 @@ private static void EnsureArgumentValueCount(IReadOnlyList<string>? values)
562552
}
563553
}
564554

565-
private static NameValueCollection CollectSwitchesAndValuesFromArguments(IList<string> namedArguments, out bool firstArgumentIsSwitch)
555+
private static NameValueCollection CollectSwitchesAndValuesFromArguments(string[] namedArguments, out bool firstArgumentIsSwitch)
566556
{
567557
firstArgumentIsSwitch = true;
568558
var switchesAndValues = new NameValueCollection();
569559
string? currentKey = null;
570560
var argumentRequiresValue = false;
571561

572-
for (var i = 0; i < namedArguments.Count; ++i)
562+
for (var i = 0; i < namedArguments.Length; ++i)
573563
{
574564
var arg = namedArguments[i];
575565

src/GitVersion.App/FileSystemGlobbing/DirectoryInfoGlobbingWrapper.cs

+20-22
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,28 @@ this.directoryInfo.Parent is null
3636

3737
public override IEnumerable<Microsoft.Extensions.FileSystemGlobbing.Abstractions.FileSystemInfoBase> EnumerateFileSystemInfos()
3838
{
39-
if (this.directoryInfo.Exists)
39+
if (!this.directoryInfo.Exists) yield break;
40+
IEnumerable<IFileSystemInfo> fileSystemInfos;
41+
try
4042
{
41-
IEnumerable<IFileSystemInfo> fileSystemInfos;
42-
try
43-
{
44-
fileSystemInfos = this.directoryInfo.EnumerateFileSystemInfos(
45-
"*",
46-
SearchOption.TopDirectoryOnly
47-
);
48-
}
49-
catch (DirectoryNotFoundException)
50-
{
51-
yield break;
52-
}
43+
fileSystemInfos = this.directoryInfo.EnumerateFileSystemInfos(
44+
"*",
45+
SearchOption.TopDirectoryOnly
46+
);
47+
}
48+
catch (DirectoryNotFoundException)
49+
{
50+
yield break;
51+
}
5352

54-
foreach (var fileSystemInfo in fileSystemInfos)
53+
foreach (var fileSystemInfo in fileSystemInfos)
54+
{
55+
yield return fileSystemInfo switch
5556
{
56-
yield return fileSystemInfo switch
57-
{
58-
IDirectoryInfo info => new DirectoryInfoGlobbingWrapper(this.fileSystem, info),
59-
IFileInfo info => new FileInfoGlobbingWrapper(this.fileSystem, info),
60-
_ => new FileSystemInfoGlobbingWrapper(this.fileSystem, fileSystemInfo),
61-
};
62-
}
57+
IDirectoryInfo info => new DirectoryInfoGlobbingWrapper(this.fileSystem, info),
58+
IFileInfo info => new FileInfoGlobbingWrapper(this.fileSystem, info),
59+
_ => new FileSystemInfoGlobbingWrapper(this.fileSystem, fileSystemInfo)
60+
};
6361
}
6462
}
6563

@@ -82,7 +80,7 @@ this.directoryInfo.Parent is null
8280
{
8381
{ Length: 1 } => new DirectoryInfoGlobbingWrapper(this.fileSystem, dirs[0], parentPath),
8482
{ Length: 0 } => null,
85-
_ => throw new InvalidOperationException($"More than one sub directories are found under {this.directoryInfo.FullName} with name {path}."),
83+
_ => throw new InvalidOperationException($"More than one sub directories are found under {this.directoryInfo.FullName} with name {path}.")
8684
};
8785
}
8886

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

0 commit comments

Comments
 (0)