Skip to content

Commit ff01e15

Browse files
committed
feat: Core project now enabled nullable reftypes.
1 parent e9ab260 commit ff01e15

23 files changed

+44
-75
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<LangVersion>latest</LangVersion>
5+
<Nullable>enable</Nullable>
56
<Platforms>AnyCPU</Platforms>
67
<DebugSymbols>true</DebugSymbols>
78
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

RelaxVersioner.Core.Tests/RelaxVersioner.Core.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Nullable>enable</Nullable>
54
<TargetFrameworks>net48;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
65
<NoWarn>$(NoWarn);NU5104</NoWarn>
76
</PropertyGroup>

RelaxVersioner.Core/Analyzer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
////////////////////////////////////////////////////////////////////////////////////////
99

10-
#nullable enable
11-
1210
using System.Collections.Generic;
1311
using System.Linq;
1412
using System.Threading;

RelaxVersioner.Core/Logger.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
////////////////////////////////////////////////////////////////////////////////////////
99

10-
#nullable enable
11-
1210
using System;
1311
using System.ComponentModel;
1412
using System.IO;

RelaxVersioner.Core/Processor.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ namespace RelaxVersioner;
2525

2626
public sealed class ProcessorContext
2727
{
28-
public string ProjectDirectory;
29-
public string OutputPath;
30-
public string Language;
31-
public string Namespace;
32-
public string TargetFramework;
33-
public string TargetFrameworkIdentity;
34-
public string TargetFrameworkVersion;
35-
public string TargetFrameworkProfile;
28+
public string ProjectDirectory = null!;
29+
public string OutputPath = null!;
30+
public string Language = null!;
31+
public string? Namespace;
32+
public string? TargetFramework;
33+
public string? TargetFrameworkIdentity;
34+
public string? TargetFrameworkVersion;
35+
public string? TargetFrameworkProfile;
3636
public bool GenerateStatic;
37-
public string BuildIdentifier;
38-
public string PropertiesPath;
39-
public string TextFormat;
40-
public string ReplaceInputPath;
41-
public string BracketStart;
42-
public string BracketEnd;
37+
public string? BuildIdentifier;
38+
public string? PropertiesPath;
39+
public string TextFormat = "{versionLabel}";
40+
public string? ReplaceInputPath;
41+
public string BracketStart = "{";
42+
public string BracketEnd = "}";
4343
public bool IsDryRun;
4444
public bool IsQuietOnStandardOutput;
4545
public bool CheckWorkingDirectoryStatus;
46-
public string[] NpmPrefixes;
46+
public string[]? NpmPrefixes;
4747
}
4848

4949
public sealed class Processor
@@ -66,8 +66,8 @@ private static async Task<Result> WriteVersionSourceFileAsync(
6666
Logger logger,
6767
WriteProviderBase writeProvider,
6868
ProcessorContext context,
69-
StructuredRepository repository,
70-
Branch targetBranch,
69+
StructuredRepository? repository,
70+
Branch? targetBranch,
7171
DateTimeOffset generated,
7272
CancellationToken ct)
7373
{
@@ -107,15 +107,15 @@ static string FormatSignature(Signature? sig) => sig is { } s ?
107107
(!string.IsNullOrWhiteSpace(context.PropertiesPath) &&
108108
File.Exists(context.PropertiesPath)) ?
109109
XDocument.Load(context.PropertiesPath).
110-
Root.Elements().
111-
ToDictionary(e => e.Name.LocalName, e => (object)e.Value) :
112-
new Dictionary<string, object>();
110+
Root!.Elements().
111+
ToDictionary(e => e.Name.LocalName, e => (object?)e.Value) :
112+
new Dictionary<string, object?>();
113113

114114
var versionLabel = await versionLabelTask;
115115

116116
var shortVersion = versionLabel.ToString(3);
117117

118-
foreach (var entry in new (string key, object value)[]
118+
foreach (var entry in new (string key, object? value)[]
119119
{
120120
("generated", generated),
121121
("branch", targetBranch),

RelaxVersioner.Core/Result.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
////////////////////////////////////////////////////////////////////////////////////////
99

10-
#nullable enable
11-
1210
using System;
1311

1412
namespace RelaxVersioner;
@@ -22,19 +20,19 @@ public readonly struct Result
2220
public readonly string EpochIntDateVersion;
2321
public readonly string CommitId;
2422
public readonly string[] Tags;
25-
public readonly string Branch;
23+
public readonly string? Branch;
2624
public readonly DateTimeOffset Date;
2725
public readonly string Author;
2826
public readonly string Committer;
29-
public readonly string Subject;
30-
public readonly string Body;
27+
public readonly string? Subject;
28+
public readonly string? Body;
3129

3230
public Result(Version version, string shortVersion, Version safeVersion,
3331
string intDateVersion, string epochIntDateVersion,
3432
string commitId,
35-
string branch, string[] tags, DateTimeOffset date,
33+
string? branch, string[] tags, DateTimeOffset date,
3634
string author, string committer,
37-
string subject, string body)
35+
string? subject, string? body)
3836
{
3937
this.Version = version;
4038
this.ShortVersion = shortVersion;

RelaxVersioner.Core/Rule.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
////////////////////////////////////////////////////////////////////////////////////////
99

10-
#nullable enable
11-
1210
namespace RelaxVersioner;
1311

1412
internal sealed class Rule

RelaxVersioner.Core/Utilities.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ public static Dictionary<string, WriteProviderBase> GetWriteProviders()
4949
return typeof(Utilities).Assembly.
5050
GetTypes().
5151
Where(type => type.IsSealed && type.IsClass && typeof(WriteProviderBase).IsAssignableFrom(type)).
52-
Select(type => (WriteProviderBase)Activator.CreateInstance(type)).
53-
ToDictionary(writer => writer.Language, StringComparer.InvariantCultureIgnoreCase);
52+
Select(type => (WriteProviderBase?)Activator.CreateInstance(type)).
53+
Where(writer => writer != null).
54+
ToDictionary(writer => writer!.Language, writer => writer!, StringComparer.InvariantCultureIgnoreCase);
5455
}
5556

56-
private static async Task<T> TraversePathToRootAsync<T>(
57-
string candidatePath, Func<string, Task<T>> action)
57+
private static async Task<T?> TraversePathToRootAsync<T>(
58+
string candidatePath, Func<string, Task<T?>> action)
5859
where T : class
5960
{
6061
var path = Path.GetFullPath(candidatePath).
@@ -84,7 +85,7 @@ public static string GetDirectoryNameWithoutTrailingSeparator(string path) =>
8485
public static string GetDirectoryNameWithTrailingSeparator(string path) =>
8586
GetDirectoryNameWithoutTrailingSeparator(path) + Path.DirectorySeparatorChar;
8687

87-
public static async Task<StructuredRepository> OpenRepositoryAsync(
88+
public static async Task<StructuredRepository?> OpenRepositoryAsync(
8889
Logger logger, string candidatePath)
8990
{
9091
var repository = await TraversePathToRootAsync(candidatePath, async path =>
@@ -117,11 +118,12 @@ public static TValue GetValue<TKey, TValue>(
117118
this Dictionary<TKey, TValue> dictionary,
118119
TKey key,
119120
TValue defaultValue)
121+
where TKey : notnull
120122
{
121-
Debug.Assert(dictionary != null);
122-
Debug.Assert(key != null);
123+
if (dictionary == null)
124+
throw new ArgumentNullException(nameof(dictionary));
123125

124-
if (dictionary.TryGetValue(key, out TValue value) == false)
126+
if (dictionary.TryGetValue(key, out TValue? value) == false)
125127
{
126128
value = defaultValue;
127129
}
@@ -163,7 +165,7 @@ public static IEnumerable<XElement> LoadRuleSets(string candidatePath)
163165
var rulePath = Path.Combine(path, "RelaxVersioner.rules");
164166
if (File.Exists(rulePath))
165167
{
166-
XElement element = null;
168+
XElement? element = null;
167169
try
168170
{
169171
element = XElement.Load(rulePath);
@@ -200,7 +202,7 @@ from language in rules.Elements("Language")
200202
where !string.IsNullOrWhiteSpace(language?.Value)
201203
select new { language, rules }).
202204
GroupBy(
203-
entry => entry.language.Value.Trim(),
205+
entry => entry.language.Value!.Trim(),
204206
entry => entry.rules,
205207
StringComparer.InvariantCultureIgnoreCase).
206208
ToDictionary(
@@ -221,7 +223,7 @@ public static IEnumerable<Rule> AggregateRules(XElement wrules)
221223
let name = rule.Attribute("name")
222224
let key = rule.Attribute("key")
223225
where !string.IsNullOrWhiteSpace(name?.Value)
224-
select new Rule(name.Value.Trim(), key?.Value.Trim(), rule.Value.Trim()));
226+
select new Rule(name!.Value.Trim(), key?.Value?.Trim() ?? "", rule.Value.Trim()));
225227
}
226228

227229
public static XElement GetDefaultRuleSet()
@@ -230,7 +232,7 @@ public static XElement GetDefaultRuleSet()
230232
using (var stream = type.Assembly.GetManifestResourceStream(
231233
type, "DefaultRuleSet.rules"))
232234
{
233-
return XElement.Load(stream);
235+
return XElement.Load(stream!);
234236
}
235237
}
236238

RelaxVersioner.Core/Version.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
////////////////////////////////////////////////////////////////////////////////////////
99

10-
#nullable enable
11-
1210
using System;
1311
using System.Collections.Generic;
1412
using System.Linq;

RelaxVersioner.Core/Writers/CPlusPlusCliSourceCodeWriteProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//
88
////////////////////////////////////////////////////////////////////////////////////////
99

10-
#nullable enable
11-
1210
namespace RelaxVersioner.Writers;
1311

1412
internal sealed class CPlusPlusCliSourceCodeWriteProvider : SourceCodeWriteProviderBase

0 commit comments

Comments
 (0)