Skip to content

Commit 1138f26

Browse files
authored
nullable warnings (#568)
* annotate code with ReSharper nullable attributes * add missing null-checks / cases * extract update checker form NugetWindow + rename asmdef
1 parent 0d2e98f commit 1138f26

File tree

70 files changed

+1654
-856
lines changed

Some content is hidden

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

70 files changed

+1654
-856
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ dotnet_diagnostic.sa1101.severity=none
142142
dotnet_diagnostic.SA1408.severity=none
143143
dotnet_diagnostic.SA1407.severity=none
144144
dotnet_diagnostic.SA1118.severity=none
145+
dotnet_diagnostic.CA1002.severity=none
146+
dotnet_diagnostic.CA1031.severity=none
147+
dotnet_diagnostic.CA1062.severity=none
148+
dotnet_diagnostic.CA2234.severity=none
149+
dotnet_diagnostic.CA2007.severity=none
150+
dotnet_diagnostic.CA1056.severity=none # URI-like properties should not be strings
151+
dotnet_diagnostic.CA1054.severity=none # URI parameters should not be strings
145152
# ReSharper properties
146153
resharper_wrap_after_declaration_lpar=true
147154

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
*.log
44
**/.idea
5+
6+
src/NuGetForUnity/Editor/NuGetForUnity.csproj*

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<!-- To support Unity 2018.4 with .NET Framework we can not 'eayily' use features of C# higher than 7.3 -->
3+
<!-- To support Unity 2018.4 with .NET Framework we can not 'easily' use features of C# higher than 7.3 -->
44
<LangVersion>7.3</LangVersion>
55
</PropertyGroup>
66

File renamed without changes.

src/NuGetForUnity.Cli/NuGetForUnity.Cli.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@
3131
<Compile Remove="..\NuGetForUnity\Editor\OnLoadNugetPackageRestorer.cs" />
3232
<Compile Remove="..\NuGetForUnity\Editor\UnityPreImportedLibraryResolver.cs" />
3333
</ItemGroup>
34+
<ItemGroup>
35+
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" />
36+
</ItemGroup>
3437
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=configuration/@EntryIndexedValue">False</s:Boolean>
3+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">False</s:Boolean>
4+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models/@EntryIndexedValue">False</s:Boolean>
5+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=packagesource/@EntryIndexedValue">False</s:Boolean>
6+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ui/@EntryIndexedValue">False</s:Boolean>
7+
</wpf:ResourceDictionary>

src/NuGetForUnity/Editor/Configuration/ConfigurationManager.cs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Runtime.CompilerServices;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using JetBrains.Annotations;
78
using NugetForUnity.Helper;
89
using NugetForUnity.Models;
910
using NugetForUnity.PackageSource;
@@ -21,11 +22,13 @@ public static class ConfigurationManager
2122
/// <summary>
2223
/// The <see cref="INugetPackageSource" /> to use.
2324
/// </summary>
25+
[CanBeNull]
2426
private static INugetPackageSource activePackageSource;
2527

2628
/// <summary>
2729
/// Backing field for the NuGet.config file.
2830
/// </summary>
31+
[CanBeNull]
2932
private static NugetConfigFile nugetConfigFile;
3033

3134
static ConfigurationManager()
@@ -40,11 +43,13 @@ static ConfigurationManager()
4043
/// <remarks>
4144
/// <see cref="NugetConfigFile" />.
4245
/// </remarks>
46+
[NotNull]
4347
public static string NugetConfigFilePath { get; }
4448

4549
/// <summary>
4650
/// Gets the loaded NuGet.config file that holds the settings for NuGet.
4751
/// </summary>
52+
[NotNull]
4853
public static NugetConfigFile NugetConfigFile
4954
{
5055
get
@@ -54,13 +59,15 @@ public static NugetConfigFile NugetConfigFile
5459
LoadNugetConfigFile();
5560
}
5661

62+
Debug.Assert(nugetConfigFile != null, nameof(nugetConfigFile) + " != null");
5763
return nugetConfigFile;
5864
}
5965
}
6066

6167
/// <summary>
6268
/// Gets the path to the directory containing the NuGet.config file.
6369
/// </summary>
70+
[NotNull]
6471
internal static string NugetConfigFileDirectoryPath { get; }
6572

6673
/// <summary>
@@ -70,6 +77,24 @@ public static NugetConfigFile NugetConfigFile
7077
/// </summary>
7178
internal static bool IsVerboseLoggingEnabled => nugetConfigFile?.Verbose ?? false;
7279

80+
/// <summary>
81+
/// Gets the <see cref="INugetPackageSource" /> to use.
82+
/// </summary>
83+
[NotNull]
84+
private static INugetPackageSource ActivePackageSource
85+
{
86+
get
87+
{
88+
if (activePackageSource is null)
89+
{
90+
LoadNugetConfigFile();
91+
}
92+
93+
Debug.Assert(activePackageSource != null, nameof(activePackageSource) + " != null");
94+
return activePackageSource;
95+
}
96+
}
97+
7398
/// <summary>
7499
/// Loads the NuGet.config file.
75100
/// </summary>
@@ -93,7 +118,7 @@ public static void LoadNugetConfigFile()
93118
{
94119
if (readingSources)
95120
{
96-
if (arg.StartsWith("-"))
121+
if (arg.StartsWith("-", StringComparison.Ordinal))
97122
{
98123
readingSources = false;
99124
}
@@ -138,14 +163,16 @@ public static void LoadNugetConfigFile()
138163
/// <param name="numberToSkip">The number of packages to skip before fetching.</param>
139164
/// <param name="cancellationToken">Token that can be used to cancel the asynchronous task.</param>
140165
/// <returns>The list of available packages.</returns>
166+
[NotNull]
167+
[ItemNotNull]
141168
public static Task<List<INugetPackage>> Search(
142-
string searchTerm = "",
169+
[NotNull] string searchTerm = "",
143170
bool includePrerelease = false,
144171
int numberToGet = 15,
145172
int numberToSkip = 0,
146173
CancellationToken cancellationToken = default)
147174
{
148-
return activePackageSource.Search(searchTerm, includePrerelease, numberToGet, numberToSkip, cancellationToken);
175+
return ActivePackageSource.Search(searchTerm, includePrerelease, numberToGet, numberToSkip, cancellationToken);
149176
}
150177

151178
/// <summary>
@@ -156,19 +183,22 @@ public static Task<List<INugetPackage>> Search(
156183
/// <param name="targetFrameworks">The specific frameworks to target?.</param>
157184
/// <param name="versionConstraints">The version constraints?.</param>
158185
/// <returns>A list of all updates available.</returns>
186+
[NotNull]
187+
[ItemNotNull]
159188
public static List<INugetPackage> GetUpdates(
160-
IEnumerable<INugetPackage> packagesToUpdate,
189+
[NotNull] IEnumerable<INugetPackage> packagesToUpdate,
161190
bool includePrerelease = false,
162191
string targetFrameworks = "",
163192
string versionConstraints = "")
164193
{
165-
return activePackageSource.GetUpdates(packagesToUpdate, includePrerelease, targetFrameworks, versionConstraints);
194+
return ActivePackageSource.GetUpdates(packagesToUpdate, includePrerelease, targetFrameworks, versionConstraints);
166195
}
167196

168197
/// <inheritdoc cref="INugetPackageSource.GetSpecificPackage(INugetPackageIdentifier)" />
169-
public static INugetPackage GetSpecificPackage(INugetPackageIdentifier nugetPackageIdentifier)
198+
[CanBeNull]
199+
public static INugetPackage GetSpecificPackage([NotNull] INugetPackageIdentifier nugetPackageIdentifier)
170200
{
171-
return activePackageSource.GetSpecificPackage(nugetPackageIdentifier);
201+
return ActivePackageSource.GetSpecificPackage(nugetPackageIdentifier);
172202
}
173203
}
174204
}

0 commit comments

Comments
 (0)