Skip to content

Commit 4f61da0

Browse files
committed
refactors: use readonly backing fields
Refactors constructors to use readonly backing fields for injected dependencies. Adds .editorconfig settings for .NET code style and updates existing settings.
1 parent 48913f9 commit 4f61da0

File tree

14 files changed

+63
-55
lines changed

14 files changed

+63
-55
lines changed

.editorconfig

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
root = true
12
# http://editorconfig.org
23

34
# top-most EditorConfig file
4-
root = true
55

66
[*]
77
indent_style = space
@@ -10,6 +10,12 @@ end_of_line = lf
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
1212

13+
# Microsoft .NET properties
14+
dotnet_style_qualification_for_event = false:none
15+
dotnet_style_qualification_for_field = false:none
16+
dotnet_style_qualification_for_method = false:none
17+
dotnet_style_qualification_for_property = false:none
18+
1319
[*.yml]
1420
indent_size = 2
1521

@@ -156,18 +162,18 @@ resharper_csharp_align_multiline_parameter = true
156162
resharper_csharp_instance_members_qualify_members = field
157163

158164
# IDE0005: Using directive is unnecessary.
159-
dotnet_diagnostic.IDE0005.severity = warning
165+
dotnet_diagnostic.ide0005.severity = warning
160166

161167
# RCS1037: Remove trailing white-space.
162-
dotnet_diagnostic.RCS1037.severity = error
168+
dotnet_diagnostic.rcs1037.severity = error
163169

164170
# RCS1036: Remove redundant empty line.
165-
dotnet_diagnostic.RCS1036.severity = error
171+
dotnet_diagnostic.rcs1036.severity = error
166172

167173
xml_space_before_self_closing = true
168174

169175
resharper_arrange_object_creation_when_type_not_evident_highlighting = none
170176

171177
resharper_unused_auto_property_accessor_global_highlighting = none
172178

173-
resharper_unused_method_return_value_global_highlighting = none
179+
resharper_unused_method_return_value_global_highlighting = none

new-cli/GitVersion.Calculation/CalculateCommand.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ public record CalculateSettings : GitVersionSettings;
99
[Command("calculate", "Calculates the version object from the git history.")]
1010
public class CalculateCommand(ILogger logger, IService service, IGitRepository repository) : ICommand<CalculateSettings>
1111
{
12-
private readonly ILogger logger = logger.NotNull();
13-
private readonly IService service = service.NotNull();
14-
private readonly IGitRepository repository = repository.NotNull();
12+
private readonly ILogger _logger = logger.NotNull();
13+
private readonly IService _service = service.NotNull();
14+
private readonly IGitRepository _repository = repository.NotNull();
1515

1616
public Task<int> InvokeAsync(CalculateSettings settings, CancellationToken cancellationToken = default)
1717
{
18-
var value = service.Call();
18+
var value = _service.Call();
1919
if (settings.WorkDir != null)
2020
{
21-
this.repository.DiscoverRepository(settings.WorkDir.FullName);
22-
var branches = this.repository.Branches.ToList();
23-
this.logger.LogInformation("Command : 'calculate', LogFile : '{logFile}', WorkDir : '{workDir}' ",
21+
_repository.DiscoverRepository(settings.WorkDir.FullName);
22+
var branches = _repository.Branches.ToList();
23+
_logger.LogInformation("Command : 'calculate', LogFile : '{logFile}', WorkDir : '{workDir}' ",
2424
settings.LogFile, settings.WorkDir);
25-
this.logger.LogInformation("Found {count} branches", branches.Count);
25+
_logger.LogInformation("Found {count} branches", branches.Count);
2626
}
2727

2828
return Task.FromResult(value);

new-cli/GitVersion.Cli.Generator/TypeVisitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ internal class TypeVisitor(Func<INamedTypeSymbol, bool> searchQuery, Cancellatio
55
{
66
private readonly HashSet<INamedTypeSymbol> _exportedTypes = new(SymbolEqualityComparer.Default);
77

8-
public ImmutableArray<INamedTypeSymbol> GetResults() => [.. this._exportedTypes];
8+
public ImmutableArray<INamedTypeSymbol> GetResults() => [.. _exportedTypes];
99

1010
public override void VisitAssembly(IAssemblySymbol symbol)
1111
{
@@ -28,7 +28,7 @@ public override void VisitNamedType(INamedTypeSymbol type)
2828

2929
if (searchQuery(type))
3030
{
31-
this._exportedTypes.Add(type);
31+
_exportedTypes.Add(type);
3232
}
3333
}
3434
}

new-cli/GitVersion.Cli/SystemCommandline/GitVersionAppRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public Task<int> RunAsync(string[] args, CancellationToken cancellationToken)
2323
return parseResult.InvokeAsync(cancellationToken: cancellationToken);
2424
}
2525

26-
// Note: there are 2 locations to watch for dotnet-suggest
26+
// Note: there are 2 locations to watch for the dotnet-suggest tool
2727
// - sentinel file: $env:TEMP\system-commandline-sentinel-files\ and
2828
// - registration file: $env:LOCALAPPDATA\.dotnet-suggest-registration.txt or $HOME/.dotnet-suggest-registration.txt
2929

new-cli/GitVersion.Configuration/ConfigCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public record ConfigSettings : GitVersionSettings;
88
[Command("config", "Manages the GitVersion configuration file.")]
99
public class ConfigCommand(ILogger logger, IService service) : ICommand<ConfigSettings>
1010
{
11-
private readonly ILogger logger = logger.NotNull();
12-
private readonly IService service = service.NotNull();
11+
private readonly ILogger _logger = logger.NotNull();
12+
private readonly IService _service = service.NotNull();
1313

1414
public Task<int> InvokeAsync(ConfigSettings settings, CancellationToken cancellationToken = default)
1515
{
16-
var value = service.Call();
17-
logger.LogInformation($"Command : 'config', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
16+
var value = _service.Call();
17+
_logger.LogInformation($"Command : 'config', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
1818
return Task.FromResult(value);
1919
}
2020
}

new-cli/GitVersion.Configuration/Init/ConfigInitCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public record ConfigInitSettings : ConfigSettings;
88
[Command<ConfigCommand>("init", "Inits the configuration for current repository.")]
99
public class ConfigInitCommand(ILogger logger, IService service) : ICommand<ConfigInitSettings>
1010
{
11-
private readonly ILogger logger = logger.NotNull();
12-
private readonly IService service = service.NotNull();
11+
private readonly ILogger _logger = logger.NotNull();
12+
private readonly IService _service = service.NotNull();
1313

1414
public Task<int> InvokeAsync(ConfigInitSettings settings, CancellationToken cancellationToken = default)
1515
{
16-
var value = service.Call();
17-
logger.LogInformation($"Command : 'config init', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
16+
var value = _service.Call();
17+
_logger.LogInformation($"Command : 'config init', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
1818
return Task.FromResult(value);
1919
}
2020
}

new-cli/GitVersion.Configuration/Show/ConfigShowCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public record ConfigShowSettings : ConfigSettings;
88
[Command<ConfigCommand>("show", "Shows the effective configuration.")]
99
public class ConfigShowCommand(ILogger logger, IService service) : ICommand<ConfigShowSettings>
1010
{
11-
private readonly ILogger logger = logger.NotNull();
12-
private readonly IService service = service.NotNull();
11+
private readonly ILogger _logger = logger.NotNull();
12+
private readonly IService _service = service.NotNull();
1313

1414
public Task<int> InvokeAsync(ConfigShowSettings settings, CancellationToken cancellationToken = default)
1515
{
16-
var value = service.Call();
17-
logger.LogInformation($"Command : 'config show', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
16+
var value = _service.Call();
17+
_logger.LogInformation($"Command : 'config show', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
1818
return Task.FromResult(value);
1919
}
2020
}

new-cli/GitVersion.Core/Extensions/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Extensions.DependencyInjection;
33
using Microsoft.Extensions.Logging;
44
using Serilog;
5+
using ILogger = Serilog.ILogger;
56

67
namespace GitVersion.Extensions;
78

@@ -23,6 +24,7 @@ public static IServiceCollection RegisterLogging(this IServiceCollection service
2324
var logger = CreateLogger();
2425
builder.AddSerilog(logger, dispose: true);
2526
});
27+
2628
return services;
2729
}
2830

@@ -37,9 +39,9 @@ private static Serilog.Core.Logger CreateLogger()
3739
// serilog.sinks.map will defer the configuration of the sink to be on demand,
3840
// allowing us to look at the properties set by the enricher to set the path appropriately
3941
.WriteTo.Console()
40-
.WriteTo.Map(LoggingEnricher.LogFilePathPropertyName, (logFilePath, wt) =>
42+
.WriteTo.Map(LoggingEnricher.LogFilePathPropertyName, (logFilePath, sinkConfiguration) =>
4143
{
42-
if (!string.IsNullOrEmpty(logFilePath)) wt.File(logFilePath);
44+
if (!string.IsNullOrEmpty(logFilePath)) sinkConfiguration.File(logFilePath);
4345
}, 1)
4446
.CreateLogger();
4547
return logger;

new-cli/GitVersion.Core/Infrastructure/LoggingEnricher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
2020
// we won't have the setting, so a default value for the log file will be required
2121
LogEventProperty logFilePathProperty;
2222

23-
if (this._cachedLogFilePathProperty != null && Path.Equals(this._cachedLogFilePath))
23+
if (_cachedLogFilePathProperty != null && Path.Equals(_cachedLogFilePath))
2424
{
2525
// The Path hasn't changed, so let's use the cached property
26-
logFilePathProperty = this._cachedLogFilePathProperty;
26+
logFilePathProperty = _cachedLogFilePathProperty;
2727
}
2828
else
2929
{
3030
// We've got a new path for the log. Let's create a new property
3131
// and cache it for future log events to use
32-
this._cachedLogFilePath = Path;
33-
this._cachedLogFilePathProperty = logFilePathProperty = propertyFactory.CreateProperty(LogFilePathPropertyName, Path);
32+
_cachedLogFilePath = Path;
33+
_cachedLogFilePathProperty = logFilePathProperty = propertyFactory.CreateProperty(LogFilePathPropertyName, Path);
3434
}
3535

3636
logEvent.AddPropertyIfAbsent(logFilePathProperty);

new-cli/GitVersion.Normalization/NormalizeCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public record NormalizeSettings : GitVersionSettings;
88
[Command("normalize", "Normalizes the git repository for GitVersion calculations.")]
99
public class NormalizeCommand(ILogger logger, IService service) : ICommand<NormalizeSettings>
1010
{
11-
private readonly ILogger logger = logger.NotNull();
12-
private readonly IService service = service.NotNull();
11+
private readonly ILogger _logger = logger.NotNull();
12+
private readonly IService _service = service.NotNull();
1313

1414
public Task<int> InvokeAsync(NormalizeSettings settings, CancellationToken cancellationToken = default)
1515
{
16-
var value = service.Call();
17-
logger.LogInformation($"Command : 'normalize', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
16+
var value = _service.Call();
17+
_logger.LogInformation($"Command : 'normalize', LogFile : '{settings.LogFile}', WorkDir : '{settings.WorkDir}' ");
1818
return Task.FromResult(value);
1919
}
2020
}

0 commit comments

Comments
 (0)